Skip to content

Commit d59c649

Browse files
larseggertrjsparksNGPixel
authored
fix: Fix spurious author extraction errors (ietf-tools#4799)
* Handle single-word author names * Some i18n names, e.g., "शिला के.सी." have a dot at the end that is also part of the ASCII, e.g., "Shilaa Kesii." That trailing dot breaks extract_authors(). Avoid this issue by stripping the dot from the ASCII. * Honorifics need to be part of the extracted ASCII name (e.g., "Lady Garcia") * feat: stop supporting pre-tzaware migration database dumps. (ietf-tools#4782) * feat: stop supporting pre-tzaware migration database dumps. * chore: remove unnecessary env variable * chore: Use `codespell` to fix typos in comments. (ietf-tools#4794) First part of replacement of ietf-tools#4651 * feat: Only show IPR search form when not showing search results (ietf-tools#4793) * feat: Only show IPR search form when not showing search results Put it into a collapsible that is only expanded by default when not showing search results. Fixes ietf-tools#4569 * Don't use example target name * fix: Don't show reorder UI fixtures unless user can reorder (ietf-tools#4785) Fixes ietf-tools#4773 Co-authored-by: Robert Sparks <rjsparks@nostrum.com> * chore: Update deps and fix resulting HTML validation issues (ietf-tools#4790) * ci: add missing build matrix config for test-playwright-legacy step * Single-letter last names exist (e.g., "Carolina de la O") * Align regex with others * Fix extraction of very long author names * Need to be more general * Add comment * Also handle i18n names with trailing semicolons * Name suffixes need to be part of the extracted author names * Handle i18n names with embedded commas Co-authored-by: Robert Sparks <rjsparks@nostrum.com> Co-authored-by: Nicolas Giard <github@ngpixel.com>
1 parent 3af68b6 commit d59c649

4 files changed

Lines changed: 29 additions & 12 deletions

File tree

ietf/person/factories.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class Meta:
6565

6666
user = factory.SubFactory(UserFactory)
6767
name = factory.LazyAttribute(lambda p: normalize_name('%s %s'%(p.user.first_name, p.user.last_name)))
68-
ascii = factory.LazyAttribute(lambda p: force_text(unidecode_name(p.name)))
68+
# Some i18n names, e.g., "शिला के.सी." have a dot at the end that is also part of the ASCII, e.g., "Shilaa Kesii."
69+
# That trailing dot breaks extract_authors(). Avoid this issue by stripping the dot from the ASCII.
70+
# Some others have a trailing semicolon (e.g., "உயிரோவியம் தங்கராஐ;") - strip those, too.
71+
ascii = factory.LazyAttribute(lambda p: force_text(unidecode_name(p.name)).rstrip(".;"))
6972

7073
class Params:
7174
with_bio = factory.Trait(biography = "\n\n".join(fake.paragraphs())) # type: ignore

ietf/submit/test_submission.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33

44

5-
Network Working Group %(initials)s %(surname)s
5+
Network Working Group %(firstpagename)37s
66
Internet-Draft Test Centre Inc.
77
Intended status: Informational %(month)s %(year)s
88
Expires: %(expiration)s
99

1010

1111
%(title)s
1212
%(name)s
13-
1413
Abstract
1514

1615
This document describes how to test tests.

ietf/submit/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def submission_file(name_in_doc, name_in_post, group, templatename, author=None,
107107
if year is None:
108108
year = _today.strftime("%Y")
109109

110+
# extract_authors() cuts the author line off at the first space past 80 characters
111+
# very long factory-generated names can hence be truncated, causing a failure
112+
# ietf/submit/test_submission.txt was changed so that 37-character names and shorter will work
113+
# this may need further adjustment if longer names still cause failures
110114
submission_text = template % dict(
111115
date=_today.strftime("%d %B %Y"),
112116
expiration=(_today + datetime.timedelta(days=100)).strftime("%d %B, %Y"),
@@ -119,6 +123,7 @@ def submission_file(name_in_doc, name_in_post, group, templatename, author=None,
119123
asciiAuthor=author.ascii,
120124
initials=author.initials(),
121125
surname=author.ascii_parts()[3] if ascii else author.name_parts()[3],
126+
firstpagename=f"{author.initials()} {author.ascii_parts()[3] if ascii else author.name_parts()[3]}",
122127
asciiSurname=author.ascii_parts()[3],
123128
email=email,
124129
title=title,

ietf/utils/draft.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ def extract_authors(self):
592592
"honor" : r"(?:[A-Z]\.|Dr\.?|Dr\.-Ing\.|Prof(?:\.?|essor)|Sir|Lady|Dame|Sri)",
593593
"prefix": r"([Dd]e|Hadi|van|van de|van der|Ver|von|[Ee]l)",
594594
"suffix": r"(jr.?|Jr.?|II|2nd|III|3rd|IV|4th)",
595-
"first" : r"([A-Z][-A-Za-z'`~]*)(( ?\([A-Z][-A-Za-z'`~]*\))?(\.?[- ]{1,2}[A-Za-z'`~]+)*)",
596-
"last" : r"([-A-Za-z'`~]{2,})",
595+
"first" : r"([A-Z][-A-Za-z'`~,]*)(( ?\([A-Z][-A-Za-z'`~,]*\))?(\.?[- ]{1,2}[A-Za-z'`~]+)*)",
596+
"last" : r"([-A-Za-z'`~,]+)", # single-letter last names exist
597597
"months": r"(January|February|March|April|May|June|July|August|September|October|November|December)",
598598
"mabbr" : r"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\.?",
599599
}
@@ -658,7 +658,12 @@ def dotexp(s):
658658

659659
# permit insertion of middle names between first and last, and
660660
# add possible honorific and suffix information
661-
authpat = r"(?:^| and )(?:%(hon)s ?)?(['`]*%(first)s\S*( +[^ ]+)* +%(last)s)( *\(.*|,( [A-Z][-A-Za-z0-9]*)?| %(suffix)s| [A-Z][a-z]+)?" % {"hon":hon, "first":first, "last":last, "suffix":suffix,}
661+
if last:
662+
authpat = r"(?:^| and )((?:%(hon)s ?)?['`]*%(first)s\S*( +[^ ]+)* +%(last)s(?: %(suffix)s)?)( *\(.*|,( [A-Z][-A-Za-z0-9]*)?| [A-Z][a-z]+)?" % {"hon":hon, "first":first, "last":last, "suffix":suffix,}
663+
else:
664+
# handle single-word names
665+
authpat = r"(?:^| and )((?:%(hon)s ?)?['`]*%(first)s\S*( +[^ ]+)*(?: %(suffix)s)?)( *\(.*|,( [A-Z][-A-Za-z0-9]*)?| [A-Z][a-z]+)?" % {"hon":hon, "first":first, "suffix":suffix,}
666+
662667
return authpat
663668

664669
authors = []
@@ -812,16 +817,17 @@ def dotexp(s):
812817
author = author[:-len(suffix)].strip()
813818
else:
814819
suffix = None
815-
if "," in author:
820+
if ", " in author:
816821
last, first = author.split(",",1)
817822
author = "%s %s" % (first.strip(), last.strip())
818823
if not " " in author:
819824
if "." in author:
820825
first, last = author.rsplit(".", 1)
821826
first += "."
822827
else:
823-
author = "[A-Z].+ " + author
824-
first, last = author.rsplit(" ", 1)
828+
# handle single-word names
829+
first = author
830+
last = ""
825831
else:
826832
if "." in author:
827833
first, last = author.rsplit(".", 1)
@@ -899,10 +905,14 @@ def dotexp(s):
899905
#else:
900906
# fullname = author_match
901907
fullname = re.sub(" +", " ", fullname)
902-
if left == firstname:
903-
given_names, surname = fullname.rsplit(None, 1)
908+
if re.search(r"\s", fullname):
909+
if left == firstname:
910+
given_names, surname = fullname.rsplit(None, 1)
911+
else:
912+
surname, given_names = fullname.split(None, 1)
904913
else:
905-
surname, given_names = fullname.split(None, 1)
914+
# handle single-word names
915+
given_names, surname = (fullname, "")
906916
if " " in given_names:
907917
first, middle = given_names.split(None, 1)
908918
else:

0 commit comments

Comments
 (0)