def test_antonym_relationBaseUnderscore(self): doc_str = r""" <root><document><sentences> <sentence id="s1"> <tokens> <token base="large" pos="pos1" surf="surf1" id="t1_1"/> <token base="animal" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> <sentence id="s2"> <tokens> <token base="small" pos="pos1" surf="surf1" id="t1_1"/> <token base="animal" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> </sentences></document></root> """ doc = etree.fromstring(doc_str) relations = get_lexical_relations(doc) expected_relations = \ ['Axiom ax_antonym_large_small : forall x, _large x -> _small x -> False.'] self.assertEqual(expected_relations, relations)
def test_no_relation(self): doc_str = r""" <root><document><sentences> <sentence id="s1"> <tokens> <token base="_base1" pos="pos1" surf="surf1" id="t1_1"/> <token base="_base2" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> <sentence id="s2"> <tokens> <token base="_base3" pos="pos1" surf="surf1" id="t1_1"/> <token base="_base4" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> </sentences></document></root> """ doc = etree.fromstring(doc_str) relations = get_lexical_relations(doc) expected_relations = [] self.assertEqual(expected_relations, relations)
def test_antonym_relation(self): sentence_1_str = r""" <sentence id="s1"> <tokens> <token base="large" pos="pos1" surf="surf1" id="t1_1"/> <token base="animal" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> """ sentence_2_str = r""" <sentence id="s2"> <tokens> <token base="small" pos="pos1" surf="surf1" id="t1_1"/> <token base="animal" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> """ ccg_xml_trees = [etree.fromstring(sentence_1_str), etree.fromstring(sentence_2_str)] relations = get_lexical_relations(ccg_xml_trees) expected_relations = \ ['Axiom ax_antonym_large_small : forall x, _large x -> _small x -> False.'] self.assertEqual(expected_relations, relations)
def test_no_relation(self): sentence_1_str = r""" <sentence id="s1"> <tokens> <token base="_base1" pos="pos1" surf="surf1" id="t1_1"/> <token base="_base2" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> """ sentence_2_str = r""" <sentence id="s2"> <tokens> <token base="_base3" pos="pos1" surf="surf1" id="t1_1"/> <token base="_base4" pos="pos2" surf="surf2" id="t1_2"/> </tokens> <ccg root="sp1-3"> <span terminal="t1_1" category="cat1" end="2" begin="1" id="sp1-1"/> <span terminal="t1_2" category="cat2" end="3" begin="2" id="sp1-2"/> <span child="sp1-1 sp1-2" rule="lex" category="NP" end="3" begin="1" id="sp1-3"/> </ccg> </sentence> """ ccg_xml_trees = [etree.fromstring(sentence_1_str), etree.fromstring(sentence_2_str)] relations = get_lexical_relations(ccg_xml_trees) expected_relations = [] self.assertEqual(expected_relations, relations)
def build_knowledge_axioms(doc): if not doc: return '' axioms = get_lexical_relations(doc) axioms_str = "" for axiom in axioms: axioms_str += axiom + '\n' axiom_name = axiom.split()[1] axioms_str += 'Hint Resolve {0}.\n'.format(axiom_name) axioms_str += '\n' return axioms_str
def build_knowledge_axioms(ccg_trees): if ccg_trees is None: return '' axioms = get_lexical_relations(ccg_trees) axioms_str = "" for axiom in axioms: axioms_str += axiom + '\n' axiom_name = axiom.split()[1] axioms_str += 'Hint Resolve {0}.\n'.format(axiom_name) axioms_str += '\n' return axioms_str