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 1 commit
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 @@ -40,21 +40,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 @@ -66,10 +74,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 @@ -134,7 +146,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 @@ -155,6 +174,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
5 changes: 5 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 All @@ -76,6 +77,9 @@ def export_anthology(anthology, outdir, clean=False, dryrun=False):
data["author"] = [
anthology.people.resolve_name(name, id_) for name, id_ in data["author"]
]
for author in data["author"]:
if "affiliation" in author:
print(paper.full_id, author)
mjpost marked this conversation as resolved.
Show resolved Hide resolved
if "editor" in data:
data["editor"] = [
anthology.people.resolve_name(name, id_) for name, id_ in data["editor"]
Expand Down Expand Up @@ -185,6 +189,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
3 changes: 2 additions & 1 deletion data/xml/schema.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ MarkupText = (text | b | i | url | fixed-case | tex-math )+

first = element first { text }
last = element last { text }
affiliation = element affiliation { text }
Variant = element variant { attribute script { xsd:string }, (first? & last) }
Person = attribute id { xsd:NCName }?, (first? & last & Variant?)
Person = attribute id { xsd:NCName }?, (first? & last & Variant? & affiliation? )

local-filename = xsd:string { pattern="[A-Za-z0-9._\-]+" }
bibtex-key = xsd:string { pattern="[A-Za-z0-9\-]+" }
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="{{ .full }}" name="citation_author" >
mjpost marked this conversation as resolved.
Show resolved Hide resolved
{{ with .affiliation }}
mjpost marked this conversation as resolved.
Show resolved Hide resolved
<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