def parse_constraint(s, equivalences):
    # print 'ParseConstraints.parse_constraint', s
    cond, constr_type, constr_args = re.match("\tcf\((.+),(eq|in_set|subsume)\((.+)\)", s).group(1, 2, 3)
    # print cond, constr_type, constr_args
    arg1, rest = parse_fs_path(constr_args)
    arg2, _ = parse_fs_path(rest[1:])
    conditions = parse_conditions(cond, equivalences)
    # if (len(conditions) == 1 and conditions[0] in equivalences):
    #    conditions = equivalences[conditions[0]]
    return Constraint(constr_type, conditions, arg1, arg2)
def parse_constraint(s, equivalences):
    #print 'ParseConstraints.parse_constraint', s
    cond, constr_type, constr_args = re.match(
        '\tcf\((.+),(eq|in_set|subsume)\((.+)\)', s).group(1, 2, 3)
    #print cond, constr_type, constr_args
    arg1, rest = parse_fs_path(constr_args)
    arg2, _ = parse_fs_path(rest[1:])
    conditions = parse_conditions(cond, equivalences)
    #if (len(conditions) == 1 and conditions[0] in equivalences):
    #    conditions = equivalences[conditions[0]]
    return Constraint(constr_type, conditions, arg1, arg2)
示例#3
0
def parse_other(s, equivalences):
    # cf(1,xyz(...)),
    i = 0
    rels = ("subtree(", "terminal(", "semform_data(", "fspan(", "surfaceform(")
    for r in rels:
        if s.find(r) != -1:
            i = s.find(r)
            break
    cond, text = s[4 : (i - 1)], s[i:-1]
    if text.endswith(","):
        text = text[:-2]
    else:
        text = text[:-1]
    return Other(parse_conditions(cond, equivalences), text)
示例#4
0
def parse_other(s, equivalences):
    #cf(1,xyz(...)),
    i = 0
    rels = ('subtree(', 'terminal(', 'semform_data(', 'fspan(', 'surfaceform(')
    for r in rels:
        if (s.find(r) != -1):
            i = s.find(r)
            break
    cond, text = s[4:(i - 1)], s[i:-1]
    if text.endswith(','):
        text = text[:-2]
    else:
        text = text[:-1]
    return Other(parse_conditions(cond, equivalences), text)
示例#5
0
def parse_node(s, equivalences):
    #print 'ParseNodes.parse_node', s
    ret = None
    if (s.find('subtree') > -1):
        cond, node = re.match(r'\tcf\((.+),subtree\((.+)\)\)', s).group(1, 2)
        #n_id, label, ch1, ch2 = node.replace('-', '0').split(',')
        n_id, label, ch1, ch2 = node.split(',')
        ret = Node(int(n_id), label[1:-1])
        conditions = parse_conditions(cond, equivalences)
        # if (len(conditions) == 1 and conditions[0] in equivalences):
        #    conditions = equivalences[conditions[0]]
        choices = set(conditions)
        ret.children_ids = [(int(i), choices) for i in (ch1, ch2) if i != '-']
    if (s.find('terminal(') > -1):
        #cf(1,terminal(32,'w',[32])),
        cond, n_id, label = re.match(r'\tcf\((.+),terminal\((.+),\'(.+)\',.*\)\)', s).group(1, 2, 3)
        ret = Node(int(n_id), label)
    return ret
示例#6
0
def parse_node(s, equivalences):
    #print 'ParseNodes.parse_node', s
    ret = None
    if (s.find('subtree') > -1):
        cond, node = re.match(r'\tcf\((.+),subtree\((.+)\)\)', s).group(1, 2)
        #n_id, label, ch1, ch2 = node.replace('-', '0').split(',')
        n_id, label, ch1, ch2 = node.split(',')
        ret = Node(int(n_id), label[1:-1])
        conditions = parse_conditions(cond, equivalences)
        # if (len(conditions) == 1 and conditions[0] in equivalences):
        #    conditions = equivalences[conditions[0]]
        choices = set(conditions)
        ret.children_ids = [(int(i), choices) for i in (ch1, ch2) if i != '-']
    if (s.find('terminal(') > -1):
        #cf(1,terminal(32,'w',[32])),
        cond, n_id, label = re.match(
            r'\tcf\((.+),terminal\((.+),\'(.+)\',.*\)\)', s).group(1, 2, 3)
        ret = Node(int(n_id), label)
    return ret
示例#7
0
def parse_phi(s, equivalences):
    cond, n_id, var = re.match(r'\tcf\((.+),phi\((.+),var\((.+)\)\)\)', s).group(1, 2, 3)
    return Phi(int(n_id), int(var), parse_conditions(cond, equivalences))
def parse_equivalence(s):
    alias, cond = re.match("\tdefine\((.+), (.+)\)", s).group(1, 2)
    # print alias, cond
    cond = parse_conditions(cond, {})  # tuple(parse_conditions(cond)[0])
    # print alias, cond
    return alias, cond
def parse_equivalence(s):
    alias, cond = re.match('\tdefine\((.+), (.+)\)', s).group(1, 2)
    #print alias, cond
    cond = parse_conditions(cond, {})  #tuple(parse_conditions(cond)[0])
    #print alias, cond
    return alias, cond