Skip to content

Commit f8bd6d3

Browse files
committed
fix: make use of fuzzy flag
1 parent 5d97898 commit f8bd6d3

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/strings2things/app/core/rdf_transformer.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ def __init__(self, label_map: dict[str, str], fuzzy: bool, fuzzy_threshold: int
2323
def _find_match(self, label: str) -> str | None:
2424
"""
2525
Find an IRI for the given label.
26-
First tries exact match, then falls back to fuzzy.
26+
First tries exact match, then (optionally) falls back to fuzzy.
2727
"""
2828
label = label.strip().lower()
2929

30-
# Exact match
31-
if label in self.label_map:
32-
return self.label_map[label]
30+
# Exact match first (cheap lookup)
31+
iri = self.label_map.get(label)
32+
if iri:
33+
return iri
3334

3435
# Fuzzy fallback
35-
best = process.extractOne(label, self.label_map.keys())
36-
if best:
37-
match, score, _ = best
38-
if score >= self.fuzzy_threshold:
39-
return self.label_map[match]
36+
if self.fuzzy:
37+
best = process.extractOne(label, self.label_map.keys())
38+
if best:
39+
match, score, _ = best
40+
if score >= self.fuzzy_threshold:
41+
return self.label_map[match]
4042

4143
return None
4244

45+
4346
def transform(self, input_graph: Graph) -> Graph:
4447
"""
4548
Replace matching string literals in the RDF graph with IRIs.

0 commit comments

Comments
 (0)