def test_SetsPrecedingEvents(self): converter = cd_converter.CDConverter() arg0 = VerbArgumentInstance('emitting entity', 'PAG', 'Barbara') arg1 = VerbArgumentInstance('thing emitted', 'PPT', 'radiation') mock_verb_data = VerbSense("nom", [arg0, arg1]) fake_verb_def = CDDefinition(Primitives.INGEST) fake_verb_def.sense_id = 'nom' fake_verb_def.preceding = CDDefinitionPredecessorWrapper() pred_def = CDDefinition(Primitives.PROPEL) fake_verb_def.preceding.definition = pred_def my_dict = {'nom': fake_verb_def} def getitem(name): return my_dict[name] mock_dictionary = mock.MagicMock() mock_dictionary.__getitem__.side_effect = getitem with patch('condep.definitions.verbs.dictionary', new = mock_dictionary): event = converter.convert_verb_event_to_cd_event(mock_verb_data) self.assertEqual(event.preceding.primitive, Primitives.PROPEL)
def test_CallsPrimitiveDictionary(self): converter = cd_converter.CDConverter() arg0 = VerbArgumentInstance('emitting entity', 'PAG', 'Barbara') arg1 = VerbArgumentInstance('thing emitted', 'PPT', 'radiation') mock_verb_data = VerbSense("gobble", [arg0, arg1]) fake_verb_def = CDDefinition(Primitives.INGEST) fake_verb_def.sense_id = 'gobble' my_dict = {'gobble': fake_verb_def} def getitem(name): return my_dict[name] mock_dictionary = mock.MagicMock() mock_dictionary.__getitem__.side_effect = getitem with patch('condep.definitions.verbs.dictionary', new=mock_dictionary): prim_dict = {Primitives.INGEST: fake_verb_def} def getprim(name): return prim_dict[name] mock_prim_dictionary = mock.MagicMock() mock_prim_dictionary.__getitem__.side_effect = getprim with patch('condep.definitions.primitives.dictionary', new=mock_prim_dictionary): converter.convert_verb_event_to_cd_event(mock_verb_data) mock_prim_dictionary.__getitem__.assert_any_call( Primitives.INGEST)
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
def test_handlesComplexArguments(self): converter = cd_converter.CDConverter() arg0 = VerbArgumentInstance(None, 'PAG', 'Barbara') arg0 = VerbArgumentInstance('position before', 'DIR', 'Preston') mock_verb_data = VerbSense("nom", [arg0]) fake_verb_def = CDDefinition(Primitives.INGEST) fake_verb_def.sense_id = 'nom' my_dict = {'nom': fake_verb_def} def getitem(name): return my_dict[name] mock_dictionary = mock.MagicMock() mock_dictionary.__getitem__.side_effect = getitem with patch('condep.definitions.verbs.dictionary', new = mock_dictionary): with patch('condep.prolog.prolog_service.query_prolog'): event = converter.convert_verb_event_to_cd_event(mock_verb_data) self.assertDictContainsSubset({'position_before':'Preston'}, event.object_attributes)
def test_CallsVerbDictionary(self): converter = cd_converter.CDConverter() arg0 = VerbArgumentInstance('emitting entity', 'PAG', 'black hole') arg1 = VerbArgumentInstance('thing emitted', 'PPT', 'radiation') mock_verb_data = VerbSense("spew", [arg0, arg1]) my_dict = {'spew': CDDefinition(Primitives.EXPEL)} def getitem(name): return my_dict[name] mock_dictionary = mock.MagicMock() mock_dictionary.__getitem__.side_effect = getitem with patch('condep.definitions.verbs.dictionary', new=mock_dictionary): converter.convert_verb_event_to_cd_event(mock_verb_data) mock_dictionary.__getitem__.assert_any_call('spew')
from condep.parsing.cd_definitions import CDDefinition, CDDefinitionPredecessorWrapper from condep.action_event import EntityAttributes from condep.action_event import EntityAttributeOutcomes from condep.primitives import Primitives dictionary = dict() # type: Dict[str, object] ##EXPEL _emit = CDDefinition(Primitives.EXPEL) _emit.sense_id = 'emit' _emit.object_override = 'kind(radiation)' _emit.affected_attribute = EntityAttributes.inside_subject _emit.attribute_outcome = EntityAttributeOutcomes.outside dictionary['emit'] = _emit _eject = CDDefinition(Primitives.EXPEL) _eject.sense_id = 'eject' _eject.affected_attribute = EntityAttributes.inside_subject _eject.attribute_outcome = EntityAttributeOutcomes.outside dictionary['eject'] = _eject _leave = CDDefinition(Primitives.EXPEL) _leave.preceding = CDDefinitionPredecessorWrapper() _leave.preceding.definition = CDDefinition(Primitives.PTRANS) _leave.preceding.definition.affected_attribute = EntityAttributes.distance_from_subject
def test_can_take_preceding_definition(self): definition = CDDefinition(Primitives.INGEST) definition.sense_id = 'fall' definition.preceding = CDDefinition(Primitives.PROPEL)
from condep.parsing.cd_definitions import CDDefinition, CDDefinitionPredecessorWrapper from condep.action_event import EntityAttributes from condep.action_event import EntityAttributeOutcomes from condep.primitives import Primitives dictionary = dict() # type: Dict[str, object] ##EXPEL _OUTPUT01 = CDDefinition(Primitives.EXPEL) dictionary['output.v.01'] = _OUTPUT01 ##INGEST _heat = CDDefinition(Primitives.INGEST) _heat.sense_id = 'heat.01' _heat.object_override = 'Energy' _heat.actor_override = 'Object' _heat.preceding = CDDefinitionPredecessorWrapper() _heat.preceding.applies_to = 'Subject' _heat.preceding.definition = CDDefinition(Primitives.EXPEL) dictionary['heat.v.01'] = _heat _charge = CDDefinition(Primitives.INGEST) _charge.object_override = 'Charge' _charge.actor_override = 'Object'