NLP Phase 1+2: glossary+negation; acronym resolver; DB seeds; flags & tests#6
Open
BrianNgann wants to merge 5 commits into
Open
NLP Phase 1+2: glossary+negation; acronym resolver; DB seeds; flags & tests#6BrianNgann wants to merge 5 commits into
BrianNgann wants to merge 5 commits into
Conversation
…; NER behind USE_NER; CSV seeds cleaned
…eds cleanup; flags & tests
| _VOWELS = set("aeiouy") | ||
|
|
||
| def _count_sentences(text: str) -> int: | ||
| s = [m.group(0) for m in _SENT_SPLIT.finditer(text)] |
Check failure
Code scanning / CodeQL
Polynomial regular expression used on uncontrolled data High
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This PR wires up the first two NLP phases for /api/v1/detect:
Phase 1: DB-backed glossary detection + negation check (simple cue window).
Phase 2: Acronym resolver with doc-local memory. Learns (Longform (ACR)) mappings in one note and applies to later mentions in the same doc_uuid.
Also included:
Seed CSVs for glossary, acronyms, and units.
Optional NER augmentation (scispaCy) behind a feature flag.
Small test scaffold and readability helpers for future phases.
What changed:
app/routes/detect.py:
Hybrid detector (glossary → acronym resolution → optional NER) with overlap rules.
Accepts optional doc_uuid to persist acronym choices per document.
app/nlp/detect/*:
negation.py: lightweight cue-based check (“no”, “denies”, “without”…).
acronym_resolver.py: extracts parenthetical ACR↔longform, persists choices, injects later ACR spans.
spacy_ner.py: optional scispaCy NER spans (guarded by USE_NER).
app/db/*:
models.py, repo.py: schema + helpers; CLI to init/seed DB and print the alias map.
Seed CSVs: app/data/glossary_seed.csv, app/data/acronyms_seed.csv, app/data/units_seed.csv.
app/schemas/detect.py: DetectRequest accepts optional doc_uuid.
Flags + minor infra tweaks; test scaffold added under app/tests/.