Preserve confirmed single-name Springer authors
Metadata integrity checks / metadata (push) Successful in 8m28s
Metadata integrity checks / metadata (push) Successful in 8m28s
This commit is contained in:
@@ -54,6 +54,27 @@ def read_page(index, url):
|
||||
return raw, evidence
|
||||
|
||||
|
||||
def require_display_authors(nodes, authors):
|
||||
matching_article_lists = []
|
||||
for node in nodes:
|
||||
if node.tag != 'script' or node.attrs.get('type') != 'application/ld+json':
|
||||
continue
|
||||
try:
|
||||
article = json.loads(''.join(node.children))
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
if not isinstance(article, dict) or article.get('@type') != 'ScholarlyArticle':
|
||||
continue
|
||||
entries = article.get('author')
|
||||
if not isinstance(entries, list) or not all(
|
||||
isinstance(entry, dict) and isinstance(entry.get('name'), str) for entry in entries
|
||||
):
|
||||
raise ValueError('Unreviewed Springer article author list')
|
||||
matching_article_lists.append([clean(entry['name']) for entry in entries])
|
||||
if matching_article_lists != [authors]:
|
||||
raise ValueError('Single-name author requires matching Springer display author list')
|
||||
|
||||
|
||||
def parse_chapter(html, doi, *, book_title, publication_year):
|
||||
nodes = list(Document(html).root.walk())
|
||||
meta = defaultdict(list)
|
||||
@@ -73,12 +94,22 @@ def parse_chapter(html, doi, *, book_title, publication_year):
|
||||
raise ValueError('Missing named chapter authors')
|
||||
authors = []
|
||||
for raw in raw_authors:
|
||||
if ',' not in raw:
|
||||
name = clean(raw)
|
||||
if len(name.split()) != 1 or not any(character.isalpha() for character in name):
|
||||
raise ValueError('Unreviewed citation author format')
|
||||
authors.append(name)
|
||||
continue
|
||||
if raw.count(',') != 1:
|
||||
raise ValueError('Unreviewed citation author format')
|
||||
family, given = [clean(s) for s in raw.split(',', 1)]
|
||||
if not family or not given:
|
||||
raise ValueError('Incomplete citation author')
|
||||
authors.append({'given':given, 'family':family})
|
||||
if any(isinstance(author, str) for author in authors):
|
||||
display_names = [author if isinstance(author, str) else author['given']+' '+author['family']
|
||||
for author in authors]
|
||||
require_display_authors(nodes, display_names)
|
||||
abstract_nodes = [n for n in nodes if n.attrs.get('id') == 'Abs1-content']
|
||||
if len(abstract_nodes) > 1:
|
||||
raise ValueError('Ambiguous abstract section')
|
||||
|
||||
Reference in New Issue
Block a user