Skip to content

Commit

Permalink
fix: infer funderIdentifierType from identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Aug 30, 2023
1 parent 452a21a commit e6773cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,6 @@ def gather_funding(focus):
yield (_funder_ref, RDF.type, DCTERMS.Agent)
yield (_funder_ref, DCTERMS.identifier, _funder_uri)
yield (_funder_ref, FOAF.name, _funder_name)
yield (_funder_ref, OSF.funderIdentifierType, _funding.get('funder_identifier_type'))
_award_uri = _funding.get('award_uri')
_award_title = _funding.get('award_title')
_award_number = _funding.get('award_number')
Expand Down
1 change: 1 addition & 0 deletions osf/metadata/rdfutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OSFIO = rdflib.Namespace(website_settings.DOMAIN)
# external pid namespaces:
DOI = rdflib.Namespace('https://doi.org/')
DxDOI = rdflib.Namespace('http://dx.doi.org/') # "earlier but no longer preferred" DOI namespace
ORCID = rdflib.Namespace('https://orcid.org/')
ROR = rdflib.Namespace('https://ror.org/')
# external terminology namespaces:
Expand Down
15 changes: 13 additions & 2 deletions osf/metadata/serializers/datacite/datacite_tree_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
RDF,
DCTERMS,
DOI,
DxDOI,
FOAF,
ORCID,
OSF,
Expand Down Expand Up @@ -154,6 +155,8 @@ def _visit_creators(self, parent_el, focus_iri):
def _identifier_type_and_value(self, identifier: str):
if identifier.startswith(DOI):
return ('DOI', without_namespace(identifier, DOI))
elif identifier.startswith(DxDOI):
return ('DOI', without_namespace(identifier, DxDOI))
elif identifier.startswith(ROR):
return ('ROR', identifier) # ROR keeps the full IRI
elif identifier.startswith(ORCID):
Expand All @@ -162,6 +165,13 @@ def _identifier_type_and_value(self, identifier: str):
return ('URL', identifier)
logger.warning('skipping non-IRI-shaped identifier "%s"', identifier)

def _funder_identifier_type(self, identifier: str):
if identifier.startswith(DxDOI) or identifier.startswith(DOI):
return 'Crossref Funder ID'
if identifier.startswith(ROR):
return 'ROR'
return 'Other'

def _get_name_type(self, agent_iri):
if (agent_iri, RDF.type, FOAF.Person) in self.basket:
return 'Personal'
Expand Down Expand Up @@ -261,12 +271,13 @@ def _visit_funding_references(self, parent_el):
for _funder in self.basket[OSF.funder]:
fundref_el = self.visit(fundrefs_el, 'fundingReference')
self.visit(fundref_el, 'funderName', text=next(self.basket[_funder:FOAF.name], ''))
funder_identifier = next(self.basket[_funder:DCTERMS.identifier], '')
self.visit(
fundref_el,
'funderIdentifier',
text=next(self.basket[_funder:DCTERMS.identifier], ''),
text=funder_identifier,
attrib={
'funderIdentifierType': next(self.basket[_funder:OSF.funderIdentifierType], ''),
'funderIdentifierType': self._funder_identifier_type(funder_identifier),
},
)
for _funding_award in self.basket[OSF.hasFunding]:
Expand Down

0 comments on commit e6773cb

Please sign in to comment.