src.dackar.RCA.ner.hybrid_ner.generators.gazetteer_generator

Classes

GazetteerConfig

Configuration for gazetteer matching.

GazetteerGenerator

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

match_mode: str = 'exact_phrase'[source]
fuzzy_jaccard_threshold: float = 0.8[source]
max_window_tokens: int = 8[source]
emit_overlapping: bool = True[source]
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.CandidateGenerator

Gazetteer-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])

excel_path[source]
config[source]
label_terms[source]
_compiled_exact: List[Tuple[str, str, re.Pattern]] | None = None[source]
_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]]

_tokenize(text)[source]
Parameters:

text (str)

Return type:

List[Tuple[str, int, int]]

_term_tokens(term)[source]
Parameters:

term (str)

Return type:

List[str]

generate(doc)[source]
Parameters:

doc (src.dackar.RCA.ner.hybrid_ner.models.Document)

Return type:

List[src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan]

_generate_exact(doc)[source]
Parameters:

doc (src.dackar.RCA.ner.hybrid_ner.models.Document)

Return type:

List[src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan]

_generate_fuzzy(doc)[source]
Parameters:

doc (src.dackar.RCA.ner.hybrid_ner.models.Document)

Return type:

List[src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan]

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:
Return type:

dict