Skip to content

NLP Phase 1+2: glossary+negation; acronym resolver; DB seeds; flags & tests#6

Open
BrianNgann wants to merge 5 commits into
mainfrom
sprint-2-db
Open

NLP Phase 1+2: glossary+negation; acronym resolver; DB seeds; flags & tests#6
BrianNgann wants to merge 5 commits into
mainfrom
sprint-2-db

Conversation

@BrianNgann

Copy link
Copy Markdown
Collaborator

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/.

_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
regular expression
that depends on a
user-provided value
may run slow on strings with many repetitions of '!'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants