Skip to content

Commit 0519e93

Browse files
committed
ner.fast tests
1 parent efe6193 commit 0519e93

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: uv python install 3.12
2020

2121
- name: Install dependencies
22-
run: uv sync --dev
22+
run: uv sync --dev --extra fast --extra dataframe
2323

2424
- name: Lint
2525
run: uv run ruff check structflo/ tests/

structflo/ner/fast/_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import re
77
from pathlib import Path
88

9-
import yaml
10-
119
from structflo.ner._entities import _ENTITY_CLASS_MAP
1210

1311
logger = logging.getLogger(__name__)
@@ -41,6 +39,8 @@ def load_gazetteer(path: Path) -> tuple[str, list[str]]:
4139
Tuple of (entity_type, list_of_terms) where entity_type is derived
4240
from the filename stem.
4341
"""
42+
import yaml # noqa: PLC0415
43+
4444
entity_type = path.stem
4545
with open(path) as f:
4646
terms = yaml.safe_load(f)

structflo/ner/fast/_matcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import re
66
from dataclasses import dataclass
77

8-
from rapidfuzz import fuzz
9-
108
from structflo.ner.fast._normalize import expand_variants, normalize
119

1210

@@ -180,6 +178,8 @@ def _regex_match(self, text: str, occupied: set[int]) -> list[Match]:
180178

181179
def _fuzzy_match(self, text: str, occupied: set[int]) -> list[Match]:
182180
"""Phase 2: Fuzzy matching on unmatched tokens."""
181+
from rapidfuzz import fuzz # noqa: PLC0415
182+
183183
matches: list[Match] = []
184184

185185
for token_match in _TOKEN_RE.finditer(text):

tests/test_fast.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
import pytest
99

10-
from structflo.ner._entities import (
10+
pytest.importorskip("rapidfuzz", reason="rapidfuzz required for fast NER tests")
11+
pytest.importorskip("yaml", reason="PyYAML required for fast NER tests")
12+
13+
from structflo.ner._entities import ( # noqa: E402
1114
AccessionEntity,
1215
ChemicalEntity,
1316
DiseaseEntity,

0 commit comments

Comments
 (0)