Esempio n. 1
0
def make_rule_pattern_from_ccg_node(ccg_tree, tokens):
    attributes = get_attributes_from_ccg_node_recursively(ccg_tree, tokens)
    category = ccg_tree.get('category')
    assert category, 'There should be a non-empty category attribute in {0}'\
      .format(etree.tostring(ccg_tree, pretty_print=True))
    semantics = None
    rule_pattern = SemanticRule(category, semantics, attributes)
    return rule_pattern
Esempio n. 2
0
def load_semantic_rules(fn):
    semantic_rules = []
    loaded = None
    with codecs.open(fn, 'r', 'utf-8') as infile:
        loaded = yaml.load(infile, Loader=yaml.SafeLoader)
    if not loaded: raise ValueError("couldn't load file: " + fn)

    for attributes in loaded:
        # Compulsory fields.
        category = attributes['category']
        semantics = lexpr(attributes['semantics'])
        del attributes['category'], attributes['semantics']
        for attr_name, attr_val in attributes.items():
            if attr_name.endswith('base') or attr_name.endswith('surf'):
                attributes[attr_name] = normalize_token(attr_val)
        new_semantic_rule = \
          SemanticRule(category, semantics, attributes)
        semantic_rules.append(new_semantic_rule)
    return semantic_rules