def fs_is_prep(val, fs, eqs):
    v = get_from_fs(val, fs, eqs)
    #print 'fs_is_prep:', v
    if (type(v) == AttributeStructure and 'CHECK' in v.attrs):
        check = get_from_fs(v.attrs['CHECK'], fs, eqs)  #fs[v.attrs['CHECK']]
        if not '_CAT' in check.attrs:
            return False
        #print 'fs_is_prep - check:', check
        return (get_from_fs(check.attrs['_CAT'], fs, eqs)) == 'prep'
    return False
def fs_is_prep(val, fs, eqs):
    v = get_from_fs(val, fs, eqs)
    #print 'fs_is_prep:', v
    if (type(v) == AttributeStructure and 'CHECK' in v.attrs):
        check = get_from_fs(v.attrs['CHECK'], fs, eqs)#fs[v.attrs['CHECK']]
        if not '_CAT' in check.attrs:
            return False
        #print 'fs_is_prep - check:', check
        return (get_from_fs(check.attrs['_CAT'], fs, eqs)) == 'prep'
    return False
def collect_preds(val, fs, eqs):
    '''prep's OBJ may be a set'''
    if fs_is_prep(val, fs, eqs):
        return collect_preds(get_from_fs(val, fs, eqs).attrs['OBJ'], fs, eqs)
    p = find_fs_pred(val, fs, eqs)
    if p:
        return [p]
    elif (type(val) == int and type(get_from_fs(val, fs, eqs)) == AttributeStructure):
        preds = []
        for e in get_from_fs(val, fs, eqs).set_elements:
            preds += collect_preds(e, fs, eqs)
        return preds
    return []
def collect_preds(val, fs, eqs):
    '''prep's OBJ may be a set'''
    if fs_is_prep(val, fs, eqs):
        return collect_preds(get_from_fs(val, fs, eqs).attrs['OBJ'], fs, eqs)
    p = find_fs_pred(val, fs, eqs)
    if p:
        return [p]
    elif (type(val) == int
          and type(get_from_fs(val, fs, eqs)) == AttributeStructure):
        preds = []
        for e in get_from_fs(val, fs, eqs).set_elements:
            preds += collect_preds(e, fs, eqs)
        return preds
    return []
def collect_struct_vars(val, fs, eqs):
    #print 'collect_attr_structs:', val
    '''prep's OBJ may be a set'''
    if fs_is_prep(val, fs, eqs):
        return collect_struct_vars(get_from_fs(val, fs, eqs).attrs['OBJ'], fs, eqs)
    if find_fs_pred(val, fs, eqs):
        return [val]
    v = get_from_fs(val, fs, eqs)
    if (type(v) == AttributeStructure):
        structs = []
        for e in v.set_elements:
            structs += collect_struct_vars(e, fs, eqs)
        return structs
    return []
def collect_struct_vars(val, fs, eqs):
    #print 'collect_attr_structs:', val
    '''prep's OBJ may be a set'''
    if fs_is_prep(val, fs, eqs):
        return collect_struct_vars(
            get_from_fs(val, fs, eqs).attrs['OBJ'], fs, eqs)
    if find_fs_pred(val, fs, eqs):
        return [val]
    v = get_from_fs(val, fs, eqs)
    if (type(v) == AttributeStructure):
        structs = []
        for e in v.set_elements:
            structs += collect_struct_vars(e, fs, eqs)
        return structs
    return []
def find_fs_pred(val, fs, eqs):
    #print '    !!!! find_fs_pred - val:', val
    if (type(val) == int):
        try:
            val = fs[val]
        except KeyError:
            #print 'find_fs_pred - KeyError'
            return None
    if (type(val) == Semform):
        return val.sem
    elif (fs_is_prep(val, fs, eqs)):
        #print val.attrs['PRED'], val.attrs.keys()
        #print '    !!!! find_fs_pred - preposition'
        return find_fs_pred(val.attrs['OBJ'], fs, eqs)
    elif (type(val) == AttributeStructure and 'PRED' in val.attrs):
        #print 'pred in struct'
        pred = val.attrs['PRED']
        #print pred
        #TODO: test
        '''if type(pred) == int:
            pred = fs[pred].sem
        else:
            pred = pred.sem'''
        pred = get_from_fs(pred, fs, eqs).sem
        #print 'will return:', pred
        return pred
    return None
def find_fs_pred(val, fs, eqs):
    #print '    !!!! find_fs_pred - val:', val
    if (type(val) == int):
        try:
            val = fs[val]
        except KeyError:
            #print 'find_fs_pred - KeyError'
            return None
    if (type(val) == Semform):
        return val.sem
    elif (fs_is_prep(val, fs, eqs)):
        #print val.attrs['PRED'], val.attrs.keys()
        #print '    !!!! find_fs_pred - preposition'
        return find_fs_pred(val.attrs['OBJ'], fs, eqs)
    elif (type(val) == AttributeStructure and 'PRED' in val.attrs):
        #print 'pred in struct'
        pred = val.attrs['PRED']
        #print pred
        #TODO: test
        '''if type(pred) == int:
            pred = fs[pred].sem
        else:
            pred = pred.sem'''
        pred = get_from_fs(pred, fs, eqs).sem
        #print 'will return:', pred
        return pred
    return None
Exemplo n.º 9
0
def collect_attr_vals(fs, eqs):
    attr_vals = set()
    for f in fs.values():
        if type(f) == AttributeStructure:
            for k, v in f.attrs.items():
                if k in val_attrs:
                    attr_vals.add((k, get_from_fs(v, fs, eqs)))
    return attr_vals
Exemplo n.º 10
0
def collect_attr_vals(fs, eqs):
    attr_vals = set()
    for f in fs.values():
        if (type(f) == AttributeStructure):
            for k, v in f.attrs.items():
                if k in val_attrs:
                    attr_vals.add((k, get_from_fs(v, fs, eqs)))
    return attr_vals
Exemplo n.º 11
0
def collect_adj_attrs(fs, eqs):
    adj_attrs = set()
    for f in fs.values():
        if type(f) == AttributeStructure:
            for k, v in f.attrs.items():
                if k in fs_attrs:
                    attr_f = get_from_fs(v, fs, eqs)
                    adj_attrs.update([(k, kk) for kk in attr_f.attrs.keys() if kk in fs_attrs])
    return adj_attrs
Exemplo n.º 12
0
def compatible_with_skladnica(struct, fs, eqs_dict):
    if ('CHECK' in struct.attrs):
        check = get_from_fs(struct.attrs['CHECK'], fs, eqs_dict)
        #print check
        try:
            cat = get_from_fs(check.attrs['_CAT'], fs, eqs_dict)
        except KeyError:
            cat = '_'
        #print cat
        if cat in ('prep',):#('pact', 'ppas', 'pcon', 'pant', 'prep', 'inf'):
            #print '        ---->    IMIESŁÓW'
            return False
    else:
        '''bardzo'''
        p = get_from_fs(struct.attrs['PRED'], fs, eqs_dict)
        if (p and p.sem == 'bardzo'):
            return False
    return True
Exemplo n.º 13
0
def compatible_with_skladnica(struct, fs, eqs_dict):
    if ('CHECK' in struct.attrs):
        check = get_from_fs(struct.attrs['CHECK'], fs, eqs_dict)
        #print check
        try:
            cat = get_from_fs(check.attrs['_CAT'], fs, eqs_dict)
        except KeyError:
            cat = '_'
        #print cat
        if cat in (
                'prep', ):  #('pact', 'ppas', 'pcon', 'pant', 'prep', 'inf'):
            #print '        ---->    IMIESŁÓW'
            return False
    else:
        '''bardzo'''
        p = get_from_fs(struct.attrs['PRED'], fs, eqs_dict)
        if (p and p.sem == 'bardzo'):
            return False
    return True
Exemplo n.º 14
0
def collect_adj_attrs(fs, eqs):
    adj_attrs = set()
    for f in fs.values():
        if (type(f) == AttributeStructure):
            for k, v in f.attrs.items():
                if k in fs_attrs:
                    attr_f = get_from_fs(v, fs, eqs)
                    adj_attrs.update([(k, kk) for kk in attr_f.attrs.keys()
                                      if kk in fs_attrs])
    return adj_attrs
Exemplo n.º 15
0
def fs_equal(fs1, fs2, fs, eqs):
    if (type(fs1) == int or type(fs2) == int):
        if (type(fs1) != int or type(fs2) != int):
            if (type(fs1) == int):
                fsi, fss = fs1, fs2
            else:
                fsi, fss = fs2, fs1
            return fs_equal(get_from_fs(fsi, fs, eqs), fss, fs, eqs)
    if type(fs1) != type(fs2):
        return False
    if (type(fs1) == int):
        return eqs[fs1] == eqs[fs2]
    if (type(fs1) == str):
        return fs1 == fs2
    if type(fs1) == Atom:
        return fs1.val == fs2.val
    #TODO arglists
    if type(fs1) == Semform:
        #print fs1.sem, fs1.arg_list, fs1.arg_list_2
        #print fs2.sem, fs2.arg_list, fs2.arg_list_2
        return ((fs1.sem == fs2.sem) and (fs1.arg_list == fs2.arg_list)
                and (fs1.arg_list_2 == fs2.arg_list_2))
    if type(fs1) == AttributeStructure:
        if (fs1.attrs.keys() != fs2.attrs.keys()):
            return False
        for a in fs1.attrs.keys():
            if (not fs_equal(fs1.attrs[a], fs2.attrs[a], fs, eqs)):
                #print '      a', a, fs1.attrs[a], fs2.attrs[a]
                return False
        e1, e2 = set(), set()
        for e in fs1.set_elements:
            e1.update(eqs[e])
        for e in fs2.set_elements:
            e2.update(eqs[e])
        if (e1 != e2):  #(fs1.set_elements != fs2.set_elements):
            #print 'set'
            return False
        return True
    raise RuntimeError
Exemplo n.º 16
0
def fs_equal(fs1, fs2, fs, eqs):
    if type(fs1) == int or type(fs2) == int:
        if type(fs1) != int or type(fs2) != int:
            if type(fs1) == int:
                fsi, fss = fs1, fs2
            else:
                fsi, fss = fs2, fs1
            return fs_equal(get_from_fs(fsi, fs, eqs), fss, fs, eqs)
    if type(fs1) != type(fs2):
        return False
    if type(fs1) == int:
        return eqs[fs1] == eqs[fs2]
    if type(fs1) == str:
        return fs1 == fs2
    if type(fs1) == Atom:
        return fs1.val == fs2.val
    # TODO arglists
    if type(fs1) == Semform:
        # print fs1.sem, fs1.arg_list, fs1.arg_list_2
        # print fs2.sem, fs2.arg_list, fs2.arg_list_2
        return (fs1.sem == fs2.sem) and (fs1.arg_list == fs2.arg_list) and (fs1.arg_list_2 == fs2.arg_list_2)
    if type(fs1) == AttributeStructure:
        if fs1.attrs.keys() != fs2.attrs.keys():
            return False
        for a in fs1.attrs.keys():
            if not fs_equal(fs1.attrs[a], fs2.attrs[a], fs, eqs):
                # print '      a', a, fs1.attrs[a], fs2.attrs[a]
                return False
        e1, e2 = set(), set()
        for e in fs1.set_elements:
            e1.update(eqs[e])
        for e in fs2.set_elements:
            e2.update(eqs[e])
        if e1 != e2:  # (fs1.set_elements != fs2.set_elements):
            # print 'set'
            return False
        return True
    raise RuntimeError
Exemplo n.º 17
0
def attr_pred_lists(struct, fs, eqs_dict, used_vars=None):
    v = False
    if (used_vars is None):
        return attr_pred_lists(struct, fs, eqs_dict, set())
    else:
        ret = []
        if v:
            print '\nattr_pred_lists start', struct
        '''PREPOSITION'''
        if fs_is_prep(struct, fs, eqs_dict):
            if v:
                print '    -> PREP'
            return attr_pred_lists(get_from_fs(struct, fs, eqs_dict).attrs['OBJ'], fs, eqs_dict, used_vars)
        if (type(struct) == AttributeStructure and not struct.set_elements):
            fs_pred = find_fs_pred(struct, fs, eqs_dict)
            if (not fs_pred):
                return []
            for attr, value in struct.attrs.items():
                if attr == 'REFLEXIVE':
                    #print fs_pred, '***************REFLEXIVE'
                    fs_pred += u'_się'
                val = value
                if (type(val) == int):
                    '''may be a prep'''
                    if (fs_is_prep(val, fs, eqs_dict)):
                        val = get_from_fs(val, fs, eqs_dict).attrs['OBJ']
                    if v:
                        print '-> attr of', fs_pred, ':', attr, val
                    if (val in fs):
                        #used_vars.add(val)
                        #structs = collect_struct_vars(val, fs, eqs_dict)#collect_attr_structs(val, fs, eqs_dict)
                        vs = collect_struct_vars(val, fs, eqs_dict)
                        if v:
                            #print 'structs:', structs
                            print 'vs:', vs
                        #for s in structs:
                        #    ret += attr_pred_lists(s, fs, eqs_dict, used_vars)
                        for var in vs:
                            v_used = False
                            if v:
                                print '  EQ:', eqs_dict[val], used_vars
                            if (not var in eqs_dict):
                                eqs_dict[var] = set([var])
                            for eq_val in eqs_dict[var]:
                                if (eq_val in used_vars):
                                    v_used = True
                                    if v:
                                        print '  USED:', var, eqs_dict[val]
                            if (not v_used):
                                if (not var in fs):
                                    for eq_val in eqs_dict[var]:
                                        if (eq_val in fs):
                                            var = eq_val
                                            break
                                used_vars.add(var)
                                s = get_from_fs(var, fs, eqs_dict)
                                ret += attr_pred_lists(s, fs, eqs_dict, used_vars)
                    else:
                        print 'UNKNOWN VAR:', val
            if v:
                print 'getting attr_pred_lists for:', fs_pred
            if (compatible_with_skladnica(struct, fs, eqs_dict)):
                #print 'attr_pred_lists - COMPATIBLE:', struct
                ret.append((fs_pred, collect_attr_preds(struct, fs, eqs_dict)))
            if v:
                print 'ret is now:', ret
        elif type(struct) == AttributeStructure and struct.set_elements:
            for s in struct.set_elements:#collect_attr_structs(struct, fs):
                elem = get_from_fs(s, fs, eqs_dict)
                ret += attr_pred_lists(elem, fs, eqs_dict, used_vars)
                '''for val in struct.set_elements:
                    v_used = False
                    if (not val in eqs_dict):
                        eqs_dict[val] = set([val])
                    for eq_val in eqs_dict[val]:
                        if (eq_val in used_vars):
                            v_used = True
                    if (not v_used):
                        if (not val in fs):
                            for eq_val in eqs_dict[val]:
                                if (eq_val in fs):
                                    val = eq_val
                                    break
                        if (val in fs):
                            used_vars.add(val)
                            ret += attr_pred_lists(fs[val], fs, eqs_dict, used_vars)
                        else:
                            print 'UNKNOWN VAR:', val'''
        else:
            pass
            #print struct
            #print type(struct)
            #raise RuntimeError()
        return ret
Exemplo n.º 18
0
def build_fs(constrs):
    fs = {}
    eqs = []
    c_count = 0
    applied = 0
    eq_constrs = []
    subsume = []
    for c in constrs:
        if (apply_constraint_to_fs(c, fs, eqs)):
            c_count += 1
            applied += 1
        else:
            eq_constrs.append(c)
            if (c.type == ConstraintType.subsume):
                subsume.append(c)
    eqs_dict = {}
    '''make sure eq sets are OK'''
    ''''for eq_set in eqs:
        print eq_set
        for var in eq_set:
            if (not var in eqs_dict):
                eqs_dict[var] = set()
            for eq_var in eq_set:
                eqs_dict[var].add(eq_var)'''
    overlap = [(i, j) for i in xrange(0, len(eqs))
               for j in xrange(0, len(eqs))
               if i != j and eqs[i].intersection(eqs[j])]
    while overlap:
        i, j = overlap[0]
        eqs[i].update(eqs[j])
        del eqs[j]
        overlap = [(i, j) for i in xrange(0, len(eqs))
                   for j in xrange(0, len(eqs))
                   if i != j and eqs[i].intersection(eqs[j])]
    for eq_set in eqs:
        for var in eq_set:
            eqs_dict[var] = eq_set
    for var in fs.keys():
        if (not var in eqs_dict):
            eqs_dict[var] = set([var])
    '''now apply eqs between vars'''
    apply_eqs_to_fs(fs, eqs_dict)
    #for k, v in fs.items():
    #    print k, v
    while True:
        #print '    ### subsumptions:', len(subsume)
        eq = None
        for c in subsume:
            #print '-----------', c
            #print eqs_dict
            #for k, v in fs.items():
            #    print k, ':', v
            #if (c.arg1.var in eqs_dict and c.arg2.var in eqs_dict):
            def1, def2 = is_defined(c.arg1.var, fs, eqs_dict), is_defined(
                c.arg2.var, fs, eqs_dict)
            if (def1 or def2):
                if (def1 and def2):
                    #print c.arg1, c.arg2
                    v1, v2 = get_from_fs(c.arg1.var, fs,
                                         eqs_dict), get_from_fs(
                                             c.arg2.var, fs, eqs_dict)
                    #print '\n', v1, '\n', v2, '\n'
                    if fs_equal(v1, v2, fs, eqs_dict):
                        subsume.remove(c)
                        eq = (c.arg1.var, c.arg2.var)
                        break
                else:
                    subsume.remove(c)
                    eq = (c.arg1.var, c.arg2.var)
                    break
        if not eq:
            break
        #print '       ===================        ', eq
        for var in eq:
            if not var in eqs_dict:
                eqs_dict[var] = set([var])
        eqs_dict[eq[0]].update(eqs_dict[eq[1]])
        for v in eqs_dict[eq[0]]:
            eqs_dict[v] = eqs_dict[eq[0]]
        #print eqs_dict
        #print 'apply'
        apply_eq_to_fs(fs, c.arg1.var, c.arg2.var)
    #for c in subsume:
    #print '======================', c
    #if (c.arg1.var in eqs_dict and c.arg2.var in eqs_dict):
    #    v1, v2 = get_from_fs(c.arg1.var, fs, eqs_dict), get_from_fs(c.arg2.var, fs, eqs_dict)
    #    if v1 != v2:
    #        print '                 **************', v1
    #        print '                               ', v2
    '''check for duplicates in set elements'''
    check_sets(fs, eqs_dict)
    return fs, eqs_dict
Exemplo n.º 19
0
def find_fs_struct(val, fs, eqs):
    if (type(val) == AttributeStructure):
        return val
    elif (type(val) == int
          and type(get_from_fs(val, fs, eqs)) == AttributeStructure):
        return get_from_fs(val, fs, eqs)
Exemplo n.º 20
0
def attr_pred_lists(struct, fs, eqs_dict, used_vars=None):
    v = False
    if (used_vars is None):
        return attr_pred_lists(struct, fs, eqs_dict, set())
    else:
        ret = []
        if v:
            print '\nattr_pred_lists start', struct
        '''PREPOSITION'''
        if fs_is_prep(struct, fs, eqs_dict):
            if v:
                print '    -> PREP'
            return attr_pred_lists(
                get_from_fs(struct, fs, eqs_dict).attrs['OBJ'], fs, eqs_dict,
                used_vars)
        if (type(struct) == AttributeStructure and not struct.set_elements):
            fs_pred = find_fs_pred(struct, fs, eqs_dict)
            if (not fs_pred):
                return []
            for attr, value in struct.attrs.items():
                if attr == 'REFLEXIVE':
                    #print fs_pred, '***************REFLEXIVE'
                    fs_pred += u'_się'
                val = value
                if (type(val) == int):
                    '''may be a prep'''
                    if (fs_is_prep(val, fs, eqs_dict)):
                        val = get_from_fs(val, fs, eqs_dict).attrs['OBJ']
                    if v:
                        print '-> attr of', fs_pred, ':', attr, val
                    if (val in fs):
                        #used_vars.add(val)
                        #structs = collect_struct_vars(val, fs, eqs_dict)#collect_attr_structs(val, fs, eqs_dict)
                        vs = collect_struct_vars(val, fs, eqs_dict)
                        if v:
                            #print 'structs:', structs
                            print 'vs:', vs
                        #for s in structs:
                        #    ret += attr_pred_lists(s, fs, eqs_dict, used_vars)
                        for var in vs:
                            v_used = False
                            if v:
                                print '  EQ:', eqs_dict[val], used_vars
                            if (not var in eqs_dict):
                                eqs_dict[var] = set([var])
                            for eq_val in eqs_dict[var]:
                                if (eq_val in used_vars):
                                    v_used = True
                                    if v:
                                        print '  USED:', var, eqs_dict[val]
                            if (not v_used):
                                if (not var in fs):
                                    for eq_val in eqs_dict[var]:
                                        if (eq_val in fs):
                                            var = eq_val
                                            break
                                used_vars.add(var)
                                s = get_from_fs(var, fs, eqs_dict)
                                ret += attr_pred_lists(s, fs, eqs_dict,
                                                       used_vars)
                    else:
                        print 'UNKNOWN VAR:', val
            if v:
                print 'getting attr_pred_lists for:', fs_pred
            if (compatible_with_skladnica(struct, fs, eqs_dict)):
                #print 'attr_pred_lists - COMPATIBLE:', struct
                ret.append((fs_pred, collect_attr_preds(struct, fs, eqs_dict)))
            if v:
                print 'ret is now:', ret
        elif type(struct) == AttributeStructure and struct.set_elements:
            for s in struct.set_elements:  #collect_attr_structs(struct, fs):
                elem = get_from_fs(s, fs, eqs_dict)
                ret += attr_pred_lists(elem, fs, eqs_dict, used_vars)
                '''for val in struct.set_elements:
                    v_used = False
                    if (not val in eqs_dict):
                        eqs_dict[val] = set([val])
                    for eq_val in eqs_dict[val]:
                        if (eq_val in used_vars):
                            v_used = True
                    if (not v_used):
                        if (not val in fs):
                            for eq_val in eqs_dict[val]:
                                if (eq_val in fs):
                                    val = eq_val
                                    break
                        if (val in fs):
                            used_vars.add(val)
                            ret += attr_pred_lists(fs[val], fs, eqs_dict, used_vars)
                        else:
                            print 'UNKNOWN VAR:', val'''
        else:
            pass
            #print struct
            #print type(struct)
            #raise RuntimeError()
        return ret
Exemplo n.º 21
0
def find_fs_struct(val, fs, eqs):
    if (type(val) == AttributeStructure):
        return val
    elif (type(val) == int and type(get_from_fs(val, fs, eqs)) == AttributeStructure):
        return get_from_fs(val, fs, eqs)
Exemplo n.º 22
0
def build_fs(constrs):
    fs = {}
    eqs = []
    c_count = 0
    applied = 0
    eq_constrs = []
    subsume = []
    for c in constrs:
        if apply_constraint_to_fs(c, fs, eqs):
            c_count += 1
            applied += 1
        else:
            eq_constrs.append(c)
            if c.type == ConstraintType.subsume:
                subsume.append(c)
    eqs_dict = {}
    """make sure eq sets are OK"""
    """'for eq_set in eqs:
        print eq_set
        for var in eq_set:
            if (not var in eqs_dict):
                eqs_dict[var] = set()
            for eq_var in eq_set:
                eqs_dict[var].add(eq_var)"""
    overlap = [
        (i, j) for i in xrange(0, len(eqs)) for j in xrange(0, len(eqs)) if i != j and eqs[i].intersection(eqs[j])
    ]
    while overlap:
        i, j = overlap[0]
        eqs[i].update(eqs[j])
        del eqs[j]
        overlap = [
            (i, j) for i in xrange(0, len(eqs)) for j in xrange(0, len(eqs)) if i != j and eqs[i].intersection(eqs[j])
        ]
    for eq_set in eqs:
        for var in eq_set:
            eqs_dict[var] = eq_set
    for var in fs.keys():
        if not var in eqs_dict:
            eqs_dict[var] = set([var])
    """now apply eqs between vars"""
    apply_eqs_to_fs(fs, eqs_dict)
    # for k, v in fs.items():
    #    print k, v
    while True:
        # print '    ### subsumptions:', len(subsume)
        eq = None
        for c in subsume:
            # print '-----------', c
            # print eqs_dict
            # for k, v in fs.items():
            #    print k, ':', v
            # if (c.arg1.var in eqs_dict and c.arg2.var in eqs_dict):
            def1, def2 = is_defined(c.arg1.var, fs, eqs_dict), is_defined(c.arg2.var, fs, eqs_dict)
            if def1 or def2:
                if def1 and def2:
                    # print c.arg1, c.arg2
                    v1, v2 = get_from_fs(c.arg1.var, fs, eqs_dict), get_from_fs(c.arg2.var, fs, eqs_dict)
                    # print '\n', v1, '\n', v2, '\n'
                    if fs_equal(v1, v2, fs, eqs_dict):
                        subsume.remove(c)
                        eq = (c.arg1.var, c.arg2.var)
                        break
                else:
                    subsume.remove(c)
                    eq = (c.arg1.var, c.arg2.var)
                    break
        if not eq:
            break
        # print '       ===================        ', eq
        for var in eq:
            if not var in eqs_dict:
                eqs_dict[var] = set([var])
        eqs_dict[eq[0]].update(eqs_dict[eq[1]])
        for v in eqs_dict[eq[0]]:
            eqs_dict[v] = eqs_dict[eq[0]]
        # print eqs_dict
        # print 'apply'
        apply_eq_to_fs(fs, c.arg1.var, c.arg2.var)
    # for c in subsume:
    # print '======================', c
    # if (c.arg1.var in eqs_dict and c.arg2.var in eqs_dict):
    #    v1, v2 = get_from_fs(c.arg1.var, fs, eqs_dict), get_from_fs(c.arg2.var, fs, eqs_dict)
    #    if v1 != v2:
    #        print '                 **************', v1
    #        print '                               ', v2
    """check for duplicates in set elements"""
    check_sets(fs, eqs_dict)
    return fs, eqs_dict