def test_create_an_event_with_ldc_time(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") # create a start position event with unknown start and end time event_start_position = aifutils.make_event( g, "http://www.test.edu/event/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/1", event_start_position, SEEDLING_TYPES_NIST['Personnel.StartPosition'], system, 1.0) unknown = LDCTimeComponent(LDCTimeType.UNKNOWN, None, None, None) endBefore = LDCTimeComponent(LDCTimeType.BEFORE, "2016", None, None) aifutils.mark_ldc_time(g, event_start_position, unknown, endBefore, system) # create an attack event with an unknown start date, but definite end date event_attack_unknown = aifutils.make_event( g, "http://www.test.edu/event/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/2", event_attack_unknown, SEEDLING_TYPES_NIST['Conflict.Attack'], system, 1.0) start = LDCTimeComponent(LDCTimeType.AFTER, "2014", "--02", None) end = LDCTimeComponent(LDCTimeType.ON, "2014", "--02", "---21") aifutils.mark_ldc_time(g, event_attack_unknown, start, end, system) self.new_file(g, "test_create_an_event_with_ldc_time.ttl") self.dump_graph(g, "create an event with LDCTime")
def test_event_missing_type(self): # having mulitple type assertions in case of uncertainty is ok, but there must always be at # least one type assertion g = aifutils.make_graph() system = aifutils.make_system_with_uri( g, "http://www.test.edu/testSytem") aifutils.make_event(g, "http://www.test.edu/events/1", system) self.dump_graph(g, "Invalid: Event missing type")
def test_create_event(self): g, system = get_initialized_graph_and_system() # make event with type election election = aifutils.make_event(g, prefix + "event/1", system) aifutils.mark_type(g, prefix + "types/1", election, "Q40231", system, 1.0) # make entity with type person putin = aifutils.make_entity(g, prefix + "entity/putin", system) aifutils.mark_type(g, prefix + "types/2", putin, "Q5", system, 1.0) # make entity with type political region russia = aifutils.make_entity(g, prefix + "enitty/russia", system) aifutils.mark_type(g, prefix + "types/3", russia, "Q1048835", system, 1.0) # add putin as cadidate for the election aifutils.mark_as_argument(g, election, "A1_ppt_theme_candidate", putin, system, .785, prefix + "arg/candidate") # add russia as location for election aifutils.mark_as_argument(g, election, "AM_loc__location", russia, system, .589, prefix + "arg/location") self.new_file(g, "test_create_event.ttl") self.dump_graph(g, "Example of event and entity")
def test_create_an_event_argument_add_invalid_attribute(self): #g = get_initialized_graph() 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") # we make a resource for the event itself event = aifutils.make_event(g, "http://www.test.edu/events/1", system) # mark the event as a Personnel.Elect event; type is encoded separately so we can express # uncertainty about type aifutils.mark_type(g, "http://www.test.edu/assertions/5", event, ldc_ontology.Personnel_Elect, system, 1.0) # create the two entities involved in the event electee = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/6", electee, ldc_ontology.PER, system, 1.0) election_country = aifutils.make_entity( g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/7", election_country, ldc_ontology.GPE, system, 1.0) # link those entities to the event argument1 = aifutils.mark_as_argument( g, event, ldc_ontology.Personnel_Elect_Candidate, electee, system, 0.785) argument2 = aifutils.mark_as_argument( g, event, ldc_ontology.Personnel_Elect_Place, election_country, system, 0.589) aifutils.mark_attribute(g, argument1, interchange_ontology.Irrealis) aifutils.mark_attribute(g, argument1, interchange_ontology.Generic) aifutils.mark_attribute( g, argument2, interchange_ontology.VideoJustificationChannelPicture) aifutils.mark_attribute( g, argument2, interchange_ontology.VideoJustificationChannelSound) self.new_file( g, "test_create_an_event_argument_add_invalid_attribute.ttl") self.dump_graph( g, "Invalid: Semantic Attribute for Event Argument, must be aida:Negated, aida:Hedged" )
def test_create_an_event_add_invalid_attribute(self): #g = get_initialized_graph() 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") # we make a resource for the event itself event = aifutils.make_event(g, "http://www.test.edu/events/1", system) aifutils.mark_attribute( g, event, interchange_ontology.VideoJustificationChannelPicture) self.new_file(g, "test_create_an_event_add_invalid_attribute.ttl") self.dump_graph( g, "Invalid: Semantic Attribute for Event, must be aida:Negated, aida:Hedged, aida:Irrealis, aida:Generic" )
def add_event(self): # add an event event_resource = aifutils.make_event(self.g, self.get_event_uri(), self.system) # add the type type_resource = self.EVENT_TYPES[ random.randint(0, len(self.EVENT_TYPES)) - 1] type_assertion = aifutils.mark_type(self.g, self.get_assertion_uri(), event_resource, type_resource, self.system, 1.0) self.add_justification_and_private_data(type_assertion) # make two arguments for i in range(2): arg = URIRef(type_resource + self.get_random_suffix()) argument = aifutils.mark_as_argument(self.g, event_resource, arg, self.get_random_entity(), self.system, 0.785, self.get_assertion_uri()) self.add_justification_and_private_data(argument)
def test_create_seedling_event_with_event_argument_uri(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") # we make a resource for the event itself event = aifutils.make_event(g, "http://www.test.edu/events/1", system) # mark the event as a Personnel.Elect event; type is encoded separately so we can express # uncertainty about type event_type_string = "Personnel.Elect" aifutils.mark_type(g, "http://www.test.edu/assertions/5", event, SEEDLING_TYPES_NIST[event_type_string], system, 1.0) # create the two entities involved in the event electee = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/7", electee, SEEDLING_TYPES_NIST.Person, system, 1.0) election_country = aifutils.make_entity( g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/7", election_country, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) # link those entities to the event aifutils.mark_as_argument( g, event, SEEDLING_TYPES_NIST[event_type_string] + "_Elect", electee, system, .785, "http://www.test.edu/eventArgument/1") aifutils.mark_as_argument( g, event, SEEDLING_TYPES_NIST[event_type_string] + "_Place", election_country, system, .589, "http://www.test.edu/eventArgument/2") self.new_file( g, "test_create_seedling_event_with_event_argument_uri.ttl") self.dump_graph(g, "Example of seedling event with event assertion URI")
def test_create_an_event(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") # we make a resource for the event itself event = aifutils.make_event(g, "http://www.test.edu/events/1", system) # mark the event as a Personnel.Elect event; type is encoded separately so we can express # uncertainty about type aifutils.mark_type(g, "http://www.test.edu/assertions/5", event, SEEDLING_TYPES_NIST['Personnel.Elect'], system, 1.0) # create the two entities involved in the event electee = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/6", electee, SEEDLING_TYPES_NIST.Person, system, 1.0) election_country = aifutils.make_entity( g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/7", election_country, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) # link those entities to the event arg = URIRef(SEEDLING_TYPES_NIST['Personnel.Elect'] + "_Elect") aifutils.mark_as_argument(g, event, arg, electee, system, 0.785) arg2 = URIRef(SEEDLING_TYPES_NIST['Personnel.Elect'] + "_Place") aifutils.mark_as_argument(g, event, arg2, election_country, system, 0.589) self.new_file(g, "test_create_an_event.ttl") self.dump_graph(g, "Example of creating an event")
def add_detections_to_graph(g, detections, parent_id, imgid, is_keyframe): str_append = 'Keyframe' if is_keyframe else 'JPG' if is_keyframe: vidid = imgid.split('_')[0] for ii, det in enumerate(detections): label = det['label'] score = det['score'] bbox = det['bbox'] model = det['model'] if score < score_threshold: continue if model == 'coco': sys = system_co elif model == 'voc': sys = system_pa elif model == 'oi': sys = system_oi elif model == 'ws': sys = system_ws elif model == 'coco/J': sys = system_co elif model == 'voc/J': sys = system_pa elif model == 'oi/J': sys = system_oi elif model == 'ws/J': sys = system_ws else: raise for iii, ont_id in enumerate(class2ont[label]): ont_name = ont2name[ont_id] labelrdf = LDC_ONTOLOGY.term(ont_name) if ont_name in ldc_entity_types_new: eid = f"http://www.columbia.edu/AIDA/DVMM/Entities/ObjectDetection/RUN00010/{str_append}/{imgid}/{ii}" entity = aifutils.make_entity(g, eid, sys) entity_dict[eid] = entity type_assertion = aifutils.mark_type( g, eid.replace('Entities', 'TypeAssertions') + f'/{iii}', entity, labelrdf, sys, score) bb = Bounding_Box((bbox[0], bbox[1]), (bbox[2], bbox[3])) if is_keyframe: justif = aifutils.mark_keyframe_video_justification( g, [entity, type_assertion], vidid, imgid, bb, sys, score) else: justif = aifutils.mark_image_justification( g, [entity, type_assertion], imgid, bb, sys, score) aifutils.add_source_document_to_justification( g, justif, parent_id) aifutils.mark_informative_justification(g, entity, justif) #aifutils.mark_private_data(g, entity, json.dumps({}), sys) #if ont_name.split('.')[0] in allowed_to_have_name: # aifutils.mark_name(g, entity, class_names[label].split('(')[-1][:-1]) else: eid = f"http://www.columbia.edu/AIDA/DVMM/Events/ObjectDetection/RUN00010/{str_append}/{imgid}/{ii}" event = aifutils.make_event(g, eid, sys) event_dict[eid] = event type_assertion = aifutils.mark_type( g, eid.replace('Events', 'TypeAssertions') + f'/{iii}', event, labelrdf, sys, score) bb = Bounding_Box((1, 1), image_shape[imgid]) if is_keyframe: justif = aifutils.mark_keyframe_video_justification( g, [event, type_assertion], vidid, imgid, bb, sys, score) else: justif = aifutils.mark_image_justification( g, [event, type_assertion], imgid, bb, sys, score) aifutils.add_source_document_to_justification( g, justif, parent_id) aifutils.mark_informative_justification(g, event, justif)
def test_create_compound_justification(self): g = aifutils.make_graph() system = aifutils.make_system_with_uri(g, "http://www.test.edu/system") event = aifutils.make_event( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#V779961.00010", system) event_type_assertion = aifutils.mark_type( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#assertion-1", event, SEEDLING_TYPES_NIST['Personnel.Elect'], system, 1.0) # create the two entities involved in the event putin = aifutils.make_entity( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#E781167.00398", system) person_type_assertion = aifutils.mark_type( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#assertion-2", putin, SEEDLING_TYPES_NIST.Person, system, 1.0) russia = aifutils.make_entity( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#E779954.00004", system) gpe_type_assertion = aifutils.mark_type( g, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#assertion-3", russia, SEEDLING_TYPES_NIST.GeopoliticalEntity, system, 1.0) # link those entities to the event electee_argument = aifutils.mark_as_argument( g, event, SEEDLING_TYPES_NIST['Personnel.Elect_Elect'], putin, system, 0.785, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#assertion-4" ) place_argument = aifutils.mark_as_argument( g, event, SEEDLING_TYPES_NIST['Personnel.Elect_Place'], russia, system, 0.589, "https://tac.nist.gov/tracks/SM-KBP/2019/LdcAnnotations#assertion-5" ) # 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 text_justification = aifutils.make_text_justification( g, "NYT_ENG_20181231", 42, 143, system, 0.973) aifutils.mark_justification(g, person_type_assertion, text_justification) aifutils.mark_justification(g, putin, text_justification) aifutils.add_source_document_to_justification( g, text_justification, "NYT_PARENT_ENG_20181231_03") bb1 = Bounding_Box((123, 45), (167, 98)) # let's suppose we also have evidence from an image image_justification = aifutils.make_image_justification( g, "NYT_ENG_20181231_03", bb1, system, 0.123) bb2 = Bounding_Box((234, 56), (345, 101)) # and also a video where the entity appears in a keyframe keyframe_video_justification = aifutils.make_keyframe_video_justification( g, "NYT_ENG_20181231_03", "keyframe ID", bb2, system, .0234) #and also a video where the entity does not appear in a keyframe shot_video_justification = aifutils.make_shot_video_justification( g, "SOME_VIDEO", "some shot ID", system, 0.487) # and even audio! audio_justification = aifutils.make_audio_justification( g, "NYT_ENG_201181231", 4.566, 9.876, system, 0.789) # combine all justifications into single justifiedBy triple with new confidence aifutils.mark_compound_justification(g, [electee_argument], [ text_justification, image_justification, keyframe_video_justification, shot_video_justification, audio_justification ], system, .321) aifutils.mark_compound_justification( g, [place_argument], [text_justification, image_justification], system, 0.543) self.new_file(g, "test_create_compound_justification.ttl") self.dump_graph(g, "Example of compound justification")
def test_use_subgraph_confidences_to_show_mutually_exclusive_linked_event_argument_options( 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") # we make a resource for the event itself event = aifutils.make_event(g, "http://www.test.edu/events/1", system) # mark the event as a Personnel.Elect event; type is encoded separately so we can express uncertainty about type aifutils.mark_type(g, "http://www.test.edu/assertions/5", event, SEEDLING_TYPES_NIST['Conflict.Attack'], system, 1.0) # create the two entities involved in the event bob = aifutils.make_entity(g, "http://www.test.edu/entities/1", system) aifutils.mark_type(g, "http://www.test.edu/assertions/6", bob, SEEDLING_TYPES_NIST.Person, system, 1.0) fred = aifutils.make_entity(g, "http://www.test.edu/entities/2", system) aifutils.mark_type(g, "http://www.test.edu/assertions/7", fred, SEEDLING_TYPES_NIST.Person, system, 1.0) # we link all possible argument fillers to the event bob_hit_fred_assertions = [ aifutils.mark_as_argument( g, event, URIRef(SEEDLING_TYPES_NIST['Conflict.Attack'] + "_Attacker"), bob, system, None), aifutils.mark_as_argument( g, event, URIRef(SEEDLING_TYPES_NIST['Conflict.Attack'] + "_Target"), fred, system, None) ] fred_hit_bob_assertions = [ aifutils.mark_as_argument( g, event, URIRef(SEEDLING_TYPES_NIST['Conflict.Attack'] + "_Attacker"), fred, system, None), aifutils.mark_as_argument( g, event, URIRef(SEEDLING_TYPES_NIST['Conflict.Attack'] + "_Target"), bob, system, None) ] # then we mark these as mutually exclusive # we also mark confidence 0.2 that neither of these are true aifutils.mark_as_mutually_exclusive( g, { tuple(bob_hit_fred_assertions): 0.6, tuple(fred_hit_bob_assertions): 0.2 }, system, 0.2) self.new_file( g, "test_use_subgraph_confidences_to_show_mutually_exclusive_linked_event_argument_options.ttl" ) self.dump_graph( g, "Example of subgraph confidences to show mutually exclusive linked event argument options" )