Skip to content

Commit

Permalink
Do not rely on empty bibcodes from datacite parser to track software
Browse files Browse the repository at this point in the history
The datacite metadata parser may recover a bibcode (e.g., from 'suplemented by')
which has not been generated by citation capture, thus when this field
is filled it does not mean that the record is a software one
  • Loading branch information
marblestation committed Jan 4, 2019
1 parent 3efc6d3 commit 3a05b47
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 4 additions & 1 deletion ADSCitationCapture/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def store_citation(app, citation_change, content_type, raw_metadata, parsed_meta

def get_citation_target_metadata(app, citation_change):
"""
If the citation target already exists in the database, return the metadata.
If the citation target already exists in the database, return the raw and
parsed metadata together with the status of the citation target in the
database.
If not, return an empty dictionary.
"""
citation_in_db = False
Expand All @@ -61,6 +63,7 @@ def get_citation_target_metadata(app, citation_change):
if citation_target_in_db:
metadata['raw'] = citation_target.raw_cited_metadata
metadata['parsed'] = citation_target.parsed_cited_metadata
metadata['status'] = citation_target.status
return metadata

def get_citations_by_bibcode(app, bibcode):
Expand Down
2 changes: 1 addition & 1 deletion ADSCitationCapture/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _parse_metadata_zenodo_doi(raw_metadata):
logger.exception("Failed parsing")
return {}
parsed_metadata['link_alive'] = True
is_software = parsed_metadata['doctype'].lower() == "software"
is_software = parsed_metadata.get('doctype', u'').lower() == "software"

if is_software:
zenodo_bibstem = "zndo"
Expand Down
7 changes: 4 additions & 3 deletions ADSCitationCapture/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def task_process_new_citation(citation_change, force=False):
citation_target_in_db = bool(metadata) # False if dict is empty
raw_metadata = metadata.get('raw', None)
parsed_metadata = metadata.get('parsed', None)
if parsed_metadata and parsed_metadata.get('bibcode') not in (None, ""):
status = "REGISTERED"
if citation_target_in_db:
status = metadata.get('status', 'DISCARDED') # "REGISTERED" if it is a software record

if citation_change.content_type == adsmsg.CitationChangeContentType.doi \
and citation_change.content not in ["", None]:
Expand All @@ -55,7 +55,8 @@ def task_process_new_citation(citation_change, force=False):
raw_metadata = doi.fetch_metadata(app.conf['DOI_URL'], app.conf['DATACITE_URL'], citation_change.content)
if raw_metadata:
parsed_metadata = doi.parse_metadata(raw_metadata)
if parsed_metadata.get('bibcode') not in (None, ""):
is_software = parsed_metadata.get('doctype', u'').lower() == "software"
if parsed_metadata.get('bibcode') not in (None, "") and is_software:
status = "REGISTERED"
elif citation_change.content_type == adsmsg.CitationChangeContentType.pid \
and citation_change.content not in ["", None]:
Expand Down
3 changes: 2 additions & 1 deletion ADSCitationCapture/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ def _init_mock_data(self):
'version_of': [],
'source': u'ZENODO',
'link_alive': True
}
},
'status': 'REGISTERED'
}

0 comments on commit 3a05b47

Please sign in to comment.