Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Reduce import/merging errors #557

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/crossref.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ def save_doi_metadata(self, metadata, extra_orcids=None):
if metadata is None or type(metadata) != dict:
raise ValueError('Invalid metadata format, expecting a dict')
if not metadata.get('author'):
raise ValueError('No author provided')
# BareName has "last" as mandatory field
metadata['author'] = {'family': 'N/A'}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is never going to be executed because it is just after an exception is raised.


if not metadata.get('title'):
raise ValueError('No title')
Expand Down
23 changes: 14 additions & 9 deletions papers/fingerprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
stripped_chars = re.compile(r'[^- a-z0-9]')


def create_paper_plain_fingerprint(title, authors, year):
def create_paper_plain_fingerprint(title, authors, year, pubdate):
"""
Creates a robust summary of a bibliographic reference.
This plain fingerprint should then be converted to an
Expand All @@ -43,6 +43,7 @@ def create_paper_plain_fingerprint(title, authors, year):
:param authors: the list of author names, represented
as (first_name, last_name) pairs
:param year: the year of publication of the paper
:param pubdate: the publication date of the paper, as date object

>>> create_paper_plain_fingerprint(' It cleans whitespace And Case\\n',[('John','Doe')], 2015)
u'it-cleans-whitespace-and-case/doe'
Expand All @@ -62,18 +63,22 @@ def create_paper_plain_fingerprint(title, authors, year):
title = re.sub('[ -]+', '-', title)
buf = title

# If the title is long enough, we return the fingerprint as is
if len(buf) > 50:
return buf

# If the title is very short, we add the year (for "Preface", "Introduction", "New members" cases)
# if len(title) <= 16:
# Add the year for disabiguation (for "Preface", "Introduction", "New members" cases)
# Necessary also for very frequent although long titles, such as
# "Extracts from the Records of the Boston Society for Medical Improvement"
# (doi:10.1097/00000441-185410000-00006 etc.)
if not '-' in title:
buf += '-'+str(year)
if len(title) > 80:
# We're above a typical max length of email line. Hopefully the title
# is unique enough and we may catch preprints from the same year.
buf += '-'+str(year)
else:
buf += '-'+pubdate.strftime("%Y%m%d")

author_names_list = []
for author in authors:
if not author:
# CrossRef and our own importer sometimes provide placeholder author names
if not author and re.sub('\W', '', author.lower()) != 'na':
continue
author = (remove_diacritics(author[0]), remove_diacritics(author[1]))

Expand Down
6 changes: 4 additions & 2 deletions papers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,14 @@ def recompute_fingerprint_and_merge_if_needed(self):
new_fingerprint = self.new_fingerprint()
if self.fingerprint == new_fingerprint:
return
match = Paper.objects.filter(fingerprint=new_fingerprint).first()
if match is None:
matches = Paper.objects.filter(fingerprint=new_fingerprint)
if len(matches) > 10 or len(matches) < 1:
# No usable/realistic matches, leave alone
self.fingerprint = new_fingerprint
self.save(update_fields=['fingerprint'])
return
else:
match = matches.first()
match.merge(self)
return match

Expand Down