Skip to content

Commit 9673f00

Browse files
derek73claude
andcommitted
Lift _vocab's regex constants to the module top
Successive parity fixes appended _PERIOD_NOT_AT_END mid-file and the PH/D credential pair after the last function; every pipeline module keeps its module-level regexes in one block after the imports, as this file's own _INITIAL already did. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 1eca44b commit 9673f00

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

nameparser/_pipeline/_vocab.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
# sync by hand; layering forbids importing the config package here.
1818
_INITIAL = re.compile(r"^(\w\.|[A-Z])$")
1919

20+
# Ported verbatim from v1 (nameparser/config/regexes.py
21+
# "period_not_at_end") -- layering forbids the config import; keep in
22+
# sync by hand.
23+
_PERIOD_NOT_AT_END = re.compile(r".*\..+$", re.I)
24+
25+
# The fix_phd credential pair ('Ph.' + 'D.' as adjacent tokens), shared
26+
# by segment's suffix-comma detection and group's merge (v1 extracted
27+
# the credential pre-parse; the two stages must agree on the pattern).
28+
PH = re.compile(r"^ph\.?$", re.IGNORECASE)
29+
D = re.compile(r"^d\.?$", re.IGNORECASE)
30+
2031

2132
def is_initial(text: str) -> bool:
2233
"""'A.' / 'j.' / bare capital -- v1's is_an_initial."""
@@ -94,11 +105,6 @@ def splits_into_suffixes(text: str, cores: frozenset[str],
94105
return False
95106

96107

97-
# Ported verbatim from v1 (nameparser/config/regexes.py
98-
# "period_not_at_end") -- layering forbids the config import; keep in
99-
# sync by hand.
100-
_PERIOD_NOT_AT_END = re.compile(r".*\..+$", re.I)
101-
102108

103109
def period_joined_vocab(text: str, lexicon: Lexicon) -> str | None:
104110
"""v1's parse_pieces derivation for interior-period tokens
@@ -118,9 +124,3 @@ def period_joined_vocab(text: str, lexicon: Lexicon) -> str | None:
118124
return "suffix"
119125
return None
120126

121-
122-
# The fix_phd credential pair ('Ph.' + 'D.' as adjacent tokens), shared
123-
# by segment's suffix-comma detection and group's merge (v1 extracted
124-
# the credential pre-parse; the two stages must agree on the pattern).
125-
PH = re.compile(r"^ph\.?$", re.IGNORECASE)
126-
D = re.compile(r"^d\.?$", re.IGNORECASE)

0 commit comments

Comments
 (0)