eta.util.tt.parse
Methods for parsing choice trees and word features from LISP definitions.
Functions
Stores a feature list in a dictionary of word features, modifying the dictionary in-place. |
|
Recursively read choice trees and word features from all LISP files in a directory or list of directories. |
|
Read a LISP file and parse the rule trees and feature definitions contained within. |
|
Initialize a node of a choice tree. |
|
Merges two feature dicts. |
|
Merges two predicate dicts (overriding any duplicates). |
|
Merges two choice tree dicts (overriding any duplicates). |
|
Read a Python file containing predicate function definitions, and return a predicate dict. |
|
Create a choice tree from a packet of pattern and template rules. |
- readrules(packet)[source]
Create a choice tree from a packet of pattern and template rules.
- Parameters:
A list of form
[depth, pattern, optional-pair, depth, pattern, optional-pair, ...]
, where:depth
is 1 for top-level rules, 2 for direct children, etc.,pattern
is a decomposition pattern or other output,optional-pair
is present iffpattern
is a reassembly pattern or other output, and consists of a(latency, directive)
tuple, where latency is an integer >= 0 specifying how long to wait to use a rule again, and directive is a symbol such as:out
,:subtree
,:gist
, etc. specifying how the output should be used.
- Returns:
root – The root of the choice tree (a nested dict structure) created from the packet.
- Return type:
- attachfeat(feat_xx, feats)[source]
Stores a feature list in a dictionary of word features, modifying the dictionary in-place.
- Parameters:
A list of form
[feat, x1, x2, ..., xk]
, where:feat
is a string, regarded as a feature.x1
,x2
, … are words that will be assignedfeat
as a feature, i.e.,isa(xi, feat)
will be True for each xi among x1, x2, …, xk.
feats (dict) – A dict mapping words to features, to be modified in-place.
- from_lisp_file(fname)[source]
Read a LISP file and parse the rule trees and feature definitions contained within.
- Parameters:
fname (str) – The filename to read.
- Returns:
trees (dict) – A dict containing all choice trees, keyed on their root names.
feats (dict) – A dict mapping words to feature lists.
- read_preds_file(fname)[source]
Read a Python file containing predicate function definitions, and return a predicate dict.