def test_create_a_simple_cluster_with_handle(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_type(g, "http://www.test.edu/assertions/1", vladimir_putin, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, vladimir_putin, "Vladimir Putin") 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") # 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_a_simple_cluster_with_handle.ttl") self.dump_graph(g, "create a simple cluster with handle")
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_create_seedling_entity_with_alternate_names(self): g = aifutils.make_graph() # 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) # 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. type_assertion = aifutils.mark_type( g, "http://www.test.org/assertions/1", entity, SEEDLING_TYPES_NIST.Person, system, 1.0) # This is just a test to make sure that validation works for the different # mark types. Rare that you would have all three with a single entity. aifutils.mark_name(g, entity, "Name One") aifutils.mark_name(g, entity, "N. One") aifutils.mark_name(g, entity, "N-Money") aifutils.mark_text_value(g, entity, "TextValue") aifutils.mark_numeric_value_as_double(g, entity, 100) aifutils.mark_numeric_value_as_long(g, entity, 100) aifutils.mark_numeric_value_as_string(g, entity, "100") self.new_file( g, "test_create_a_seedling_entity_with_alternate_names.ttl") self.dump_graph(g, "Example of seedling entity with alternate names")
def test_create_a_cluster_with_link_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") putin = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/1", putin, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, putin, "Путин") vladimir_putin = aifutils.make_entity( g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/2", vladimir_putin, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, vladimir_putin, "Vladimir 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") # person 1 is definitely in the cluster, person 2 is probably in the cluster aifutils.mark_as_possible_cluster_member(g, putin, putin_cluster, 1.0, system) aifutils.mark_as_possible_cluster_member(g, vladimir_putin, putin_cluster, 0.71, system) # also we can link this entity to something in an external KB aifutils.link_to_external_kb(g, putin_cluster, "freebase.FOO", system, .398) self.new_file(g, "test_create_a_cluster_with_link_and_confidence.ttl") self.dump_graph(g, "create a cluster with link and confidence")
def add_entity(self): # add an entity entity_resource = aifutils.make_entity(self.g, self.get_entity_uri(), self.system) self.entity_resource_list.append(entity_resource) # sometimes add hasName, textValue, or numericValue, NOTE: This does not check type!!! rand = random.random() if rand < 0.15: aifutils.mark_name(self.g, entity_resource, self.get_random_string(5)) elif rand < 0.3: aifutils.mark_text_value(self.g, entity_resource, self.get_random_string(7)) elif rand < 0.4: aifutils.mark_numeric_value_as_double(self.g, entity_resource, random.random()) # set the type type_to_use = self.get_random_entity() type_assertion = aifutils.mark_type(self.g, self.get_assertion_uri(), entity_resource, type_to_use, self.system, 1.0) self.add_justification_and_private_data(type_assertion)
def test_create_hierarchical_cluster(self): # we want to say that the cluster of Trump entities might be the same as the cluster of the president entities 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') # create president entities president_usa = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/1", president_usa, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) aifutils.mark_name(g, president_usa, "the president") new_president = aifutils.make_entity(g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/2", president_usa, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) aifutils.mark_name(g, president_usa, "the newly-inaugurated president") president_45 = aifutils.make_entity(g, "http://www.test.edu/entities/3", system) aifutils.mark_type(g, "http://www.test.edu/assertions/3", president_usa, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) aifutils.mark_name(g, president_usa, "the 45th president") # cluster president entities president_cluster = aifutils.make_cluster_with_prototype( g, "http://www.test.edu/clusters/president", president_usa, system) aifutils.mark_as_possible_cluster_member(g, president_usa, president_cluster, 1, system) aifutils.mark_as_possible_cluster_member(g, new_president, president_cluster, .9, system) aifutils.mark_as_possible_cluster_member(g, president_45, president_cluster, .9, system) # create Trump entities donald_trump = aifutils.make_entity(g, "http://www.test.edu/entities/4", system) aifutils.mark_type(g, "http://www.test.edu/assertions/4", president_usa, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, president_usa, "Donald Trump") trump = aifutils.make_entity(g, "http://www.test.edu/entities/5", system) aifutils.mark_type(g, "http://www.test.edu/assertions/5", president_usa, SEEDLING_TYPES_NIST.Person, system, 1.0) aifutils.mark_name(g, president_usa, "Trump") # cluster trump entities trump_cluster = aifutils.make_cluster_with_prototype( g, "http://www.test.edu/clusters/trump", donald_trump, system) aifutils.mark_as_possible_cluster_member(g, donald_trump, trump_cluster, 1, system) aifutils.mark_as_possible_cluster_member(g, trump, trump_cluster, .9, system) aifutils.mark_as_possible_cluster_member(g, president_cluster, trump_cluster, .6, system) self.new_file(g, "test_create_hierarchical_cluster.ttl") self.dump_graph(g, "Seedling hierarchical cluster")