Skip to content

Commit

Permalink
Only include name variants in YAML if they appear on papers (re #86)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Bollmann committed Mar 21, 2019
1 parent 40f26b2 commit 3f9edbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions bin/anthology/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,32 @@ def __len__(self):
def is_canonical(self, name):
return name not in self.variants

def has_variants(self, name):
return name in self.canonical

def get_canonical_variant(self, name):
"""Maps a name to its canonical variant."""
return self.variants.get(name, name)

def get_all_variants(self, name):
"""Return a list of all variants for a given name.
Includes the supplied name itself.
"""
if not self.is_canonical(name):
name = self.get_canonical_variant(name)
return self.canonical[name] + [name]

def get_registered_variants(self, name):
"""Return a list of variants for a given name that are actually
associated with papers.
Will only return true variants, not including the canonical name.
"""
if not self.is_canonical(name):
name = self.get_canonical_variant(name)
return [n for n in self.canonical[name] if n in self.papers]

def get_slug(self, name):
if name in self.slugs:
return self.slugs[name]
Expand Down
4 changes: 2 additions & 2 deletions bin/create_hugo_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def export_anthology(anthology, outdir, dryrun=False):
key=lambda p: p[1],
reverse=True,
)
if name in anthology.people.canonical: # name has variants
if anthology.people.has_variants(name):
data["variant_entries"] = [
anthology.people.get_slug(var)
for var in anthology.people.canonical[name]
for var in anthology.people.get_registered_variants(name)
]
else:
data["canonical_entry"] = anthology.people.get_slug(
Expand Down

0 comments on commit 3f9edbb

Please sign in to comment.