def test_check_consistency(): a = logic.LogicParser().parse('(man j)') b = logic.LogicParser().parse('(not (man j))') print '%s, %s: %s' % (a.infixify(), b.infixify(), RTEInferenceTagger().check_consistency([a,b], True)) print '%s, %s: %s' % (a.infixify(), a.infixify(), RTEInferenceTagger().check_consistency([a,a], True))
def __init__(self, meaning, glue, indices=set([])): if isinstance(meaning, str): try: self.meaning = logic.LogicParser().parse( meaning ) # lp.parse('\\x.(<word> x)') -> LambdaExpression('x', '(<word> x)') except Exception: raise RuntimeError, 'Meaning string %s' % (meaning) elif isinstance(meaning, logic.Expression): try: self.meaning = meaning except Exception: raise RuntimeError, 'Meaning expression %s' % (meaning) else: raise RuntimeError, 'Meaning term neither string or expression: %s' % ( meaning) if isinstance(glue, str): try: self.glue = linearlogic.Parser().parse( glue ) # llp.parse('(v -o r)') -> ApplicationExpression('(-o v)', 'r') except Exception: raise RuntimeError, 'Glue string %s' % (glue) elif isinstance(glue, linearlogic.Expression): try: self.glue = glue except Exception: raise RuntimeError, 'Glue expression %s' % (glue) else: raise RuntimeError, 'Glue term neither string or expression: %s' % ( glue) self.indices = indices
def _create_axiom_reverse(self, word_text, word_synset, nym_text, pos, operator): nym_text = nym_text.split('(')[0]; nym_word = pos[nym_text] dist = 1#min([word_synset.shortest_path_distance(nym_synset) for nym_synset in nym_word]) word_text = word_text.replace('.', '') nym_text = nym_text.replace('.', '') exp_text = 'all x.((%s x) %s (%s x))' % (nym_text, operator, word_text) return (logic.LogicParser().parse(exp_text), dist)
def _create_axiom_synset_sisters(self, text1, word1_synset, text2, word2_synset, pos): """ Return an expression of the form 'all x.((word x) implies (not (sister x)))'. The reverse is not needed because it is equal to 'all x.((not (word x)) or (not (sister x)))' """ text2 = text2.split('(')[0]; dist = 1#word1_synset.shortest_path_distance(word2_synset) text1 = text1.replace('.', '') text2 = text2.replace('.', '') exp_text = 'all x.((%s x) implies (not (%s x)))' % (text1, text2) return (logic.LogicParser().parse(exp_text), dist)