Skip to content

Commit

Permalink
Update create_hugo_yaml.py to export people
Browse files Browse the repository at this point in the history
  • Loading branch information
mbollmann committed Apr 21, 2024
1 parent 966262b commit 2a67631
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
90 changes: 41 additions & 49 deletions bin/create_hugo_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
"""

from docopt import docopt
from collections import defaultdict
from collections import Counter, defaultdict
import logging as log
import os
from rich import print
from rich.logging import RichHandler
from rich.progress import Progress
import yaml
Expand Down Expand Up @@ -246,54 +247,49 @@ def export_anthology(anthology, outdir, clean=False, dryrun=False):
progress.update(task, advance=len(collection_papers))

# Export volumes
with open(f"{outdir}/volumes.yaml", "w") as f:
yaml.dump(all_volumes, Dumper=Dumper, stream=f)

exit(35)
##### NOT PORTED YET BEYOND THIS POINT
if not dryrun:
with open(f"{outdir}/volumes.yaml", "w") as f:
yaml.dump(all_volumes, Dumper=Dumper, stream=f)

# Prepare people index
# Export people
people = defaultdict(dict)
for id_ in anthology.people.personids():
name = anthology.people.get_canonical_name(id_)
log.debug("export_anthology: processing person '{}'".format(repr(name)))
data = name.as_dict()
data["slug"] = id_
if id_ in anthology.people.comments:
data["comment"] = anthology.people.comments[id_]
if id_ in anthology.people.similar:
data["similar"] = sorted(anthology.people.similar[id_])
papers_for_id = anthology.people.get_papers(id_, role="author") + [
paper
for paper in anthology.people.get_papers(id_, role="editor")
if anthology.papers.get(paper).is_volume
]
data["papers"] = sorted(
papers_for_id,
key=lambda p: anthology.papers.get(p).get("year"),
for person_id, person in anthology.people.items():
cname = person.canonical_name
papers = sorted(
person.papers(),
key=lambda paper: paper.year,
reverse=True,
)
data["coauthors"] = sorted(
[[co_id, count] for (co_id, count) in anthology.people.get_coauthors(id_)],
key=lambda p: p[1],
reverse=True,
)
data["venues"] = sorted(
[
[venue, count]
for (venue, count) in anthology.people.get_venues(id_).items()
],
key=lambda p: p[1],
reverse=True,
)
variants = [
n
for n in anthology.people.get_used_names(id_)
if n.first != name.first or n.last != name.last
]
if len(variants) > 0:
data["variant_entries"] = [name.as_dict() for name in sorted(variants)]
people[id_[0]][id_] = data
data = {
"first": cname.first,
"last": cname.last,
"full": cname.as_first_last(),
"slug": person_id,
"papers": [paper.full_id for paper in papers],
"coauthors": anthology.people.find_coauthors_counter(person).most_common(),
"venues": Counter(
venue for paper in papers for venue in paper.venue_ids
).most_common(),
}
if len(person.names) > 1:
data["variant_entries"] = [
{"first": n.first, "last": n.last, "full": n.as_first_last()}
for n in person.names[1:]
]
if person.comment is not None:
data["comment"] = person.comment
similar = anthology.people.similar.subset(person_id)
if len(similar) > 1:
data["similar"] = list(similar - {person_id})
people[person_id[0]][person_id] = data

if not dryrun:
for first_letter, people_list in people.items():
with open(f"{outdir}/people/{first_letter}.yaml", "w") as f:
yaml.dump(people_list, Dumper=Dumper, stream=f)

exit(35)
##### NOT PORTED YET BEYOND THIS POINT

# Prepare venue index
venues = {}
Expand Down Expand Up @@ -373,10 +369,6 @@ def volume_sorter(volume):
yaml.dump(sigs, Dumper=Dumper, stream=f)
progress.update()

for first_letter, people_list in people.items():
with open("{}/people/{}.yaml".format(outdir, first_letter), "w") as f:
yaml.dump(people_list, Dumper=Dumper, stream=f)
progress.update()
progress.close()


Expand Down
6 changes: 5 additions & 1 deletion python/acl_anthology/people/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def set_canonical_name(self, name: Name) -> None:
self.names.insert(0, name)

def papers(self) -> Iterator[Paper]:
"""Returns an iterator over all papers associated with this person."""
"""Returns an iterator over all papers associated with this person.
Note:
This will return papers where this person is an author, as well as frontmatter of volumes where they are an editor. It will _not_ include all other papers in volumes they have edited.
"""
for anthology_id in self.item_ids:
paper_id = anthology_id[-1]
if paper_id is not None:
Expand Down

0 comments on commit 2a67631

Please sign in to comment.