Normalize --chapters filter input to zero-padded chapter numbers #1

Closed
opened 2026-05-31 17:58:59 +02:00 by Brummel · 0 comments
Owner

Symptom

The --chapters filter on alpha-id suggest silently returns zero
results whenever the supplied value is not a two-digit zero-padded
chapter number. The filter takes the value verbatim and compares it by
exact string equality, so the natural inputs a user reaches for —
--chapters E,I (code letters) or --chapters 4,9 (un-padded numbers)
— never match any candidate and the suggestion list comes back empty
with no diagnostic.

Reproduction

Input file with one extracted phrase per line:

Typ-2-Diabetes mit diabetischer Polyneuropathie
arterielle Hypertonie
chronische Niereninsuffizienz Stadium 3
Vorhofflimmern
Z. n. Myokardinfarkt
$ alpha-id suggest fall1.txt --mode c --chapters 4,9 --top 8
[5 segments, mode C, 1 ms, degraded=false]      # zero suggestions

$ alpha-id suggest fall1.txt --mode c --chapters E,I --top 8
[5 segments, mode C, 0 ms, degraded=false]      # zero suggestions

$ alpha-id suggest fall1.txt --mode c --chapters 04,09 --top 8
E11.40   ...   Diabetes mellitus, Typ 2 ...      # works
I10.90   ...   Essentielle Hypertonie ...

Root cause

  • The chapter tag is produced zero-padded: roman_to_padded formats
    the Arabic chapter number as format!("{n:02}"), yielding "01".."22"
    (src/claml.rs:17). JSON output confirms values like "04", "14".
  • The filter compares the raw command-line token to that value by exact
    string equality, with no normalization:
    if !ch.iter().any(|c| c == &t.chapter) (src/model.rs:51).
  • The command-line layer only splits on comma and trims, it does not
    pad: chapters.map(|c| c.split(',').map(|s| s.trim().to_string()).collect())
    (src/bin/alpha_id.rs).

So "4" != "04" and the entire candidate set is filtered out.

Two distinct defects

  • Input-format mismatch: un-padded numbers (4) and code letters (E)
    are the intuitive inputs but never match. Normalizing the filter
    input — pad bare 1-2 digit numbers to two digits, and/or map ICD code
    letters to their chapter number — would remove the trap.
  • Silent empty result: a --chapters value that cannot match any
    known chapter produces an empty list indistinguishable from "no
    clinical match". A warning on an unrecognized/never-matching chapter
    token would make the misuse visible.

Acceptance

  • --chapters 4 and --chapters 04 behave identically.
  • A --chapters token that matches no known chapter emits a warning to
    stderr rather than silently yielding zero results.
## Symptom The `--chapters` filter on `alpha-id suggest` silently returns zero results whenever the supplied value is not a two-digit zero-padded chapter number. The filter takes the value verbatim and compares it by exact string equality, so the natural inputs a user reaches for — `--chapters E,I` (code letters) or `--chapters 4,9` (un-padded numbers) — never match any candidate and the suggestion list comes back empty with no diagnostic. ## Reproduction Input file with one extracted phrase per line: ``` Typ-2-Diabetes mit diabetischer Polyneuropathie arterielle Hypertonie chronische Niereninsuffizienz Stadium 3 Vorhofflimmern Z. n. Myokardinfarkt ``` ``` $ alpha-id suggest fall1.txt --mode c --chapters 4,9 --top 8 [5 segments, mode C, 1 ms, degraded=false] # zero suggestions $ alpha-id suggest fall1.txt --mode c --chapters E,I --top 8 [5 segments, mode C, 0 ms, degraded=false] # zero suggestions $ alpha-id suggest fall1.txt --mode c --chapters 04,09 --top 8 E11.40 ... Diabetes mellitus, Typ 2 ... # works I10.90 ... Essentielle Hypertonie ... ``` ## Root cause - The chapter tag is produced zero-padded: `roman_to_padded` formats the Arabic chapter number as `format!("{n:02}")`, yielding "01".."22" (`src/claml.rs:17`). JSON output confirms values like "04", "14". - The filter compares the raw command-line token to that value by exact string equality, with no normalization: `if !ch.iter().any(|c| c == &t.chapter)` (`src/model.rs:51`). - The command-line layer only splits on comma and trims, it does not pad: `chapters.map(|c| c.split(',').map(|s| s.trim().to_string()).collect())` (`src/bin/alpha_id.rs`). So "4" != "04" and the entire candidate set is filtered out. ## Two distinct defects - [ ] Input-format mismatch: un-padded numbers (4) and code letters (E) are the intuitive inputs but never match. Normalizing the filter input — pad bare 1-2 digit numbers to two digits, and/or map ICD code letters to their chapter number — would remove the trap. - [ ] Silent empty result: a `--chapters` value that cannot match any known chapter produces an empty list indistinguishable from "no clinical match". A warning on an unrecognized/never-matching chapter token would make the misuse visible. ## Acceptance - `--chapters 4` and `--chapters 04` behave identically. - A `--chapters` token that matches no known chapter emits a warning to stderr rather than silently yielding zero results.
Brummel added the bug label 2026-05-31 17:58:59 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Brummel/alpha-id#1