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)
def resolve_types_in_signature(signature): signature = {k : v for k, v in signature.items() if v is not None} for predicate, pred_type in signature.items(): pred_type_str = str(pred_type) pred_type_str_resolved = re.sub(r'\?', r't', pred_type_str) signature[predicate] = read_type(pred_type_str_resolved) return signature
def convert_coq_to_nltk_type(coq_type): """ Given a coq_type specification such as: Parameter _love : Entity -> Entity -> Prop. return the equivalent NLTK type specification: {'_love' : read_type('<e, <e, t>>')} """ assert isinstance(coq_type, str) coq_type_list = coq_type.split() assert len(coq_type_list) >= 4, 'Wrong coq_type format: %s' % coq_type parameter, surface, colon = coq_type_list[:3] assert parameter == 'Parameter' and colon == ':' # This list contains something like ['Entity', '->', 'Prop', '->', 'Prop'...] type_sig = coq_type_list[3:] type_ids = [] for i, type_item in enumerate(type_sig): assert (i % 2 == 1) == (type_item == '->') if type_item.startswith('Entity'): type_ids.append('e') elif type_item.startswith('Prop'): type_ids.append('t') elif type_item.startswith('Event'): type_ids.append('e') elif type_item != '->': raise(ValueError('Invalid type name: %s in %s' % (type_item, coq_type))) assert len(type_ids) > 0 if len(type_ids) == 1: nltk_type_str = type_ids[0] else: # Create a string like "<e, <t, t>>" nltk_type_str = '<' + ', <'.join(type_ids[:-1]) \ + ', ' + type_ids[-1] + '>' * len(type_ids) return {surface : read_type(nltk_type_str)}
def test_entitypropertyAndpropertyentity(self): coq_type = 'Parameter base : (Entity -> Prop) -> Prop.' nltk_type = convert_coq_to_nltk_type(coq_type) expected_nltk_type = {'base' : read_type('<<e,t>,<t,e>>')} self.assertEqual(expected_nltk_type, nltk_type)
def test_property(self): coq_type = 'Parameter base : Prop.' nltk_type = convert_coq_to_nltk_type(coq_type) expected_nltk_type = {'base' : read_type('t')} self.assertEqual(expected_nltk_type, nltk_type)
def test_entity(self): coq_type = 'Parameter base : Entity.' nltk_type = convert_coq_to_nltk_type(coq_type) expected_nltk_type = {'base' : read_type('e')} self.assertEqual(expected_nltk_type, nltk_type)