src.dackar.RCA.ner.hybrid_ner.compatibility

Classes

CompatibilityResult

Output of compatibility application:

CompatibilityEngine

Applies label-group compatibility and conditional rules from group-schema.json.

Module Contents

class src.dackar.RCA.ner.hybrid_ner.compatibility.CompatibilityResult[source]
Output of compatibility application:
  • updated_candidates: candidates with group annotations on hypotheses

  • decisions: decisions per candidate (accept/reject/defer/split)

  • relation_proposals: optional (v0.3 mostly empty)

updated_candidates: List[src.dackar.RCA.ner.hybrid_ner.models.CandidateSpan][source]
decisions: List[src.dackar.RCA.ner.hybrid_ner.models.Decision][source]
relation_proposals: List[src.dackar.RCA.ner.hybrid_ner.models.RelationProposal][source]
class src.dackar.RCA.ner.hybrid_ner.compatibility.CompatibilityEngine(context_left=80, context_right=80)[source]

Applies label-group compatibility and conditional rules from group-schema.json.

Upgrades:
  • Conditional triggers:
    • cue_phrases_any / event_cues_any searched in context and sentence window

    • pattern_templates supported with placeholder expansion (<MECH>, <OUTCOME>, <PHYS>, <MAT>)

  • Split heuristic for G1_PHYSICAL + G6_OUTCOMES_OCCURRENCES compounds (R2 policy)

Still enforced:
  • one label per group per span (best score retained)

  • multi-label allowed only if matrix says ‘A’ OR conditional rule allows it

Parameters:
  • context_left (int)

  • context_right (int)

context_left = 80[source]
context_right = 80[source]
assign_groups(candidates, schema)[source]
Parameters:
Return type:

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

apply(doc, candidates, schema)[source]
Parameters:
Return type:

CompatibilityResult

resolve_span(doc, cand, schema)[source]

Resolve one candidate span into an accept/defer decision.

Policy (current): - Pick the best label per group (by score). - If multiple groups remain:

  • If same-span multi-label is not whitelisted -> reduce to single best label.

  • If whitelisted (currently {G1_PHYSICAL_COMPONENT, G4_MECHANISM_PROCESS}) -> require token evidence

    for BOTH roles using exclusive tokens (role-aware), else try conditional rules / split; if none apply -> reduce to single best label.

  • For other multi-group cases, consult conditional rules; if still not allowed -> reduce to single best label.

This intentionally prefers trustworthy output over forced collapse. When ambiguity remains material, defer instead of inventing certainty.

Parameters:
Return type:

Tuple[src.dackar.RCA.ner.hybrid_ner.models.Decision, List[src.dackar.RCA.ner.hybrid_ner.models.RelationProposal]]

_allowed_same_span(groups)[source]

Return True iff same-span multi-labeling is allowed for these groups.

Conservative whitelist: only allow the pair {G1_PHYSICAL_COMPONENT, G4_MECHANISM_PROCESS}. (Change this if you want to allow additional group-pairs.)

Parameters:

groups (list)

Return type:

bool

_try_split_physical_outcome(doc, cand, selected)[source]
Parameters:
Return type:

src.dackar.RCA.ner.hybrid_ner.models.Decision | None

_multilabel_allowed_with_rules(doc, cand, groups, schema)[source]
Parameters:
Return type:

Tuple[bool, List[str]]

_conditional_allows(doc, cand, g1, g2, schema)[source]
Parameters:
Return type:

Tuple[bool, str | None]

_match_template(template, text)[source]
Parameters:
  • template (str)

  • text (str)

Return type:

bool

static _context_window(text, start, end, left, right)[source]
Parameters:
  • text (str)

  • start (int)

  • end (int)

  • left (int)

  • right (int)

Return type:

str

static _sentence_window(text, start, end)[source]
Parameters:
  • text (str)

  • start (int)

  • end (int)

Return type:

str