def link_musiccomposition_and_parts(musiccomposition_id, part_ids): for part_id in part_ids: query = mutation_musiccomposition.mutation_merge_music_composition_included_composition( musiccomposition_id, part_id) connection.submit_request(query) query = mutation_musiccomposition.mutation_merge_music_composition_has_part( musiccomposition_id, part_id) connection.submit_request(query)
def create_mediaobject(mediaobject): mediaobject["creator"] = CREATOR_URL mutation_create = mutation_mediaobject.mutation_create_media_object( **mediaobject) resp = connection.submit_request(mutation_create) # TODO: If this query fails? return resp['data']['CreateMediaObject']['identifier']
def create_musiccomposition(musiccomposition): musiccomposition["creator"] = CREATOR_URL mutation_create = mutation_musiccomposition.mutation_create_music_composition( **musiccomposition) resp = connection.submit_request(mutation_create) # TODO: If this query fails? return resp['data']['CreateMusicComposition']['identifier']
def get_existing_mediaobject_by_source(source) -> str: """Returns an identifier of the thing with the given source, else None""" query_by_source = query_mediaobject.query_mediaobject(source=source) resp = connection.submit_request(query_by_source) mediaobject = resp.get('data', {}).get('MediaObject', []) if not mediaobject: return None else: return mediaobject[0]['identifier']
def get_existing_person_by_source(source) -> str: """Returns an identifier of the thing with the given source, else None""" query_by_source = query_person.query_person(source=source) resp = connection.submit_request(query_by_source) person = resp.get('data', {}).get('Person', []) if not person: return None else: return person[0]['identifier']
def get_existing_musiccomposition_by_source(source) -> str: """Returns an identifier of the thing with the given source, else None""" query_by_source = query_musiccomposition.query_musiccomposition( source=source) resp = connection.submit_request(query_by_source) mc = resp.get('data', {}).get('MusicComposition', []) if not mc: return None else: return mc[0]['identifier']
def create_person(person): """Create a person object Arguments: person: a dictionary where keys are the parameters to the `mutation_create_person` function If `person` includes the keys 'birthplace' or 'deathplace', these items are extracted out, used to create a Place object, and then linked to the person """ person["creator"] = CREATOR_URL birthplace = None if 'birthplace' in person: birthplace = person['birthplace'] del person['birthplace'] deathplace = None if 'deathplace' in person: deathplace = person['deathplace'] del person['deathplace'] mutation_create = mutation_person.mutation_create_person(**person) resp = connection.submit_request(mutation_create) # TODO: If this query fails? person_id = resp['data']['CreatePerson']['identifier'] if birthplace: birthplace["creator"] = CREATOR_URL mutation_create = mutation_place.mutation_create_place(**birthplace) resp = connection.submit_request(mutation_create) birthplace_id = resp['data']['CreatePlace']['identifier'] mutation_merge = mutation_place.mutation_merge_person_birthplace( person_id, birthplace_id) connection.submit_request(mutation_merge) if deathplace: deathplace["creator"] = CREATOR_URL mutation_create = mutation_place.mutation_create_place(**deathplace) resp = connection.submit_request(mutation_create) deathplace_id = resp['data']['CreatePlace']['identifier'] mutation_merge = mutation_place.mutation_merge_person_deathplace( person_id, deathplace_id) connection.submit_request(mutation_merge) return person_id
def link_mediaobject_was_derived_from(source_id, derived_id): query = mutation_mediaobject.mutation_merge_media_object_wasderivedfrom( derived_id, source_id) connection.submit_request(query)
def link_musiccomposition_and_mediaobject(composition_id, mediaobject_id): query = mutation_mediaobject.mutation_merge_mediaobject_example_of_work( mediaobject_id, composition_id) connection.submit_request(query)
def link_person_ids(person_ids): for from_id, to_id in itertools.permutations(person_ids, 2): query = mutation_person.mutation_person_add_exact_match_person( from_id, to_id) connection.submit_request(query)
def link_musiccomposition_exactmatch(musiccomposition_ids): for from_id, to_id in itertools.permutations(musiccomposition_ids, 2): query = mutation_musiccomposition.mutation_merge_music_composition_exact_match( from_id, to_id) connection.submit_request(query)
def link_musiccomposition_and_composers(musiccomposition_id, composer_ids): for composer_id in composer_ids: query = mutation_musiccomposition.mutation_merge_music_composition_composer( musiccomposition_id, composer_id) connection.submit_request(query)
def create_place(place): place["creator"] = CREATOR_URL mutation_create = mutation_place.mutation_create_place(**place) resp = connection.submit_request(mutation_create) # TODO: If this query fails? return resp['data']['CreatePlace']['identifier']