Ejemplo n.º 1
0
 def test_entity(self):
     coq_sig = ['Parameter base1 : Entity.',
                'Parameter base2 : Prop.']
     nltk_sig = convert_coq_signatures_to_nltk(coq_sig)
     expected_nltk_sig = {'base1' : read_type('e'),
                          'base2' : read_type('t')}
     self.assertEqual(expected_nltk_sig, nltk_sig)
Ejemplo n.º 2
0
 def test_lexical_binary_two_coq_complex_type(self):
     semantic_index = SemanticIndex(None)
     semantic_rules = [SemanticRule(r'cat1', r'\P x R.P(x, R)', {'coq_type' : 'Entity -> Prop -> Prop'}),
                       SemanticRule(r'cat2', r'\Q S T.Q(S, T)', {'coq_type' : 'Prop -> Entity -> Prop'}),
                       SemanticRule(r'NP', r'\P Q x R S T.(Q(x, R) -> P(S, T))', {'rule' : 'lex'})]
     semantic_index.rules = semantic_rules
     sentence_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 = etree.fromstring(sentence_str)
     ccg_tree = assign_semantics_to_ccg(sentence, semantic_index)
     coq_lib = get_coq_types(ccg_tree)
     expected_coq_lib = ['Parameter _base1 : Entity -> Prop -> Prop.',
                         'Parameter _base2 : Prop -> Entity -> Prop.']
     self.assertEqual(expected_coq_lib, coq_lib)
     expression = [ccg_tree.get('sem')]
     coq_sig =  convert_coq_signatures_to_nltk(coq_lib)
     nltk_lib = build_dynamic_library(expression, coq_sig)
     lib = merge_dynamic_libraries(coq_lib, nltk_lib, './coqlib.v', sentence)
     expected_lib = ["Parameter _base2 : Prop -> Entity -> Prop.",
                     "Parameter _base1 : Entity -> Prop -> Prop."]
     self.assertCountEqual(expected_lib, lib)
Ejemplo n.º 3
0
 def test_lexical_binary_two_coq_complex_type(self):
     semantic_index = SemanticIndex(None)
     semantic_rules = [
         SemanticRule(r'cat1', r'\P x R.P(x, R)',
                      {'coq_type': 'Entity -> Prop -> Prop'}),
         SemanticRule(r'cat2', r'\Q S T.Q(S, T)',
                      {'coq_type': 'Prop -> Entity -> Prop'}),
         SemanticRule(r'NP', r'\P Q x R S T.(Q(x, R) -> P(S, T))',
                      {'rule': 'lex'})
     ]
     semantic_index.rules = semantic_rules
     sentence_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 = etree.fromstring(sentence_str)
     ccg_tree = assign_semantics_to_ccg(sentence, semantic_index)
     coq_lib = get_coq_types(ccg_tree)
     expected_coq_lib = [
         'Parameter _base1 : Entity -> Prop -> Prop.',
         'Parameter _base2 : Prop -> Entity -> Prop.'
     ]
     self.assertEqual(expected_coq_lib, coq_lib)
     expression = [ccg_tree.get('sem')]
     coq_sig = convert_coq_signatures_to_nltk(coq_lib)
     nltk_lib, _ = build_dynamic_library(expression, coq_sig)
     lib = merge_dynamic_libraries(coq_sig, nltk_lib, './coqlib.v',
                                   sentence)
     expected_lib = [
         "Parameter _base2 : Prop -> (Entity -> Prop).",
         "Parameter _base1 : Entity -> (Prop -> Prop)."
     ]
     self.assertCountEqual(expected_lib, lib)
Ejemplo n.º 4
0
 def test_entity(self):
     coq_sig = ['Parameter base1 : Entity.', 'Parameter base2 : Prop.']
     nltk_sig = convert_coq_signatures_to_nltk(coq_sig)
     expected_nltk_sig = {'base1': read_type('e'), 'base2': read_type('t')}
     self.assertEqual(expected_nltk_sig, nltk_sig)