src.dackar.RCA.ner.hybrid_ner.generators.gazetteer_generator¶
Classes¶
Configuration for gazetteer matching. |
|
Gazetteer-based candidate generator reading an Excel file of labeled term lists. |
Module Contents¶
- class src.dackar.RCA.ner.hybrid_ner.generators.gazetteer_generator.GazetteerConfig[source]¶
Configuration for gazetteer matching.
- match_mode:
“exact_phrase”: match whole phrase with word boundaries (case-insensitive)
“fuzzy_tokens”: slide a token window and match by token overlap (Jaccard)
- fuzzy_jaccard_threshold:
Minimum Jaccard similarity (0..1) to accept a fuzzy match.
- max_window_tokens:
Maximum tokens for sliding window when fuzzy matching is enabled.
- emit_overlapping:
If False, stops after the first fuzzy match for each term (reduces duplicates).
- class src.dackar.RCA.ner.hybrid_ner.generators.gazetteer_generator.GazetteerGenerator(excel_path, sheet_names=None, config=None)[source]¶
Bases:
src.dackar.RCA.ner.hybrid_ner.generators.base.CandidateGeneratorGazetteer-based candidate generator reading an Excel file of labeled term lists.
- Expected Excel convention:
Each sheet contains one or more columns of terms.
- Column header should contain the label in square brackets, e.g.:
“Degradation mechanisms [deg_mech]”
If brackets are missing, the entire header is treated as the label.
- For each term:
exact_phrase mode: compiled, case-insensitive word-boundary regex
fuzzy_tokens mode: approximate phrase matching by token overlap
Produces CandidateSpan with a LabelHypothesis(label=<label>).
- Parameters:
excel_path (str)
sheet_names (Optional[List[str]])
config (Optional[GazetteerConfig])
- _load_gazetteer(path, sheet_names)[source]¶
- Parameters:
path (str)
sheet_names (Optional[List[str]])
- Return type:
Dict[str, Set[str]]
- _compile_exact(label_terms)[source]¶
- Parameters:
label_terms (Dict[str, Set[str]])
- Return type:
List[Tuple[str, str, re.Pattern]]
- get_token_evidence(schema, min_len=3)[source]¶
Return role-aware token evidence derived from the gazetteer.
- Output schema:
- {
“exclusive_by_group”: { “G1_PHYSICAL_COMPONENT”: {tokens…}, “G4_MECHANISM_PROCESS”: {tokens…}, … }, “token_to_groups”: { “token”: {“G1_PHYSICAL_COMPONENT”,”G4_MECHANISM_PROCESS”,…}, … }
}
A token is exclusive to a group if it only appears in gazetteer terms whose labels map to that group. This is used downstream to reduce false multi-label acceptance.
- Parameters:
schema (SchemaIndex)
min_len (int)
- Return type:
dict