def test_SetsActorAsPredicate(self): event = CDEvent(Primitives.EXPEL) event.subject = 'star' predicates = converter.convert_to_prolog(event) self.assertTrue( any(pred.startswith("actorOfEvent(star,") for pred in predicates))
def test_sets_attributes_correctly(self): converter = cd_converter.CDConverter() fake_cd_event = CDEvent(Primitives.EXPEL) result = converter.convert_cd_event_to_action_events(fake_cd_event) self.assertEqual(result[0].affected_attribute, EntityAttributes.inside_subject) self.assertEqual(result[0].attribute_outcome, EntityAttributeOutcomes.outside)
def test_returns_action_event(self): converter = cd_converter.CDConverter() fake_cd_event = CDEvent(Primitives.EXPEL) result = converter.convert_cd_event_to_action_events(fake_cd_event) self.assertIsInstance(result, list) self.assertIsInstance(result[0], ActionEvent)
def test_SetsObjectInPredicate(self): event = CDEvent(Primitives.EXPEL) event.event_object = 'particle' predicates = converter.convert_to_prolog(event) self.assertTrue( any( pred.startswith("objectOfEvent(particle,") for pred in predicates))
def test_ReturnsList(self): event = CDEvent(Primitives.EXPEL) result = converter.convert_to_prolog(event) self.assertIsInstance(result, list) for pred in result: self.assertIsInstance(pred, str)
def test_sets_subject_and_object_correctly(self): converter = cd_converter.CDConverter() fake_cd_event = CDEvent(Primitives.EXPEL) fake_cd_event.subject = "Star" fake_cd_event.event_object = "particle" result = converter.convert_cd_event_to_action_events(fake_cd_event) self.assertEqual(result[0].subject, "Star") self.assertEqual(result[0].event_object, "particle")
def test_sets_order_of_action_events_correctly(self): converter = cd_converter.CDConverter() cd_event_1 = CDEvent(Primitives.EXPEL) cd_event_2 = CDEvent(Primitives.PTRANS) cd_event_3 = CDEvent(Primitives.INGEST) cd_event_1.preceding = cd_event_2 cd_event_2.preceding = cd_event_3 results = converter.convert_cd_event_to_action_events(cd_event_1) self.assertEqual(len(results), 3, 'Should return 3 action events from nested CD input') self.assertEqual(results[0].affected_attribute, EntityAttributes.inside_subject) self.assertEqual(results[0].attribute_outcome, EntityAttributeOutcomes.inside) self.assertEqual(results[1].affected_attribute, EntityAttributes.position) self.assertEqual(results[2].affected_attribute, EntityAttributes.inside_subject) self.assertEqual(results[2].attribute_outcome, EntityAttributeOutcomes.outside)
def _merge_definitions(verb_definition: CDDefinition, prim_defintition: CDDefinition): '''Merges a verb definition with a primitive definition, to output a CDEvent''' new_def = CDEvent(prim_defintition.preceding) for attr in [ 'primitive', 'sense_id', 'affected_attribute', 'attribute_outcome' ]: attr_1 = verb_definition.__getattribute__(attr) attr_2 = prim_defintition.__getattribute__(attr) if attr_1 and attr_2 and (attr_1 != attr_2): raise ValueError('Conflicting values of ' + attr) else: explicit_value = verb_definition.__getattribute__(attr) setattr(new_def, attr, explicit_value) return new_def