src.dackar.RCA.ner.alarm_id_extractor

alarm_id_extractor.py ───────────────────────────────────────────────────────────────────────────── Extract alarm and annunciator IDs from nuclear plant text (ALM, ANN, process tags, SCRAM/SI/AFAS setpoint conditions, etc.).

Plant-specific flexibility ────────────────────────── Like doc_ref_extractor.py, this module is driven by the same JSON plant profile (see ner/data/plant_profiles/default_plant_profile.json). Alarm patterns live in the alarm_patterns array; each entry has a name, pattern (regex string), and score (0–1 confidence).

False-positive filtering uses the false_positive_filters.excluded_prefixes_from_alarm list from the same profile, so document-reference prefixes (CR, WO, …) are never returned as alarm IDs.

Output ────── Each extracted alarm reference is an AlarmRef namedtuple:

pattern_name - stable pattern identifier (e.g. “short_alarm_id”) raw - original matched text (before normalization) norm - normalized ID (uppercase, collapsed separators) score - pattern confidence score (0–1) from the plant profile

Classes

AlarmRef

A single extracted alarm or annunciator reference.

Functions

_compile_alarm_profile(profile)

Return list of (pattern_name, score, compiled_pattern) from profile.

_make_alarm_fp_checker(profile)

Return a callable that returns True when a norm is a false positive

_normalize_alarm_ref(raw)

Return a canonical alarm reference string.

extract_alarm_refs(text, *[, profile_path, profile, ...])

Extract alarm and annunciator IDs from text.

extract_alarm_ref_ids(text, **kwargs)

Convenience wrapper — returns only the normalised alarm ID strings.

Module Contents

class src.dackar.RCA.ner.alarm_id_extractor.AlarmRef[source]

Bases: NamedTuple

A single extracted alarm or annunciator reference.

pattern_name: str[source]
raw: str[source]
norm: str[source]
score: float[source]
src.dackar.RCA.ner.alarm_id_extractor._compile_alarm_profile(profile)[source]

Return list of (pattern_name, score, compiled_pattern) from profile.

Patterns are compiled case-insensitively.

Parameters:

profile (Dict)

Return type:

List[tuple]

src.dackar.RCA.ner.alarm_id_extractor._make_alarm_fp_checker(profile)[source]

Return a callable that returns True when a norm is a false positive alarm ID and should be dropped.

Parameters:

profile (Dict)

src.dackar.RCA.ner.alarm_id_extractor._normalize_alarm_ref(raw)[source]

Return a canonical alarm reference string.

  • Uppercase

  • Collapse any internal whitespace to a single hyphen

  • Collapse multiple consecutive hyphens

  • Strip leading/trailing punctuation

Parameters:

raw (str)

Return type:

str

src.dackar.RCA.ner.alarm_id_extractor.extract_alarm_refs(text, *, profile_path=None, profile=None, normalize=True, unique=True, max_ids=200, min_score=0.0)[source]

Extract alarm and annunciator IDs from text.

Parameters:
  • text (str) – Arbitrary chunk or document text.

  • profile_path (Optional[str | pathlib.Path]) – Path to a plant profile JSON override. Ignored when profile is supplied directly.

  • profile (Optional[Dict]) – Pre-loaded plant profile dict (takes priority over profile_path). Pass this when calling the function many times on the same plant to avoid repeated file I/O.

  • normalize (bool) – Normalize matched IDs (uppercase, canonical hyphens).

  • unique (bool) – Return each normalised ID at most once (keeps highest-score pattern hit when the same norm is matched by multiple patterns).

  • max_ids (int) – Safety cap on the number of refs returned.

  • min_score (float) – Drop any match whose pattern score is below this threshold.

Returns:

List of AlarmRef namedtuples in match order.

Return type:

List[AlarmRef]

src.dackar.RCA.ner.alarm_id_extractor.extract_alarm_ref_ids(text, **kwargs)[source]

Convenience wrapper — returns only the normalised alarm ID strings.

Suitable for direct assignment to NERSeed.alarm_ids.

Parameters:
Returns:

List of normalised alarm reference strings.

Return type:

List[str]