git @ Cat's Eye Technologies relwrite / a72e141
Add an example of a noncontracting (context-sensitive) grammar. Chris Pressey 4 months ago
2 changed file(s) with 35 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1515 ambiguous, then all possible parses (or generations) can be returned.
1616
1717 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.
2226
2327 The grammar must be provided in the form of a JSON file. There are example
2428 grammar files in the `eg/` directory of this repo.
3741 ./bin/relwrite eg/recursive-grammar.json --parse --start "a penguin sees a penguin then sees a dog"
3842 ```
3943
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:
4146
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.
4363
4464 ### Notes
4565
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".
4968
5069 ### TODO
5170
5271 * specify output filename
5372 * try heuristic for contraction phase: highest proportion of terminals
73 * `--goal` to assert that a particular final utterance appears
0 [
1 [["<S>"], ["a", "b", "c"]],
2 [["<S>"], ["a", "<S>", "<B>", "c"]],
3 [["c", "<B>"], ["<B>", "c"]],
4 [["b", "<B>"], ["b", "b"]]
5 ]