Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author affiliation to page metadata #2325

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Icon

#virtual environment
/venv/

.coverage
35 changes: 28 additions & 7 deletions bin/anthology/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,29 @@ def score_variant(name):


class PersonName:
first, last = "", ""
"""
Represents an instance of a person name.
"""

def __init__(self, first, last, script="roman", variant: "PersonName" = None):
def __init__(
self, first, last, affiliation=None, script="roman", variant: "PersonName" = None
):
"""
Initialize an instance of a person's name.
"""
self.first = first if first is not None else ""
self.last = last
self.affiliation = affiliation
self.script = script
self.variant = variant

def from_element(person_element):
"""
Reads from the XML, which includes an optional first name, a last name,
and an optional variant (itself containing an optional first name, and a
last name).
affiliation, and an optional variant (itself containing an optional first name,
and a last name).
"""
first, last = "", ""
first, last, affiliation = "", "", ""
# The name variant script, defaults to roman
script = person_element.attrib.get("script", "roman")
variant = None
Expand All @@ -65,10 +73,14 @@ def from_element(person_element):
first = element.text or ""
elif tag == "last":
last = element.text or ""
elif tag == "affiliation":
affiliation = element.text or ""
elif tag == "variant":
variant = PersonName.from_element(element)

return PersonName(first, last, script=script, variant=variant)
return PersonName(
first, last, affiliation=affiliation, script=script, variant=variant
)

def from_repr(repr_):
parts = repr_.split(" || ")
Expand Down Expand Up @@ -133,7 +145,14 @@ def as_citeproc_json(self):
return {"family": self.last, "given": self.first}

def as_dict(self):
return {"first": self.first, "last": self.last, "full": self.full}
d = {
"first": self.first,
"last": self.last,
"full": self.full,
}
if self.affiliation:
d["affiliation"] = self.affiliation
return d

def without_variant(self):
if self.variant is None:
Expand All @@ -154,6 +173,8 @@ def __lt__(self, other):
return self.full < other.full

def __str__(self):
if self.affiliation:
return f"{self.full} ({self.affiliation})"
return self.full

def __repr__(self):
Expand Down
2 changes: 2 additions & 0 deletions bin/create_hugo_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def export_anthology(anthology, outdir, clean=False, dryrun=False):
# "mla": "modern-language-association-7th-edition",
}

# Load paper information
for id_, paper in anthology.papers.items():
log.debug("export_anthology: processing paper '{}'".format(id_))
data = paper.as_dict()
Expand Down Expand Up @@ -192,6 +193,7 @@ def volume_sorter(volume):
# the alphabetically-earliest volume
return min(volumes[volume]["venues"])

# sort volumes
event_data["volumes"] = sorted(event_data["volumes"], key=volume_sorter)

events[event_name] = event_data
Expand Down
2 changes: 1 addition & 1 deletion data/xml/W18.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13121,7 +13121,7 @@
</paper>
<paper id="19">
<title>A Call for Clarity in Reporting <fixed-case>BLEU</fixed-case> Scores</title>
<author><first>Matt</first><last>Post</last></author>
<author><first>Matt</first><last>Post</last><affiliation>Amazon</affiliation></author>
<pages>186–191</pages>
<url hash="240bc5c5">W18-6319</url>
<attachment type="poster" hash="19fea775">W18-6319.Poster.pdf</attachment>
Expand Down
9 changes: 8 additions & 1 deletion hugo/layouts/papers/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
<meta content="{{ $paper.title }}" name="citation_title" >
{{ range $paper.author }}
{{ $first_letter := slicestr .id 0 1 }}
<meta content="{{ (index $.Site.Data.people $first_letter .id).full }}" name="citation_author" >
{{ $author := index .Site.Data.people $first_letter .id }}
<meta content="{{ $author.full }}" name="citation_author" >
{{ with $author.affiliation }}
<meta content="{{ . }}" name="citation_author_institution">
{{ end }}
{{ with $author.orcid }}
<meta content="{{ . }}" name="citation_author_orcid">
{{ end }}
{{ end }}
{{ with $paper.parent_volume_id }}
{{ $volume := index $.Site.Data.volumes . }}
Expand Down