def crosswalk_funding(orcid_profile, person_uri, graph): if "funding-list" in orcid_profile["orcid-profile"]["orcid-activities"] \ and orcid_profile["orcid-profile"]["orcid-activities"]["funding-list"] \ and "funding" in orcid_profile["orcid-profile"]["orcid-activities"]["funding-list"]: #Funding fundings = orcid_profile["orcid-profile"]["orcid-activities"]["funding-list"]["funding"] for funding in fundings: if funding["funding-type"] == "GRANT": title = funding["funding-title"]["title"]["value"] grant_uri = ns.D[to_hash_identifier(PREFIX_GRANT, (title,))] #Type graph.add((grant_uri, RDF.type, VIVO.Grant)) #Person graph.add((grant_uri, VIVO.relates, person_uri)) #Title graph.add((grant_uri, RDFS.label, Literal(title))) #Role role_uri = grant_uri + "-role" graph.add((role_uri, RDF.type, VIVO.PrincipalInvestigatorRole)) #Inheres in graph.add((role_uri, OBO.RO_0000052, person_uri)) graph.add((role_uri, VIVO.relatedBy, grant_uri)) #Date interval interval_uri = grant_uri + "-interval" interval_start_uri = interval_uri + "-start" interval_end_uri = interval_uri + "-end" start_year = funding["start-date"]["year"]["value"] \ if "start-date" in funding and "year" in funding["start-date"] else None start_month = funding["start-date"]["month"]["value"] \ if "start-date" in funding and "month" in funding["start-date"] else None start_day = funding["start-date"]["day"]["value"] \ if "start-date" in funding and "day" in funding["start-date"] else None end_year = funding["end-date"]["year"]["value"] \ if "end-date" in funding and "year" in funding["start-date"] else None end_month = funding["end-date"]["month"]["value"] \ if "end-date" in funding and "month" in funding["start-date"] else None end_day = funding["end-date"]["day"]["value"] \ if "end-date" in funding and "day" in funding["start-date"] else None add_date_interval(interval_uri, grant_uri, graph, interval_start_uri if add_date(interval_start_uri, start_year, graph, start_month, start_day) else None, interval_end_uri if add_date(interval_end_uri, end_year, graph, end_month, end_day) else None) #Award amount if "amount" in funding: award_amount = "${:,}".format(int(funding["amount"]["value"])) graph.add((grant_uri, VIVO.totalAwardAmount, Literal(award_amount))) #Awarded by if "organization" in funding: organization_name = funding["organization"]["name"] organization_uri = ns.D[to_hash_identifier(PREFIX_ORGANIZATION, (organization_name,))] graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) graph.add((grant_uri, VIVO.assignedBy, organization_uri)) #Identifiers if "funding-external-identifiers" in funding: for external_identifier in funding["funding-external-identifiers"]["funding-external-identifier"]: if "funding-external-identifier-value" in external_identifier: graph.add((grant_uri, VIVO.sponsorAwardId, Literal(external_identifier["funding-external-identifier-value"]))) if "funding-external-identifier-url" in external_identifier: identifier_url = external_identifier["funding-external-identifier-url"]["value"] vcard_uri = ns.D[to_hash_identifier("vcard", (identifier_url,))] graph.add((vcard_uri, RDF.type, VCARD.Kind)) #Has contact info graph.add((grant_uri, OBO.ARG_2000028, vcard_uri)) #Url vcard vcard_url_uri = vcard_uri + "-url" graph.add((vcard_url_uri, RDF.type, VCARD.URL)) graph.add((vcard_uri, VCARD.hasURL, vcard_url_uri)) graph.add((vcard_url_uri, VCARD.url, Literal(identifier_url, datatype=XSD.anyURI)))
def crosswalk(self, orcid_profile, person_uri, graph): if "fundings" in orcid_profile["activities-summary"]: # Funding for funding_group in orcid_profile["activities-summary"]["fundings"]["group"]: for funding in funding_group["funding-summary"]: if funding["type"] == "GRANT": title = funding["title"]["title"]["value"] grant_uri = self.identifier_strategy.to_uri(VIVO.Grant, {"title": title}) # Type graph.add((grant_uri, RDF.type, VIVO.Grant)) # Person graph.add((grant_uri, VIVO.relates, person_uri)) # Title graph.add((grant_uri, RDFS.label, Literal(title))) # Role role_uri = self.identifier_strategy.to_uri(VIVO.PrincipalInvestigatorRole, {"grant_uri": grant_uri}) graph.add((role_uri, RDF.type, VIVO.PrincipalInvestigatorRole)) # Inheres in graph.add((role_uri, OBO.RO_0000052, person_uri)) graph.add((role_uri, VIVO.relatedBy, grant_uri)) # Date interval (start_year, start_month, start_day) = FundingCrosswalk._get_date_parts("start-date", funding) (end_year, end_month, end_day) = FundingCrosswalk._get_date_parts("end-date", funding) add_date_interval(grant_uri, graph, self.identifier_strategy, add_date(start_year, graph, self.identifier_strategy, start_month, start_day), add_date(end_year, graph, self.identifier_strategy, end_month, end_day)) # Award amount funding_amount = funding.get("amount") if funding_amount is not None: value = funding_amount.get("value") if value is not None: award_amount = "${:,}".format(int(value)) graph.add((grant_uri, VIVO.totalAwardAmount, Literal(award_amount))) # Awarded by if "organization" in funding: organization_name = funding["organization"]["name"] organization_uri = self.identifier_strategy.to_uri(FOAF.Organization, {"name": organization_name}) graph.add((grant_uri, VIVO.assignedBy, organization_uri)) if self.create_strategy.should_create(FOAF.Organization, organization_uri): graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) # Identifiers if "external-ids" in funding and funding.get("external-ids"): for external_identifier in funding["external-ids"]["external-id"]: if "funding-external-identifier-value" in external_identifier: graph.add((grant_uri, VIVO.sponsorAwardId, Literal(external_identifier["external-id-value"]))) identifier_url = (external_identifier.get("external-id-url", {}) or {}).get("value") if identifier_url: vcard_uri = self.identifier_strategy.to_uri(VCARD.Kind, {"url": identifier_url}) graph.add((vcard_uri, RDF.type, VCARD.Kind)) # Has contact info graph.add((grant_uri, OBO.ARG_2000028, vcard_uri)) # Url vcard vcard_url_uri = self.identifier_strategy.to_uri(VCARD.URL, {"vcard_uri": vcard_uri}) graph.add((vcard_url_uri, RDF.type, VCARD.URL)) graph.add((vcard_uri, VCARD.hasURL, vcard_url_uri)) graph.add((vcard_url_uri, VCARD.url, Literal(identifier_url, datatype=XSD.anyURI)))
def crosswalk(self, orcid_profile, person_uri, graph): # Education if "educations" in orcid_profile["activities-summary"]: for education in orcid_profile["activities-summary"]["educations"][ "education-summary"]: # Gather some values degree_name = education.get("role-title") organization_name = education["organization"]["name"] start_date_year = (education["start-date"] or {}).get("year", {}).get("value") end_date_year = (education["end-date"] or {}).get("year", {}).get("value") # Organization organization_uri = self.identifier_strategy.to_uri( FOAF.Organization, {"name": organization_name}) if self.create_strategy.should_create(FOAF.Organization, organization_uri): graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) if "address" in education["organization"]: city = education["organization"]["address"]["city"] state = education["organization"]["address"]["region"] address_uri = ns.D[to_hash_identifier( "geo", (city, state))] graph.add((address_uri, RDF.type, VIVO.GeographicLocation)) graph.add((organization_uri, OBO.RO_0001025, address_uri)) graph.add((address_uri, RDFS.label, Literal("%s, %s" % (city, state)))) # Output of educational process educational_process_uri = self.identifier_strategy.to_uri( VIVO.EducationalProcess, { "organization_name": organization_name, "degree_name": degree_name, "start_year": start_date_year, "end_year": end_date_year }) graph.add((educational_process_uri, RDF.type, VIVO.EducationalProcess)) # Has participants graph.add((educational_process_uri, OBO.RO_0000057, organization_uri)) graph.add( (educational_process_uri, OBO.RO_0000057, person_uri)) # Department if education.get("department-name"): graph.add( (educational_process_uri, VIVO.departmentOrSchool, Literal(education["department-name"]))) # Interval add_date_interval( educational_process_uri, graph, self.identifier_strategy, add_date(start_date_year, graph, self.identifier_strategy), add_date(end_date_year, graph, self.identifier_strategy)) if "role-title" in education: degree_name = education["role-title"] # Awarded degree awarded_degree_uri = self.identifier_strategy.to_uri( VIVO.AwardedDegree, {"educational_process_uri": educational_process_uri}) graph.add( (awarded_degree_uri, RDF.type, VIVO.AwardedDegree)) graph.add( (awarded_degree_uri, RDFS.label, Literal(degree_name))) # Assigned by organization graph.add((awarded_degree_uri, VIVO.assignedBy, organization_uri)) # Related to educational process graph.add((awarded_degree_uri, OBO.RO_0002353, educational_process_uri)) # Relates to degree degree_uri = self.identifier_strategy.to_uri( VIVO.AcademicDegree, {"name": degree_name}) graph.add((awarded_degree_uri, VIVO.relates, degree_uri)) if self.create_strategy.should_create( VIVO.AcademicDegree, degree_uri): graph.add((degree_uri, RDF.type, VIVO.AcademicDegree)) graph.add( (degree_uri, RDFS.label, Literal(degree_name))) # Relates to person graph.add((awarded_degree_uri, VIVO.relates, person_uri))
def crosswalk(self, orcid_profile, person_uri, graph): # Education if "educations" in orcid_profile["activities-summary"]: for education in orcid_profile["activities-summary"]["educations"]["education-summary"]: # Gather some values degree_name = education.get("role-title") organization_name = education["organization"]["name"] start_date_year = (education["start-date"] or {}).get("year", {}).get("value") end_date_year = (education["end-date"] or {}).get("year", {}).get("value") # Organization organization_uri = self.identifier_strategy.to_uri(FOAF.Organization, {"name": organization_name}) if self.create_strategy.should_create(FOAF.Organization, organization_uri): graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) if "address" in education["organization"]: city = education["organization"]["address"]["city"] state = education["organization"]["address"]["region"] address_uri = ns.D[to_hash_identifier("geo", (city, state))] graph.add((address_uri, RDF.type, VIVO.GeographicLocation)) graph.add((organization_uri, OBO.RO_0001025, address_uri)) graph.add((address_uri, RDFS.label, Literal("%s, %s" % (city, state)))) # Output of educational process educational_process_uri = self.identifier_strategy.to_uri(VIVO.EducationalProcess, {"organization_name": organization_name, "degree_name": degree_name, "start_year": start_date_year, "end_year": end_date_year}) graph.add((educational_process_uri, RDF.type, VIVO.EducationalProcess)) # Has participants graph.add((educational_process_uri, OBO.RO_0000057, organization_uri)) graph.add((educational_process_uri, OBO.RO_0000057, person_uri)) # Department if education.get("department-name"): graph.add((educational_process_uri, VIVO.departmentOrSchool, Literal(education["department-name"]))) # Interval add_date_interval(educational_process_uri, graph, self.identifier_strategy, add_date(start_date_year, graph, self.identifier_strategy), add_date(end_date_year, graph, self.identifier_strategy)) if "role-title" in education: degree_name = education["role-title"] # Awarded degree awarded_degree_uri = self.identifier_strategy.to_uri(VIVO.AwardedDegree, {"educational_process_uri": educational_process_uri}) graph.add((awarded_degree_uri, RDF.type, VIVO.AwardedDegree)) graph.add((awarded_degree_uri, RDFS.label, Literal(degree_name))) # Assigned by organization graph.add((awarded_degree_uri, VIVO.assignedBy, organization_uri)) # Related to educational process graph.add((awarded_degree_uri, OBO.RO_0002353, educational_process_uri)) # Relates to degree degree_uri = self.identifier_strategy.to_uri(VIVO.AcademicDegree, {"name": degree_name}) graph.add((awarded_degree_uri, VIVO.relates, degree_uri)) if self.create_strategy.should_create(VIVO.AcademicDegree, degree_uri): graph.add((degree_uri, RDF.type, VIVO.AcademicDegree)) graph.add((degree_uri, RDFS.label, Literal(degree_name))) # Relates to person graph.add((awarded_degree_uri, VIVO.relates, person_uri))
def crosswalk(self, orcid_profile, person_uri, graph): if "fundings" in orcid_profile["activities-summary"]: # Funding for funding_group in orcid_profile["activities-summary"][ "fundings"]["group"]: for funding in funding_group["funding-summary"]: if funding["type"] == "GRANT": title = funding["title"]["title"]["value"] grant_uri = self.identifier_strategy.to_uri( VIVO.Grant, {"title": title}) # Type graph.add((grant_uri, RDF.type, VIVO.Grant)) # Person graph.add((grant_uri, VIVO.relates, person_uri)) # Title graph.add((grant_uri, RDFS.label, Literal(title))) # Role role_uri = self.identifier_strategy.to_uri( VIVO.PrincipalInvestigatorRole, {"grant_uri": grant_uri}) graph.add((role_uri, RDF.type, VIVO.PrincipalInvestigatorRole)) # Inheres in graph.add((role_uri, OBO.RO_0000052, person_uri)) graph.add((role_uri, VIVO.relatedBy, grant_uri)) # Date interval (start_year, start_month, start_day) = FundingCrosswalk._get_date_parts( "start-date", funding) (end_year, end_month, end_day) = FundingCrosswalk._get_date_parts( "end-date", funding) add_date_interval( grant_uri, graph, self.identifier_strategy, add_date(start_year, graph, self.identifier_strategy, start_month, start_day), add_date(end_year, graph, self.identifier_strategy, end_month, end_day)) # Award amount funding_amount = funding.get("amount") if funding_amount is not None: value = funding_amount.get("value") if value is not None: award_amount = "${:,}".format(int(value)) graph.add((grant_uri, VIVO.totalAwardAmount, Literal(award_amount))) # Awarded by if "organization" in funding: organization_name = funding["organization"]["name"] organization_uri = self.identifier_strategy.to_uri( FOAF.Organization, {"name": organization_name}) graph.add( (grant_uri, VIVO.assignedBy, organization_uri)) if self.create_strategy.should_create( FOAF.Organization, organization_uri): graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) # Identifiers if "external-ids" in funding and funding.get( "external-ids"): for external_identifier in funding["external-ids"][ "external-id"]: if "funding-external-identifier-value" in external_identifier: graph.add((grant_uri, VIVO.sponsorAwardId, Literal(external_identifier[ "external-id-value"]))) identifier_url = (external_identifier.get( "external-id-url", {}) or {}).get("value") if identifier_url: vcard_uri = self.identifier_strategy.to_uri( VCARD.Kind, {"url": identifier_url}) graph.add( (vcard_uri, RDF.type, VCARD.Kind)) # Has contact info graph.add((grant_uri, OBO.ARG_2000028, vcard_uri)) # Url vcard vcard_url_uri = self.identifier_strategy.to_uri( VCARD.URL, {"vcard_uri": vcard_uri}) graph.add( (vcard_url_uri, RDF.type, VCARD.URL)) graph.add((vcard_uri, VCARD.hasURL, vcard_url_uri)) graph.add((vcard_url_uri, VCARD.url, Literal(identifier_url, datatype=XSD.anyURI)))
def crosswalk_affiliations(orcid_profile, person_uri, graph): #Education for affiliation in (orcid_profile["orcid-profile"].get("orcid-activities") or {}).get("affiliations", {})\ .get("affiliation", []): if affiliation["type"] == "EDUCATION": #Gather some values degree_name = affiliation.get("role-title") organization_name=affiliation["organization"]["name"] start_date_year = (affiliation["start-date"] or {}).get("year", {}).get("value") end_date_year = (affiliation["end-date"] or {}).get("year", {}).get("value") #Organization organization_uri = ns.D[to_hash_identifier(PREFIX_ORGANIZATION, (organization_name,))] graph.add((organization_uri, RDF.type, FOAF.Organization)) graph.add((organization_uri, RDFS.label, Literal(organization_name))) if "address" in affiliation["organization"]: city = affiliation["organization"]["address"]["city"] state = affiliation["organization"]["address"]["region"] address_uri = ns.D[to_hash_identifier("geo", (city, state))] graph.add((address_uri, RDF.type, VIVO.GeographicLocation)) graph.add((organization_uri, OBO.RO_0001025, address_uri)) graph.add((address_uri, RDFS.label, Literal("%s, %s" % (city, state)))) #Output of educational process educational_process_uri = ns.D[to_hash_identifier(PREFIX_EDUCATIONAL_PROCESS, (organization_name, degree_name, start_date_year, end_date_year))] graph.add((educational_process_uri, RDF.type, VIVO.EducationalProcess)) #Has participants graph.add((educational_process_uri, OBO.RO_0000057, organization_uri)) graph.add((educational_process_uri, OBO.RO_0000057, person_uri)) #Department if "department-name" in affiliation: graph.add((educational_process_uri, VIVO.departmentOrSchool, Literal(affiliation["department-name"]))) #Interval interval_uri = educational_process_uri + "-interval" interval_start_uri = interval_uri + "-start" # start_date_year = affiliation["start-date"]["year"]["value"] if "start-date" in affiliation else None interval_end_uri = interval_uri + "-end" # end_date_year = affiliation["end-date"]["year"]["value"] if "end-date" in affiliation else None add_date_interval(interval_uri, educational_process_uri, graph, interval_start_uri if add_date(interval_start_uri, start_date_year, graph) else None, interval_end_uri if add_date(interval_end_uri, end_date_year, graph) else None) if "role-title" in affiliation: degree_name = affiliation["role-title"] #Awarded degree awarded_degree_uri = educational_process_uri + "-dgre" graph.add((awarded_degree_uri, RDF.type, VIVO.AwardedDegree)) graph.add((awarded_degree_uri, RDFS.label, Literal(degree_name))) #Assigned by organization graph.add((awarded_degree_uri, VIVO.assignedBy, organization_uri)) #Related to educational process graph.add((awarded_degree_uri, OBO.RO_0002353, educational_process_uri)) #Relates to degree degree_uri = ns.D[to_hash_identifier(PREFIX_DEGREE, (degree_name,))] graph.add((degree_uri, RDF.type, VIVO.AcademicDegree)) graph.add((degree_uri, RDFS.label, Literal(degree_name))) graph.add((awarded_degree_uri, VIVO.relates, degree_uri)) #Relates to person graph.add((awarded_degree_uri, VIVO.relates, person_uri))