src.dackar.RCA.ner.spacy_annotator¶
spacy_annotator.py ────────────────────────────────────────────────────────────────────────────── Thin wrapper that runs the six plant-specific spaCy pipeline components (Temporal, TemporalRelation, TemporalAttribute, Location, Conjecture, Unit) on arbitrary text and returns a structured SpacyAnnotationResult.
- Used in two tiers of the RCA workflow:
Tier 1 (indexing) — called from ner_adapter to enrich NERSeed Tier 2 (scoring) — injected into ChromaEvidenceRetriever to annotate
each retrieved snippet inside _assess_hit_against_candidate
Attributes¶
Classes¶
Structured output from SpacyAnnotator.annotate(). |
|
One-time-initialised wrapper for the six plant-specific spaCy components. |
Functions¶
|
Return the first parseable duration in hours from a list of temporal ref texts. |
|
Factory function — initialise a |
Module Contents¶
- src.dackar.RCA.ner.spacy_annotator._parse_lag_hours(texts)[source]¶
Return the first parseable duration in hours from a list of temporal ref texts.
Returns None if no duration pattern is found.
- Parameters:
texts (List[str])
- Return type:
Optional[float]
- class src.dackar.RCA.ner.spacy_annotator.SpacyAnnotationResult[source]¶
Structured output from SpacyAnnotator.annotate().
- measurements: List[Dict[str, Any]] = [][source]¶
{value, unit, entity_type, text}.
- Type:
Physical measurements
- temporal_refs: List[str] = [][source]¶
‘March 14 2025’, ‘48 hours’.
- Type:
Absolute dates and durations
- temporal_relations: List[Dict[str, str]] = [][source]¶
{text, sub_label} where sub_label is one of temporal_relation_order | temporal_relation_reverse_order | temporal_relation_concurrency.
- Type:
Ordering words
- temporal_qualifiers: List[str] = [][source]¶
‘approximately’, ‘roughly’.
- Type:
Fuzzy temporal qualifiers
- locations: List[Dict[str, str]] = [][source]¶
{text, sub_label} where sub_label is one of location_proximity | location_up | location_down.
- Type:
Spatial terms
- conjectures: List[str] = [][source]¶
‘possibly’, ‘likely’, ‘suspected’.
- Type:
Epistemic hedge markers
- lag_hours: float | None = None[source]¶
First parseable duration from temporal_refs, converted to hours.
- lag_is_approximate: bool = False[source]¶
True when temporal_qualifiers are present alongside a lag_hours value.
- class src.dackar.RCA.ner.spacy_annotator.SpacyAnnotator(nlp_model='en_core_web_sm')[source]¶
One-time-initialised wrapper for the six plant-specific spaCy components.
Instantiate once per process (model load + pipe setup are expensive) and share the same instance across Tier 1 (ner_adapter) and Tier 2 (evidence_retriever).
- Parameters:
nlp_model (str) – spaCy model name. Must include an NER component so that TemporalEntity’s Matcher patterns that rely on ENT_TYPE DATE/TIME fire correctly. Defaults to ‘en_core_web_sm’.
- annotate(text)[source]¶
Run all six components on text and return a structured result.
- Parameters:
text (str) – Arbitrary chunk or snippet text.
- Returns:
SpacyAnnotationResultwith all signal buckets populated.- Return type:
- src.dackar.RCA.ner.spacy_annotator.build_spacy_annotator(nlp_model='en_core_web_sm')[source]¶
Factory function — initialise a
SpacyAnnotatorand return it.Centralises model selection so callers don’t need to import SpacyAnnotator directly.
- Parameters:
nlp_model (str) – spaCy model name (default: ‘en_core_web_sm’).
- Returns:
Configured and ready
SpacyAnnotatorinstance.- Return type: