From deb0926c14d9ce2ca90d4d4e983683e158e76432 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 May 2019 15:04:39 -0700 Subject: improved CSL transform (structured author names) --- python/fatcat_tools/transforms/csl.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'python/fatcat_tools/transforms') diff --git a/python/fatcat_tools/transforms/csl.py b/python/fatcat_tools/transforms/csl.py index 989629ab..f94fa372 100644 --- a/python/fatcat_tools/transforms/csl.py +++ b/python/fatcat_tools/transforms/csl.py @@ -34,31 +34,30 @@ def release_to_csl(entity): contribs = [] for contrib in (entity.contribs or []): if contrib.creator: - # TODO: should we actually be pulling creator metadata? or just - # using release-local raw metadata? - family = contrib.creator.surname - if not family: - if not contrib.raw_name: - raise ValueError("CSL requires some surname (family name)") - family = contrib.raw_name.split()[-1] + # Default to "local" (publication-specific) metadata; fall back to + # creator-level + family = contrib.surname or contrib.creator.surname or (contrib.raw_name and contrib.raw_name.split()[-1]) + if not contrib.raw_name: + raise ValueError("CSL requires some surname (family name)") c = dict( - family=contrib.creator.surname, - given=contrib.creator.given_name, + family=family, + given=contrib.given_name or contrib.creator.given_name, #dropping-particle #non-dropping-particle #suffix #comma-suffix #static-ordering - literal=contrib.raw_name, # or display_name? + literal=contrib.raw_name or contrib.creator.display_name, #parse-names, role=contrib.role, ) else: + family = contrib.surname or (contrib.raw_name and contrib.raw_name.split()[-1]) if not contrib.raw_name: raise ValueError("CSL requires some surname (family name)") c = dict( - # XXX: possible inclusion of full name metadata in release_contrib - family=contrib.raw_name.split()[-1], + family=family, + given=contrib.given_name, literal=contrib.raw_name, role=contrib.role, ) -- cgit v1.2.3