Add an example of a noncontracting (context-sensitive) grammar.
Chris Pressey
4 months ago
15 | 15 | ambiguous, then all possible parses (or generations) can be returned. |
16 | 16 | |
17 | 17 | It should be understood that `relwrite` trades off performance and small |
18 | memory footprint in favour of generality. There is, however, a feature to improve | |
19 | the performance in the case of very long derivations. Specifying a search strategies | |
20 | enables a **beam search** algorithm which aggressively focuses on derivations with a | |
21 | desirable character, e.g. a particular minimum length. | |
18 | memory footprint in favour of generality, so in general usage, it works | |
19 | best on small inputs. | |
20 | ||
21 | There are, however, features intended to improve performance in the case of very | |
22 | long derivations. Specifying a search strategy enables a **beam search** algorithm | |
23 | which aggressively focuses on derivations with a desired propery, e.g. a particular | |
24 | minimum length. This does sacrifice completeness however -- only a handful of all | |
25 | the possible results will be returned. | |
22 | 26 | |
23 | 27 | The grammar must be provided in the form of a JSON file. There are example |
24 | 28 | grammar files in the `eg/` directory of this repo. |
37 | 41 | ./bin/relwrite eg/recursive-grammar.json --parse --start "a penguin sees a penguin then sees a dog" |
38 | 42 | ``` |
39 | 43 | |
40 | Generate a really long string from a non-terminal in a grammar: | |
44 | Generate a really long string from a non-terminal in a grammar, without running out | |
45 | of memory and only taking a few hours of processor time: | |
41 | 46 | |
42 | (TK) | |
47 | ``` | |
48 | ./bin/relwrite eg/recursive-grammar.json --start "<Sentence>" --max-derivations=1 --strategy=expansion --expand-until=3000 | |
49 | ``` | |
50 | ||
51 | Parse a really long string from a non-terminal in a grammar, without running out | |
52 | of memory and only taking a few hours of processor time. This assumes the string | |
53 | to be parsed is in JSON format in the file `xyz.json`. | |
54 | ||
55 | ``` | |
56 | ./bin/relwrite eg/recursive-grammar.json --parse --start-set-file=xyz.json --max-derivations=1 --strategy=contraction | |
57 | ``` | |
58 | ||
59 | ### Detailed usage | |
60 | ||
61 | Run `relwrite --help` for a description of all the possible command-line options. Note that | |
62 | these are somewhat provisional and subject to change. | |
43 | 63 | |
44 | 64 | ### Notes |
45 | 65 | |
46 | `relwrite` uses the term "derivation" as a generic term meaning "parse or generation". | |
47 | ||
48 | `relwrite` also uses the term "utterance" to mean "any string of terminals and non-terminals". | |
66 | `relwrite` uses the term "derivation" as a generic term meaning "a parse or a generated utterance". | |
67 | It also uses the term "utterance" to mean "any string of terminals and non-terminals". | |
49 | 68 | |
50 | 69 | ### TODO |
51 | 70 | |
52 | 71 | * specify output filename |
53 | 72 | * try heuristic for contraction phase: highest proportion of terminals |
73 | * `--goal` to assert that a particular final utterance appears |