Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rml_orgunit_to_metajson(rml_orgunit, source, rec_id_prefix):
""" orgUnit -> orgunit """
orgunit = Orgunit()
# source
if source:
orgunit["rec_source"] = source
# acronym -> acronym
orgunit.update(get_rml_element_text_and_set_key(rml_orgunit, "acronym", "acronym"))
# address -> addresses
orgunit.update(get_rml_addresses(rml_orgunit))
# affiliation -> affiliations
orgunit.update(get_rml_affiliations(rml_orgunit))
# award -> awards
orgunit.update(get_rml_textlangs_and_set_key(rml_orgunit, "award", "awards"))
# description -> descriptions[i]
teaching.update(get_rml_textlangs_and_set_key(rml_teaching, "description", "descriptions"))
# level -> level
teaching.update(get_rml_element_text_and_set_key(rml_teaching, "level", "level"))
# title -> title
teaching.update(get_rml_element_text_and_set_key(rml_teaching, "title", "title"))
# creators
# name -> creators[0].agent.name
name = get_rml_element_text(rml_teaching, "name")
creator = creator_service.formatted_name_to_creator(name, constants.REC_CLASS_ORGUNIT, "dgg")
if creator is None:
creator = Creator()
creator["agent"] = Orgunit()
creator["roles"] = "dgg"
# identifiers -> creators[0].agent.rec_id or creators[0].agent.identifiers
creator["agent"].update(get_rml_identifiers(rml_teaching))
if "name" in creator["agent"] or "rec_id" in creator["agent"] or "identifiers" in creator["agent"]:
teaching["creators"] = [creator]
if teaching is not None:
teachings.append(teaching)
if teachings:
result["teachings"] = teachings
return result
if rec_class == constants.REC_CLASS_PERSON:
person = Person()
person.set_key_if_not_none("name_family", name_family)
person.set_key_if_not_none("name_given", name_given)
person.set_key_if_not_none("name_middle", name_middle)
person.set_key_if_not_none("name_terms_of_address", name_terms_of_address)
person.set_key_if_not_none("name_prefix", name_prefix)
person.set_key_if_not_none("date_birth", date_birth)
person.set_key_if_not_none("date_death", date_death)
creator["agent"] = person
if 'affiliation_name' in vars() and affiliation_name:
#todo manage as an object
affiliation = Orgunit()
affiliation["name"] = affiliation_name
creator["affiliation"] = affiliation
elif rec_class == constants.REC_CLASS_FAMILY:
family = Family()
family.set_key_if_not_none("name_family", name_family)
creator["agent"] = family
#logging.debug(jsonbson.dumps_json(creator, True))
return creator
def get_rml_call(rml):
""" call -> call """
result = {}
rml_call = rml.find(xmletree.prefixtag("rml", "call"))
if rml_call is not None:
call = Call()
# funding -> funding
rml_funding = rml_call.find(xmletree.prefixtag("rml", "funding"))
if rml_funding is not None:
# name -> agent.name
name = get_rml_element_text(rml_funding, "name")
funding = creator_service.formatted_name_to_creator(name, constants.REC_CLASS_ORGUNIT, None)
if funding is None:
funding = Creator()
funding["agent"] = Orgunit()
# identifier -> agent.rec_id & agent.identifiers
funding["agent"].update(get_rml_identifiers(rml_funding))
# programme -> programme
funding.update(get_rml_element_text_and_set_key(rml_funding, "programme", "programme"))
# scheme -> scheme
funding.update(get_rml_element_text_and_set_key(rml_funding, "scheme", "scheme"))
# contribution -> contribution
funding.update(get_rml_money_and_set_key(rml_funding, "contribution", "contribution"))
if funding:
call["funding"] = funding
elif mods_name_part.get("type") == "date":
date = mods_name_part.text.replace("(", "").replace(")", "").strip()
minus_index = date.find("-")
if minus_index == -1:
person["date_birth"] = date
else:
person["date_birth"] = date[:minus_index]
person["date_death"] = date[minus_index+1:]
elif mods_name_part.get("termsOfAddress") == "date":
person["name_terms_of_address"] = mods_name_part.text
creator["agent"] = person
elif mods_name_type == "corporate":
# logging.debug("corporate")
orgunit = Orgunit()
creator["agent"] = orgunit
if mods_name_parts:
orgunit["name"] = mods_name_parts[0].text.strip()
elif mods_name_type == "conference":
# logging.debug("conference")
event = Event()
creator["agent"] = event
if mods_name_parts:
for mods_name_part in mods_name_parts:
if mods_name_part.get("type") is None:
event["title"] = mods_name_part.text.strip()
elif mods_name_part.get("type") == "termsOfAddress":
address = mods_name_part.text.strip()
rec_class = constants.REC_CLASS_ORGUNIT
break
if rec_class is None:
rec_class = constants.REC_CLASS_PERSON
creator = Creator()
if role:
creator["roles"] = [role]
if rec_class == constants.REC_CLASS_EVENT:
event = Event()
event["title"] = formatted_name
creator["agent"] = event
elif rec_class == constants.REC_CLASS_ORGUNIT:
orgunit = Orgunit()
orgunit["name"] = formatted_name
creator["agent"] = orgunit
elif rec_class == constants.REC_CLASS_PERSON or rec_class == constants.REC_CLASS_FAMILY:
# class is "Person" or "Family"
name_given = ""
name_middle = ""
name_family = ""
name_prefix = ""
name_terms_of_address = ""
date_birth = ""
date_death = ""
parenthesis_index = formatted_name.rfind("(")
if parenthesis_index != -1:
if field.indicator1 == "1":
# Event
event = Event()
if field.get_subfields('a'):
event["title"] = "".join(field.get_subfields('a'))
if field.get_subfields('d'):
event["number"] = "".join(field.get_subfields('d'))
if field.get_subfields('e'):
event["place"] = "".join(field.get_subfields('e'))
if field.get_subfields('f'):
event["date_begin"] = "".join(field.get_subfields('f'))
if event:
creator["agent"] = event
else:
# Orgunit
orgunit = Orgunit()
name = []
if field.get_subfields('3'):
orgunit["identifiers"] = field.get_subfields('3')[0]
if field.get_subfields('a'):
name.extend(field.get_subfields('a'))
if field.get_subfields('b'):
# todo division
name.append(". ")
name.extend(field.get_subfields('b'))
if name:
orgunit["name"] = "".join(name)
if field.get_subfields('c'):
addresses = []
for locality in field.get_subfields('c'):
address = {"locality_city_town" : locality.replace("(","").replace(")","").strip()}
addresses.append(address)
# description -> descriptions
degree.update(get_rml_textlangs_and_set_key(rml_degree, "description", "descriptions"))
# level -> level
degree.update(get_rml_element_text_and_set_key(rml_degree, "level", "level"))
# title -> title
degree.update(get_rml_element_text_and_set_key(rml_degree, "title", "title"))
# creators
# name -> creators[0].agent.name
name = get_rml_element_text(rml_degree, "name")
creator = creator_service.formatted_name_to_creator(name, constants.REC_CLASS_ORGUNIT, "dgg")
if creator is None:
creator = Creator()
creator["agent"] = Orgunit()
creator["roles"] = ["dgg"]
# identifiers -> creators[0].agent.rec_id or creators[0].agent.identifiers
creator["agent"].update(get_rml_identifiers(rml_degree))
if "name" in creator["agent"] or "rec_id" in creator["agent"] or "identifiers" in creator["agent"]:
degree["creators"] = [creator]
if degree is not None:
degrees.append(degree)
if degrees:
result["degrees"] = degrees
return result