Use word-boundary matching for personnel name blocklist
Devin Review correctly flagged that the bare "NO" and "KET" entries in the blocklist would silently drop common Indonesian names (KETUT, NOVA, NOOR, NORMAN, NOVIANTI, ...) because the check used startswith rather than a word boundary. Replaced the per-prefix loop with a single compiled regex anchored at ^ with a trailing \b, which still matches column headers like "NO" or "KET" on their own line but no longer rejects "NOOR HIDAYAT" or "KETUT WARDANA". Also fixes the same bug in _following_jabatan. Added two regression tests covering both directions: names starting with the offending tokens are kept, bare column headers still rejected. Co-Authored-By: adrian kuman firmansah <adriancuman@gmail.com>
This commit is contained in:
@@ -50,8 +50,15 @@ _RE_RANK_NRP_LINE = re.compile(
|
||||
# line in tabular layouts.
|
||||
_RE_ROW_NUMBER = re.compile(r"^\s*(\d{1,3})\s*[.)]\s*$")
|
||||
# Lines that should never be interpreted as a personnel name. These are
|
||||
# section headers, OCR garbage anchors, and column header tokens.
|
||||
_NAME_BLOCKLIST_PREFIXES: tuple[str, ...] = (
|
||||
# section headers, OCR garbage anchors, and column header tokens. We match
|
||||
# them with a *word-boundary* regex (built from this list) rather than a
|
||||
# bare ``startswith`` check, because short tokens like ``"NO"`` and
|
||||
# ``"KET"`` would otherwise reject perfectly valid Indonesian names
|
||||
# (e.g. ``"NOVA SARI"``, ``"NOOR HIDAYAT"``, ``"KETUT WARDANA"`` — the
|
||||
# latter being an extremely common Balinese birth-order name).
|
||||
_NAME_BLOCKLIST_TOKENS: tuple[str, ...] = (
|
||||
"PADA TANGGAL", # multi-word entries first so they win the alternation
|
||||
"SURAT PERINTAH",
|
||||
"DASAR",
|
||||
"PERIHAL",
|
||||
"PERTIMBANGAN",
|
||||
@@ -60,7 +67,6 @@ _NAME_BLOCKLIST_PREFIXES: tuple[str, ...] = (
|
||||
"UNTUK",
|
||||
"TEMBUSAN",
|
||||
"DIKELUARKAN",
|
||||
"PADA TANGGAL",
|
||||
"SELESAI",
|
||||
"DAFTAR",
|
||||
"LAMPIRAN",
|
||||
@@ -71,7 +77,6 @@ _NAME_BLOCKLIST_PREFIXES: tuple[str, ...] = (
|
||||
"RESOR",
|
||||
"SEKTOR",
|
||||
"MABES",
|
||||
"SURAT PERINTAH",
|
||||
"NRP",
|
||||
"NIP",
|
||||
"PANGKAT",
|
||||
@@ -81,6 +86,10 @@ _NAME_BLOCKLIST_PREFIXES: tuple[str, ...] = (
|
||||
"KET",
|
||||
"NO",
|
||||
)
|
||||
_RE_NAME_BLOCKLIST = re.compile(
|
||||
r"^(?:" + "|".join(re.escape(tok) for tok in _NAME_BLOCKLIST_TOKENS) + r")\b",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
# A name should look like a name: mostly letters, common punctuation, and
|
||||
# at least one alphabetic character. Pure-numeric or pure-symbol lines are
|
||||
# rejected.
|
||||
@@ -92,10 +101,8 @@ def _is_plausible_name(line: str) -> bool:
|
||||
stripped = line.strip()
|
||||
if not stripped or not _RE_NAME_OK.search(stripped):
|
||||
return False
|
||||
upper = stripped.upper()
|
||||
for prefix in _NAME_BLOCKLIST_PREFIXES:
|
||||
if upper.startswith(prefix):
|
||||
return False
|
||||
if _RE_NAME_BLOCKLIST.match(stripped):
|
||||
return False
|
||||
if _RE_ROW_NUMBER.match(stripped):
|
||||
return False
|
||||
if _RE_RANK_NRP_LINE.search(stripped):
|
||||
@@ -122,8 +129,7 @@ def _following_jabatan(lines: list[str], idx: int) -> str | None:
|
||||
break
|
||||
if _RE_ROW_NUMBER.match(candidate):
|
||||
break
|
||||
upper = candidate.upper()
|
||||
if any(upper.startswith(p) for p in _NAME_BLOCKLIST_PREFIXES):
|
||||
if _RE_NAME_BLOCKLIST.match(candidate):
|
||||
break
|
||||
parts.append(candidate)
|
||||
if not parts:
|
||||
|
||||
Reference in New Issue
Block a user