def test_create_an_entity_with_uncertainty_about_its_type(self): g = aifutils.make_graph() g.bind('ldcOnt', SEEDLING_TYPES_NIST.uri) # every AIF needs an object for the system responsible for creating it system = aifutils.make_system_with_uri( g, "http://www.test.edu/testSystem") entity = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) entity_is_a_person = aifutils.mark_type( g, "http://www.test.org/assertions/1", entity, SEEDLING_TYPES_NIST.Person, system, 0.5) entity_is_an_organization = aifutils.mark_type( g, "http://www.test.org/assertions/2", entity, SEEDLING_TYPES_NIST.Organization, system, 0.2) aifutils.mark_text_justification(g, [entity, entity_is_a_person], "NYT_ENG_201181231", 42, 143, system, 0.6) aifutils.mark_text_justification(g, [entity, entity_is_an_organization], "NYT_ENG_201181231", 343, 367, system, 0.3) aifutils.mark_as_mutually_exclusive( g, { tuple([entity_is_a_person]): 0.5, tuple([entity_is_an_organization]): 0.2 }, system, None) self.new_file( g, "test_create_an_entity_with_uncertainty_about_its_type.ttl") self.dump_graph(g, "Example of entity with uncertainty about type")
def add_justification_and_private_data(self, resource): docId = self.get_random_doc_id() # justify the type assertion aifutils.mark_text_justification(self.g, resource, docId, 1029, 1033, self.system, 0.973) # add some private data aifutils.mark_private_data(self.g, resource, "{ 'provenance' : '" + docId + "' }", self.system)
def test_make_entity(self): g = make_graph() system = make_system_with_uri(g, "http://www.test.edu/system") entity = make_entity(g, "http://www.test.edu/entities/1", system) type_assertion = mark_type(g, "http://www.test.edu/assertions/1", entity, AIDA_PROGRAM_ONTOLOGY.Person, system, 1.0) mark_text_justification(g, [entity, type_assertion], "NYT_ENG_20181231", 42, 143, system, 0.973) self.dump_graph(g, "Example of creating an entity") self.assertEqual([type_assertion], get_type_assertions(g, entity))
def test_create_an_entity_with_information_justification(self): g = aifutils.make_graph() g.bind('ldcOnt', SEEDLING_TYPES_NIST.uri) # every AIF needs an object for the system responsible for creating it system = aifutils.make_system_with_uri( g, 'http://www.test.edu/testSystem') # Two people, probably the same person vladimir_putin = aifutils.make_entity( g, "http://www.test.edu/entities/1", system) aifutils.mark_name(g, vladimir_putin, "Vladimir Putin") type_assertion = aifutils.mark_type( g, "http://www.test.org/assertions/1", vladimir_putin, SEEDLING_TYPES_NIST.Person, system, 1.0) text_justification_1 = aifutils.mark_text_justification( g, [vladimir_putin, type_assertion], "HC00002Z0", 0, 10, system, 1.0) aifutils.mark_informative_justification(g, vladimir_putin, text_justification_1) putin = aifutils.make_entity(g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/2", putin, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, putin, "Путин") # create a cluster with prototype putin_cluster = aifutils.make_cluster_with_prototype( g, "http://www.test.edu/clusters/1", vladimir_putin, system, "Vladimir Putin") text_justification_2 = aifutils.mark_text_justification( g, [putin, type_assertion], "HC00002Z0", 0, 10, system, 1.0) aifutils.mark_informative_justification(g, putin_cluster, text_justification_2) # person 1 is definitely in the cluster, person 2 is probably in the cluster aifutils.mark_as_possible_cluster_member(g, putin, putin_cluster, 0.71, system) self.new_file( g, "test_create_an_entity_and_cluster_with_informative_mention.ttl") self.dump_graph( g, "create an entity and cluster with informative mention")
def test_make_entity(self): g = aifutils.make_graph() system = aifutils.make_system_with_uri(g, "http://www.test.edu/system") entity = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) type_assertion = aifutils.mark_type( g, "http://www.test.edu/assertions/1", entity, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_text_justification(g, [entity, type_assertion], "NYT_ENG_20181231", 42, 143, system, 0.973) self.new_file(g, "test_make_an_entity.ttl") self.dump_graph(g, "Example of creating an entity") self.assertEqual([type_assertion], aifutils.get_type_assertions(g, entity))
def test_create_an_entity_with_all_justification_types_and_confidence( self): g = aifutils.make_graph() g.bind('ldcOnt', SEEDLING_TYPES_NIST.uri) # every AIF needs an object for the system responsible for creating it system = aifutils.make_system_with_uri( g, "http://www.test.edu/testSystem") # it doesn't matter what URI we give entities, events, etc. so long as they are # unique entity = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) # in order to allow uncertainty about the type of an entity, we don't mark an # entity's type directly on the entity, but rather make a separate assertion for it # its URI doesn't matter either type_assertion = aifutils.mark_type( g, "http://www.test.org/assertions/1", entity, SEEDLING_TYPES_NIST.Person, system, 1.0) # the justification provides the evidence for our claim about the entity's type # we attach this justification to both the type assertion and the entity object # itself, since it provides evidence both for the entity's existence and its type. # in TA1 -> TA2 communications, we attach confidences at the level of justifications aifutils.mark_text_justification(g, [entity, type_assertion], "NYT_ENG_20181231", 42, 143, system, 0.973) # let's suppose we also have evidence from an image bb1 = Bounding_Box((123, 45), (167, 98)) aifutils.mark_image_justification(g, [entity, type_assertion], "NYT_ENG_20181231_03", bb1, system, 0.123) # and also a video where the entity appears in a keyframe bb2 = Bounding_Box((123, 45), (167, 98)) aifutils.mark_keyframe_video_justification(g, [entity, type_assertion], "NYT_ENG_20181231_03", "keyframe ID", bb2, system, 0.234) # and also a video where the entity does not appear in a keyframe aifutils.mark_shot_video_justification(g, [entity, type_assertion], "SOME_VIDEO", "some shot ID", system, 0.487) # and even audio! aifutils.mark_audio_justification(g, [entity, type_assertion], "NYT_ENG_201181231", 4.566, 9.876, system, 0.789) # also we can link this entity to something in an external KB aifutils.link_to_external_kb(g, entity, "freebase.FOO", system, .398) # let's mark our entity with some arbitrary system-private data. You can attach such data # to nearly anything aifutils.mark_private_data(g, entity, "{ 'hello' : 'world' }", system) self.new_file( g, "test_create_an_entity_with_all_justification_types_and_confidence.ttl" ) self.dump_graph(g, "Example of entity with all justifications")