eta.util.tt.parse

Methods for parsing choice trees and word features from LISP definitions.

Functions

attachfeat

Stores a feature list in a dictionary of word features, modifying the dictionary in-place.

from_lisp_dirs

Recursively read choice trees and word features from all LISP files in a directory or list of directories.

from_lisp_file

Read a LISP file and parse the rule trees and feature definitions contained within.

init_node

Initialize a node of a choice tree.

merge_feats

Merges two feature dicts.

merge_preds

Merges two predicate dicts (overriding any duplicates).

merge_trees

Merges two choice tree dicts (overriding any duplicates).

read_preds_file

Read a Python file containing predicate function definitions, and return a predicate dict.

readrules

Create a choice tree from a packet of pattern and template rules.

init_node(pattern)[source]

Initialize a node of a choice tree.

readrules(packet)[source]

Create a choice tree from a packet of pattern and template rules.

Parameters:

packet (list[str]) –

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 iff pattern 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:

dict

attachfeat(feat_xx, feats)[source]

Stores a feature list in a dictionary of word features, modifying the dictionary in-place.

Parameters:
  • feat_xx (list[str]) –

    A list of form [feat, x1, x2, ..., xk], where:

    • feat is a string, regarded as a feature.

    • x1, x2, … are words that will be assigned feat 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.

merge_feats(feats1, feats2)[source]

Merges two feature dicts.

merge_trees(trees1, trees2)[source]

Merges two choice tree dicts (overriding any duplicates).

merge_preds(preds1, preds2)[source]

Merges two predicate dicts (overriding any duplicates).

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.

Parameters:

fname (str) – The filename to read.

Returns:

preds – A dict mapping predicate names to functions.

Return type:

dict

from_lisp_dirs(dirs)[source]

Recursively read choice trees and word features from all LISP files in a directory or list of directories.

Parameters:

dirs (str or list[str]) – The directory or directories 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.

  • preds (dict) – A dict mapping predicate names to functions.