def audio_file_liebestraum(print_queries, submit_queries): # A file that we're annotating contenturl = "https://trompa-mtg.upf.edu/data/anno-component-test/SMC_005.wav" get_audio = query_audioobject.query_audioobject(contenturl=contenturl) if submit_queries: audio_id = send_query_and_get_id(get_audio, "AudioObject") if audio_id: print("get AudioObject") if print_queries: print(get_audio) return audio_id[0] audio = audioobject.mutation_create_audioobject( name="Liebestraum No. 3", title="Liebestraum No. 3", creator="https://github.com/trompamusic/audio-annotator", contributor="https://mtg.upf.edu/", source=contenturl, format_="audio/wav", encodingformat="audio/wav", contenturl=contenturl) audio_id = "audio-node-id" print("AudioObject") if print_queries: print(audio) if submit_queries: audio_id = send_query_and_get_id(audio, "CreateAudioObject") return audio_id
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" # Our vocabulary vocabulary_ids = fixed_vocabulary(print_queries, submit_queries) audio_id = audio_file_liebestraum(print_queries, submit_queries) # The annotation target. We're annotating the URL that is at the `source` field of the above audio object target = annotation.create_annotation_ce_target( creator=user_vcard, field= "source", # we want to annotate the URL that is at the 'source' field of the AudioObject node # Optionally, set the 'fragment' parameter to annotate a time range in the file ) target_id = "ce-target-id" print("AnnotationCETarget") if print_queries: print(target) if submit_queries: target_id = send_query_and_get_id(target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") target_join = annotation.merge_annotation_target_target( target_id, audio_id) if print_queries: print(target_join) if submit_queries: send_query_and_get_id(target_join) # The annotation ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging) ann_id = "annotation-id" print("Annotation") if print_queries: print(ann) if submit_queries: ann_id = send_query_and_get_id(ann, "CreateAnnotation") # Join the annotation with the AnnotationCETarget annotation_target_join = annotation.merge_annotation_targetnode( ann_id, target_id) # Join the annotation with the Body. In this case, the body is the "Happy" DefinedTerm # from the DefinedTermSet that we provided body_id = vocabulary_ids["dt_happy_id"] annotation_body_join = annotation.merge_annotation_bodynode( ann_id, body_id) print("Annotation - link to target and body") if print_queries: print(annotation_target_join) print(annotation_body_join) if submit_queries: send_query_and_get_id(annotation_target_join) send_query_and_get_id(annotation_body_join)
def fixed_vocabulary(print_queries: bool, submit_queries: bool): """A closed vocabulary of tags that someone can use""" admin_vcard = "https://alastair.trompa-solid.upf.edu/profile/card#me" dts = definedterm.create_defined_term_set(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_TAG_COLLECTION], name="Mood") dts_id = "definedtermset-id" print("DefinedTermSet") if print_queries: print(dts) if submit_queries: dts_id = send_query_and_get_id(dts, "CreateDefinedTermSet") dt_happy = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_TAG_COLLECTION_ELEMENT], termcode="Happy") dt_sad = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_TAG_COLLECTION_ELEMENT], termcode="Sad") dt_happy_id = "definedterm-happy-id" dt_sad_id = "definedterm-sad-id" print("DefinedTerms") if print_queries: print(dt_happy) print(dt_sad) if submit_queries: dt_happy_id = send_query_and_get_id(dt_happy, "CreateDefinedTerm") dt_sad_id = send_query_and_get_id(dt_sad, "CreateDefinedTerm") dts_join_happy = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_happy_id) dts_join_sad = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_sad_id) print("Join DefinedTerm to DefinedTermSet") if print_queries: print(dts_join_happy) print(dts_join_sad) if submit_queries: send_query_and_get_id(dts_join_happy) send_query_and_get_id(dts_join_sad) return {"dts_id": dts_id, "dt_happy_id": dt_happy_id, "dt_sad_id": dt_sad_id}
def main(print_queries: bool, submit_queries: bool): admin_vcard = "https://alastair.trompa-solid.upf.edu/profile/card#me" # A vocabulary, this is two tags "Happy and "Sad" vocabulary_ids = fixed_vocabulary(print_queries, submit_queries) dts_id = vocabulary_ids["dts_id"] # A collection of motivations (bowing instructions) fixed_motivations = motivation_collection(print_queries, submit_queries) motivation_dts_id = fixed_motivations["dts_id"] # A 'template' of the rating that we're using. This can be used to show a graphical widget, # and also as a common template that can be used to join together multiple annotations rating_definition = rating.create_rating_definition(creator=admin_vcard, worstrating=0, bestrating=10) rating_definition_id = "rating-definition-id" print("Rating (definition)") if print_queries: print(rating_definition) if submit_queries: rating_definition_id = send_query_and_get_id(rating_definition, "CreateRating") # A plain textbox that can be used to make an annotation with motivation oa:commenting commenting_motivation = "http://www.w3.org/ns/oa#commenting" # a smaller textbox that can be used with oa:commenting tagging_motivation = "http://www.w3.org/ns/oa#tagging" # Make our toolkit - this is an itemlist with a special additionalType # TODO: Currently we're making queries manually. Should have related methods in trompace.client # to wrap up the complexity in making multiple queries toolkit = annotation.create_annotation_toolkit( creator=admin_vcard, name="Creatve feedback annotation", description= "A set of annotations that I like to use when giving feedback to people" ) toolkit_item_vocabulary = annotation.create_annotation_toolkit_element( creator=admin_vcard, name="Choose a mood!") toolkit_item_motivations = annotation.create_annotation_toolkit_element( creator=admin_vcard, name="Bowing instructions") toolkit_item_rating = annotation.create_annotation_toolkit_element( creator=admin_vcard, name="Rate this item") toolkit_item_motivation = annotation.create_annotation_toolkit_element( creator=admin_vcard, name="Tell us your thoughts", itemurl=commenting_motivation) toolkit_item_tagging = annotation.create_annotation_toolkit_element( creator=admin_vcard, name="One word tag", itemurl=tagging_motivation) itemlist_id = "itemlist-id" listitem_vocab_id = "listitem-vocab-id" listitem_motivations_id = "listitem-motivations-id" listitem_rating_id = "listitem-rating-id" listitem_commenting_id = "listitem-commenting-id" listitem_tagging_id = "listitem-tagging-id" print("Toolkit - ItemList and ListItems") if print_queries: print(toolkit) print(toolkit_item_vocabulary) print(toolkit_item_motivations) print(toolkit_item_rating) print(toolkit_item_motivation) print(toolkit_item_tagging) if submit_queries: itemlist_id = send_query_and_get_id(toolkit, "CreateItemList") listitem_vocab_id = send_query_and_get_id(toolkit_item_vocabulary, "CreateListItem") listitem_motivations_id = send_query_and_get_id( toolkit_item_motivations, "CreateListItem") listitem_rating_id = send_query_and_get_id(toolkit_item_rating, "CreateListItem") listitem_commenting_id = send_query_and_get_id(toolkit_item_motivation, "CreateListItem") listitem_tagging_id = send_query_and_get_id(toolkit_item_tagging, "CreateListItem") # Join toolkit items with the thing that they point to join_vocab = itemlist.mutation_add_listitem_item(listitem_vocab_id, dts_id) join_motivations = itemlist.mutation_add_listitem_item( listitem_motivations_id, motivation_dts_id) join_rating = itemlist.mutation_add_listitem_item(listitem_rating_id, rating_definition_id) print("Toolkit - join ListItems with item") if print_queries: print(join_vocab) print(join_motivations) print(join_rating) if submit_queries: send_query_and_get_id(join_vocab) send_query_and_get_id(join_motivations) send_query_and_get_id(join_rating) # Join the toolkit items to the toolkit add_vocab = itemlist.mutation_add_itemlist_itemlist_element( itemlist_id, listitem_vocab_id) add_motivation = itemlist.mutation_add_itemlist_itemlist_element( itemlist_id, listitem_motivations_id) add_rating = itemlist.mutation_add_itemlist_itemlist_element( itemlist_id, listitem_rating_id) add_commenting = itemlist.mutation_add_itemlist_itemlist_element( itemlist_id, listitem_commenting_id) add_tagging = itemlist.mutation_add_itemlist_itemlist_element( itemlist_id, listitem_tagging_id) print("Toolkit - add ListItems to ItemList") if print_queries: print(add_vocab) print(add_motivation) print(add_rating) print(add_commenting) print(add_tagging) if submit_queries: send_query_and_get_id(add_vocab) send_query_and_get_id(add_motivation) send_query_and_get_id(add_rating) send_query_and_get_id(add_commenting) send_query_and_get_id(add_tagging)
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" # An annotation where the target is a specific field of an existing node. # For simplicity we don't have a body audio_id = audio_file_pierri_etude(print_queries, submit_queries) # The annotation target. We're annotating the URL that is at the `source` field of the above audio object target = annotation.create_annotation_ce_target( creator=user_vcard, field="source", # we want to annotate the URL that is at the 'source' field of the AudioObject node fragment="t=10,20" # only annotate 10 seconds of audio from 10sec - 20sec ) target_id = "ce-target-id" print("AnnotationCETarget") if print_queries: print(target) if submit_queries: target_id = send_query_and_get_id(target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") target_join = annotation.merge_annotation_target_target(target_id, audio_id) if print_queries: print(target_join) if submit_queries: send_query_and_get_id(target_join) # The annotation ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging ) ann_id = "annotation-id" print("Annotation") if print_queries: print(ann) if submit_queries: ann_id = send_query_and_get_id(ann, "CreateAnnotation") # Join the annotation with the AnnotationCETarget annotation_target_join = annotation.merge_annotation_targetnode(ann_id, target_id) print("Annotation - link to target") if print_queries: print(annotation_target_join) if submit_queries: send_query_and_get_id(annotation_target_join) # An annotation where the target is an actual node in the CE (not the item at a field) # The annotation target. We're annotating the URL that is at the `source` field of the above audio object ann_target = annotation.create_annotation_ce_target( creator=user_vcard # no field or fragment set ) ann_target_id = "ce-target-id" print("AnnotationCETarget - no field") if print_queries: print(ann_target) if submit_queries: ann_target_id = send_query_and_get_id(ann_target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") # Here, the target field of the AnnotationCETarget object is the previous annotation object ann_target_join = annotation.merge_annotation_target_target(ann_target_id, ann_id) if print_queries: print(ann_target_join) if submit_queries: send_query_and_get_id(ann_target_join) # A new annotation, this one is an annotation about the _other_ annotation ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging ) ann_id = "annotation-id" print("Annotation") if print_queries: print(ann) if submit_queries: ann_id = send_query_and_get_id(ann, "CreateAnnotation") # Join the annotation with the AnnotationCETarget annotation_target_join = annotation.merge_annotation_targetnode(ann_id, target_id) print("Annotation - link to target") if print_queries: print(annotation_target_join) if submit_queries: send_query_and_get_id(annotation_target_join) # Annotation target 3: external target # This style of annotation doesn't need an AnnotationCETarget object, because the target isn't in the CE ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging, target_url="https://example.com/audio.mp3" ) print("Annotation - external URL target") if print_queries: print(ann) if submit_queries: send_query_and_get_id(ann, "CreateAnnotation")
def main(print_queries: bool, submit_queries: bool): admin_vcard = "https://alastair.trompa-solid.upf.edu/profile/card#me" user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" audio_id = audio_file_liebestraum(print_queries, submit_queries) # A 'template' of the rating that we're using. This can be used to show a graphical widget, # and also as a common template that can be used to join together multiple annotations rating_definition = rating.create_rating_definition(creator=admin_vcard, worstrating=0, bestrating=10) rating_definition_id = "rating-definition-id" print("Rating (definition)") if print_queries: print(rating_definition) if submit_queries: rating_definition_id = send_query_and_get_id(rating_definition, "CreateRating") # The annotation target. We're annotating the URL that is at the `source` field of the above audio object target = annotation.create_annotation_ce_target( creator=user_vcard, field= "source", # we want to annotate the URL that is at the 'source' field of the AudioObject node # Optionally, set the 'fragment' parameter to annotate a time range in the file ) target_id = "ce-target-id" print("AnnotationCETarget") if print_queries: print(target) if submit_queries: target_id = send_query_and_get_id(target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") target_join = annotation.merge_annotation_target_target( target_id, audio_id) if print_queries: print(target_join) if submit_queries: send_query_and_get_id(target_join) # The annotation ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.assessing) ann_id = "annotation-id" print("Annotation") if print_queries: print(ann) if submit_queries: ann_id = send_query_and_get_id(ann, "CreateAnnotation") # Make a rating user_rating = rating.create_rating(creator=user_vcard, bestrating=10, worstrating=1, ratingvalue=8) print("Rating") rating_id = "rating-id" if print_queries: print(user_rating) if submit_queries: rating_id = send_query_and_get_id(user_rating, "CreateRating") # Say that the rating was derived from the original definition that we created rating_was_derived_from_definition = rating.rating_add_was_derived_from_rating( rating_id, rating_definition_id) print("Rating - join to definition template") if print_queries: print(rating_was_derived_from_definition) if submit_queries: send_query_and_get_id(rating_was_derived_from_definition) # Join the annotation with the AnnotationCETarget annotation_target_join = annotation.merge_annotation_targetnode( ann_id, target_id) # Join the annotation with the Body. In this case, the body is the Rating that we just made annotation_body_join = annotation.merge_annotation_bodynode( ann_id, rating_id) print("Annotation - link to target and body") if print_queries: print(annotation_target_join) print(annotation_body_join) if submit_queries: send_query_and_get_id(annotation_target_join) send_query_and_get_id(annotation_body_join)
def motivation_collection(print_queries: bool, submit_queries: bool): """A collection of annotation motivations that could be applied to a single item""" admin_vcard = "https://alastair.trompa-solid.upf.edu/profile/card#me" dts = definedterm.create_defined_term_set(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_MOTIVATION_COLLECTION], broader_schema=annotation.AnnotationSchemaMotivation.commenting, image="https://alastair.trompa-solid.upf.edu/annotation-images/conductor-baton.png", name="Performance instructions") dt_upbow = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_MOTIVATION_COLLECTION_ELEMENT, annotation.OA_ANNOTATION_MOTIVATION_TYPE], image="https://alastair.trompa-solid.upf.edu/annotation-images/upbow.png", termcode="Upbow") dt_downbow = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[ annotation.ADDITIONAL_TYPE_MOTIVATION_COLLECTION_ELEMENT, annotation.OA_ANNOTATION_MOTIVATION_TYPE], image="https://alastair.trompa-solid.upf.edu/annotation-images/downbow.png", termcode="Downbow") dt_arco = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_MOTIVATION_COLLECTION_ELEMENT, annotation.OA_ANNOTATION_MOTIVATION_TYPE], image="https://alastair.trompa-solid.upf.edu/annotation-images/arco.png", termcode="Arco") dt_slur = definedterm.create_defined_term(creator=admin_vcard, additionaltype=[annotation.ADDITIONAL_TYPE_MOTIVATION_COLLECTION_ELEMENT, annotation.OA_ANNOTATION_MOTIVATION_TYPE], image="https://alastair.trompa-solid.upf.edu/annotation-images/slur.png", termcode="Slur") print("DefinedTerm - Motivation Collection") dts_id = "dts-id" dt_upbow_id = "dt-upbow-id" dt_downbow_id = "dt-downbow-id" dt_arco_id = "dt-arco-id" dt_slur_id = "dt-slur-id" if print_queries: print(dts) print(dt_upbow) print(dt_downbow) print(dt_arco) print(dt_slur) if submit_queries: dts_id = send_query_and_get_id(dts, "CreateDefinedTermSet") dt_upbow_id = send_query_and_get_id(dt_upbow, "CreateDefinedTerm") dt_downbow_id = send_query_and_get_id(dt_downbow, "CreateDefinedTerm") dt_arco_id = send_query_and_get_id(dt_arco, "CreateDefinedTerm") dt_slur_id = send_query_and_get_id(dt_slur, "CreateDefinedTerm") dts_join_upbow = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_upbow_id) dts_join_downbow = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_downbow_id) dts_join_arco = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_arco_id) dts_join_slur = definedterm.defined_term_add_to_defined_term_set(defined_term_set=dts_id, defined_term=dt_slur_id) print("DefinedTerm - Join to DefinedTermSet") if print_queries: print(dts_join_upbow) print(dts_join_downbow) print(dts_join_arco) print(dts_join_slur) if submit_queries: send_query_and_get_id(dts_join_upbow) send_query_and_get_id(dts_join_downbow) send_query_and_get_id(dts_join_arco) send_query_and_get_id(dts_join_slur) return { "dts_id": dts_id, "dt_upbow_id": dt_upbow_id, "dt_downbow_id": dt_downbow_id, "dt_slur_id": dt_slur_id, "dt_arco_id": dt_arco_id, }
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" # An annotation requires a target, but we omit it from this demo. # An annotation whose body is an external URL ann_url = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.describing, body_url=["https://trompamusic.eu/something", "http://example.com/somethingelse"] ) ann_url_id = "annotation-id" print("Annotation - url body") if print_queries: print(ann_url) if submit_queries: ann_url_id = send_query_and_get_id(ann_url, "CreateAnnotation") # An annotation whose body is some text body = annotation.create_annotation_textual_body( creator=user_vcard, value="if the <i>format</i> field is set correctly, the value of the <b>textualbody</b> can even be html!", format_="text/html", language="en" ) body_id = "text-body-id" print("AnnotationTextualBody") if print_queries: print(body) if submit_queries: body_id = send_query_and_get_id(body, "CreateAnnotationTextualBody") ann_text = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.commenting ) ann_text_id = "annotation-id" print("Annotation - Textual body") if print_queries: print(ann_text) if submit_queries: ann_text_id = send_query_and_get_id(ann_text, "CreateAnnotation") # Join the annotation with the and the Body annotation_text_body_join = annotation.merge_annotation_bodytext(ann_text_id, body_id) print("Annotation - link to body") if print_queries: print(annotation_text_body_join) if submit_queries: send_query_and_get_id(annotation_text_body_join) # An annotation whose body is another node in the CE. In this case, the previous annotation ann_node = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.linking ) ann_node_id = "annotation-id" print("Annotation - node body") if print_queries: print(ann_node) if submit_queries: ann_node_id = send_query_and_get_id(ann_node, "CreateAnnotation") # Join the annotation with the and the Body annotation_node_body_join = annotation.merge_annotation_bodynode(ann_node_id, ann_text_id) print("Annotation - link to body") if print_queries: print(annotation_node_body_join) if submit_queries: send_query_and_get_id(annotation_node_body_join)
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" audio1_id = audio_file_liebestraum(print_queries, submit_queries) audio2_id = audio_file_pierri_etude(print_queries, submit_queries) session = annotation.create_annotation_session(creator=user_vcard, name="Some session") print("Annotation session") session_id = "session-id" if print_queries: print(session) if submit_queries: session_id = send_query_and_get_id(session, "CreateItemList") # We have three annotations in this session. One of audio1_id, and two of audio2_id at different points in time # For simplicity we don't set any body target1 = annotation.create_annotation_ce_target(creator=user_vcard, field="contenturl", fragment="#t=8") annotation1 = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.highlighting) target2 = annotation.create_annotation_ce_target(creator=user_vcard, field="contenturl") annotation2 = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.highlighting) target3 = annotation.create_annotation_ce_target(creator=user_vcard, field="contenturl", fragment="#t=15") annotation3 = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.highlighting) print("Annotation - Create CE Target and Annotation objects") target1_id = "target1-id" target2_id = "target2-id" target3_id = "target3-id" annotation1_id = "annotation1-id" annotation2_id = "annotation2-id" annotation3_id = "annotation3-id" if print_queries: print(target1) print(target2) print(target3) print(annotation1) print(annotation2) print(annotation3) if submit_queries: target1_id = send_query_and_get_id(target1, "CreateAnnotationCETarget") target2_id = send_query_and_get_id(target2, "CreateAnnotationCETarget") target3_id = send_query_and_get_id(target3, "CreateAnnotationCETarget") annotation1_id = send_query_and_get_id(annotation1, "CreateAnnotation") annotation2_id = send_query_and_get_id(annotation2, "CreateAnnotation") annotation3_id = send_query_and_get_id(annotation3, "CreateAnnotation") # Linking audio to AnnotationCETarget and AnnotationCETarget to Annotation target1_audio = annotation.merge_annotation_target_target( target1_id, audio1_id) target2_audio = annotation.merge_annotation_target_target( target2_id, audio2_id) target3_audio = annotation.merge_annotation_target_target( target3_id, audio2_id) annotation1_target = annotation.merge_annotation_targetnode( annotation1_id, target1_id) annotation2_target = annotation.merge_annotation_targetnode( annotation2_id, target2_id) annotation3_target = annotation.merge_annotation_targetnode( annotation3_id, target3_id) print("Annotation - join audio to target and target to annotation") if print_queries: print(target1_audio) print(target2_audio) print(target3_audio) print(annotation1_target) print(annotation2_target) print(annotation3_target) if submit_queries: send_query_and_get_id(target1_audio) send_query_and_get_id(target2_audio) send_query_and_get_id(target3_audio) send_query_and_get_id(annotation1_target) send_query_and_get_id(annotation2_target) send_query_and_get_id(annotation3_target) # Make a container ListItem to add to the Session annotation1_item = annotation.create_annotation_session_element( creator=user_vcard) annotation2_item = annotation.create_annotation_session_element( creator=user_vcard) annotation3_item = annotation.create_annotation_session_element( creator=user_vcard) print("Annotation - create ListItem") annotation1_item_id = "annotation1-listitem-id" annotation2_item_id = "annotation2-listitem-id" annotation3_item_id = "annotation3-listitem-id" if print_queries: print(annotation1_item) print(annotation2_item) print(annotation3_item) if submit_queries: annotation1_item_id = send_query_and_get_id(annotation1_item, "CreateListItem") annotation2_item_id = send_query_and_get_id(annotation2_item, "CreateListItem") annotation3_item_id = send_query_and_get_id(annotation3_item, "CreateListItem") # Linking Annotations to ListItems, and add ListItems to the session item1_annotation = itemlist.mutation_add_listitem_item( annotation1_item_id, annotation1_id) item2_annotation = itemlist.mutation_add_listitem_item( annotation2_item_id, annotation2_id) item3_annotation = itemlist.mutation_add_listitem_item( annotation3_item_id, annotation3_id) session_item1 = itemlist.mutation_add_itemlist_itemlist_element( session_id, annotation1_item_id) session_item2 = itemlist.mutation_add_itemlist_itemlist_element( session_id, annotation2_item_id) session_item3 = itemlist.mutation_add_itemlist_itemlist_element( session_id, annotation3_item_id) print( "Annotation - join annotation to ListItem and and add ListItem to session" ) if print_queries: print(item1_annotation) print(item2_annotation) print(item3_annotation) print(session_item1) print(session_item2) print(session_item3) if submit_queries: send_query_and_get_id(item1_annotation) send_query_and_get_id(item2_annotation) send_query_and_get_id(item3_annotation) send_query_and_get_id(session_item1) send_query_and_get_id(session_item2) send_query_and_get_id(session_item3)
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" vocabulary_ids = fixed_vocabulary(print_queries, submit_queries) audio_id = audio_file_liebestraum(print_queries, submit_queries) # The annotation target. We're annotating the URL that is at the `source` field of the above audio object target = annotation.create_annotation_ce_target( creator=user_vcard, field="source", ) target_id = "ce-target-id" print("AnnotationCETarget") if print_queries: print(target) if submit_queries: target_id = send_query_and_get_id(target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") target_join = annotation.merge_annotation_target_target( target_id, audio_id) if print_queries: print(target_join) if submit_queries: send_query_and_get_id(target_join) # Annotation 1 - "Happy" tag ann1 = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging) ann1_id = "annotation1-id" print("Annotation1") if print_queries: print(ann1) if submit_queries: ann1_id = send_query_and_get_id(ann1, "CreateAnnotation") # Join the annotation with the AnnotationCETarget annotation_target_join = annotation.merge_annotation_targetnode( ann1_id, target_id) # Join the annotation with the Body. In this case, the body is the "Happy" DefinedTerm # from the DefinedTermSet that we provided body_id = vocabulary_ids["dt_happy_id"] annotation_body_join = annotation.merge_annotation_bodynode( ann1_id, body_id) print("Annotation1 - link to target and body") if print_queries: print(annotation_target_join) print(annotation_body_join) if submit_queries: send_query_and_get_id(annotation_target_join) send_query_and_get_id(annotation_body_join) # Annotation 2 - freeform tag ann2 = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging) ann2_id = "annotation2-id" print("Annotation2") if print_queries: print(ann2) if submit_queries: ann2_id = send_query_and_get_id(ann2, "CreateAnnotation") # The annotation text body body = annotation.create_annotation_textual_body( creator=user_vcard, value="favourite-song", # the tag format_="text/plain", language="en") body_id = "text-body-id" print("AnnotationTextualBody") if print_queries: print(body) if submit_queries: body_id = send_query_and_get_id(body, "CreateAnnotationTextualBody") # Join the annotation with the AnnotationCETarget and body. Note that we can use the same # target as we know that all annotations are of the same thing annotation_target_join = annotation.merge_annotation_targetnode( ann2_id, target_id) annotation_body_join = annotation.merge_annotation_bodynode( ann2_id, body_id) print("Annotation1 - link to target and body") if print_queries: print(annotation_target_join) print(annotation_body_join) if submit_queries: send_query_and_get_id(annotation_target_join) send_query_and_get_id(annotation_body_join) # Linking Annotation, this joins together the two previous annotations into a third one # Make a custom motivation which describes what this linking represents custom_motivation = annotation.create_annotation_motivation( creator=user_vcard, title="Music scholars feedback grouping", description= "This motivation groups together 4 different annotations into a single meta-annotation" "which represents the full description of a recording by a user", broader_schema=annotation.AnnotationSchemaMotivation.linking) custom_motivation_id = "custom-motivation-id" print("Linking Annotation - create Motivation") if print_queries: print(custom_motivation) if submit_queries: custom_motivation_id = send_query_and_get_id( custom_motivation, "CreateAnnotationCEMotivation") ann_link = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.linking) ann_link_id = "annotation2-id" print("Linking Annotation") if print_queries: print(ann2) if submit_queries: ann_link_id = send_query_and_get_id(ann_link, "CreateAnnotation") # Add the custom motivation as the motivation of the linking annotation link_annotation_target_join = annotation.merge_annotation_targetnode( ann_link_id, target_id) link_annotation_motivation_join = annotation.merge_annotation_cemotivation( ann_link_id, custom_motivation_id) # Add the two prior annotations as the body of the linking annotation link_annotation_body1_join = annotation.merge_annotation_bodynode( ann_link_id, ann1_id) link_annotation_body2_join = annotation.merge_annotation_bodynode( ann_link_id, ann2_id) print("Linking Annotation - join with target, motivation, and bodies") if print_queries: print(link_annotation_target_join) print(link_annotation_motivation_join) print(link_annotation_body1_join) print(link_annotation_body2_join) if submit_queries: send_query_and_get_id(link_annotation_target_join) send_query_and_get_id(link_annotation_motivation_join) send_query_and_get_id(link_annotation_body1_join) send_query_and_get_id(link_annotation_body2_join)
def main(print_queries: bool, submit_queries: bool): user_vcard = "https://testuser.trompa-solid.upf.edu/profile/card#me" audio_id = audio_file_liebestraum(print_queries, submit_queries) # The annotation text body body = annotation.create_annotation_textual_body( creator=user_vcard, value="favourite-song", # the tag format_="text/plain", language="en") body_id = "text-body-id" print("AnnotationTextualBody") if print_queries: print(body) if submit_queries: body_id = send_query_and_get_id(body, "CreateAnnotationTextualBody") # The annotation target. We're annotating the URL that is at the `source` field of the above audio object target = annotation.create_annotation_ce_target( creator=user_vcard, field= "source", # we want to annotate the URL that is at the 'source' field of the AudioObject node # Optionally, set the 'fragment' parameter to annotate a time range in the file ) target_id = "ce-target-id" print("AnnotationCETarget") if print_queries: print(target) if submit_queries: target_id = send_query_and_get_id(target, "CreateAnnotationCETarget") print("Join AnnotationCETarget-Target") target_join = annotation.merge_annotation_target_target( target_id, audio_id) if print_queries: print(target_join) if submit_queries: send_query_and_get_id(target_join) # The annotation ann = annotation.create_annotation( creator=user_vcard, motivation=annotation.AnnotationSchemaMotivation.tagging) ann_id = "annotation-id" print("Annotation") if print_queries: print(ann) if submit_queries: ann_id = send_query_and_get_id(ann, "CreateAnnotation") # Join the annotation with the AnnotationCETarget, and the Body annotation_target_join = annotation.merge_annotation_targetnode( ann_id, target_id) annotation_body_join = annotation.merge_annotation_bodytext( ann_id, body_id) print("Annotation - link to target and body") if print_queries: print(annotation_target_join) print(annotation_body_join) if submit_queries: send_query_and_get_id(annotation_target_join) send_query_and_get_id(annotation_body_join)