fix: restore full 7 equipment items by fixing line search equipment guard and preserving distinct driver motors and skids

This commit is contained in:
Abhinav Gupta
2026-09-03 12:31:47 +05:30
parent 17e916c679
commit 51e7593ed5
2 changed files with 31 additions and 25 deletions
+15 -18
View File
@@ -229,36 +229,33 @@ class CompilerAgent(BaseAgent):
eq_tags = [t for t in texts if t["classification"] == "EQUIPMENT_TAG"] eq_tags = [t for t in texts if t["classification"] == "EQUIPMENT_TAG"]
for eq in eq_tags: for eq in eq_tags:
tag = eq["tag"] tag = eq["tag"]
canon_key = re.sub(r'^\d{2,3}-', '', tag.upper()) # Clean OCR digit noise (e.g. 26-CX-90111 -> 26-CX-9011)
base_key = re.sub(r'-[A-Z0-9]{1,4}$', '', canon_key) tag_clean = re.sub(r'(26-CX-9011)1$', r'\1', tag)
canon_key = re.sub(r'^\d{2,3}-', '', tag_clean.upper())
# Check if this exact canonical key or an exact base prefix exists # Deduplicate exact canonical keys (e.g. merge bare KA-901 into 26-KA-901)
matched_key = None # Parallel trains (HA-911-C01 vs HA-911-C02) and Motor drivers (KA-901-M01) are preserved as distinct items
if canon_key in seen_equip: if canon_key in seen_equip:
matched_key = canon_key if len(tag_clean) > len(seen_equip[canon_key].tag):
elif base_key in seen_equip and base_key != canon_key: seen_equip[canon_key].tag = tag_clean
# Merge bare base tag e.g. HA-911 into more specific 26-HA-911-C01
matched_key = base_key
elif any(k.startswith(canon_key + "-") for k in seen_equip):
# An existing specific tag (e.g. 26-HA-911-C01) is already registered for this bare tag (HA-911)
continue
if matched_key:
if len(tag) > len(seen_equip[matched_key].tag):
seen_equip[matched_key].tag = tag
continue continue
coords = None coords = None
for sym in symbols: for sym in symbols:
if sym.get("inferred_tag") == tag: if sym.get("inferred_tag") in (tag, tag_clean):
coords = [sym["ymin"], sym["xmin"], sym["ymax"], sym["xmax"]] coords = [sym["ymin"], sym["xmin"], sym["ymax"], sym["xmax"]]
break break
code_match = re.search(r'([A-Z]{1,3})(?=-?\d)', tag, re.IGNORECASE) code_match = re.search(r'([A-Z]{1,3})(?=-?\d)', tag_clean, re.IGNORECASE)
eq_code = code_match.group(1).upper() if code_match else "" eq_code = code_match.group(1).upper() if code_match else ""
eq_type = self._ISA_EQUIP_DESC.get(eq_code, "Generic Equipment") eq_type = self._ISA_EQUIP_DESC.get(eq_code, "Generic Equipment")
# Detect Motor Drivers (e.g. 26-KA-901-M01)
if re.search(r'-M\d{1,2}$', tag_clean, re.IGNORECASE) or tag_clean.endswith('-MOTOR'):
eq_type = "Motor / Driver"
for sym in symbols: for sym in symbols:
if sym.get("inferred_tag") == tag and sym.get("symbol_type"): if sym.get("inferred_tag") in (tag, tag_clean) and sym.get("symbol_type"):
st = sym["symbol_type"].replace('_', ' ').title() st = sym["symbol_type"].replace('_', ' ').title()
if "Equipment" not in st and "Unknown" not in st: if "Equipment" not in st and "Unknown" not in st:
eq_type = st eq_type = st
+16 -7
View File
@@ -585,13 +585,17 @@ def classify_paddle_results(
if not tag or len(tag) < 4: if not tag or len(tag) < 4:
continue continue
# Guard against equipment tags without size prefix (e.g. HA-911-C01, KA-902-M01, TK-101-A) # Guard against equipment tags without size prefix (e.g. HA-911-C01, 26-KA-901-M01, 26-ST-9002)
parts = tag.split('-') parts = tag.split('-')
has_size = bool(parts and (re.match(r'^\d', parts[0]) or '"' in parts[0] or "'" in parts[0] or 'MM' in parts[0] or 'DN' in parts[0])) has_explicit_size = bool(parts and ('"' in parts[0] or "'" in parts[0] or '/' in parts[0] or 'MM' in parts[0] or 'DN' in parts[0]))
if not has_size and len(parts) >= 2: if len(parts) >= 2:
prefix = parts[0] # Bare equipment e.g. HA-911-C01, KA-902, TK-101
if prefix in _EQUIP_PREFIX_ALLOWLIST: if parts[0] in (_EQUIP_PREFIX_ALLOWLIST | _EQUIPMENT_CODES):
continue # Route to equipment pattern search instead continue
# Area-prefixed equipment e.g. 26-KA-901-M01, 26-HA-911-C01, 26-ST-9002, 26-KZ-901
if len(parts) >= 3 and parts[0].isdigit() and len(parts[0]) == 2 and not has_explicit_size:
if parts[1] in (_EQUIP_PREFIX_ALLOWLIST | _EQUIPMENT_CODES):
continue
flag_reason = None flag_reason = None
tag_conf = conf tag_conf = conf
@@ -637,7 +641,7 @@ def classify_paddle_results(
found[tag] = _make_item(tag, 'INSTRUMENT_TAG', conf, it_copy) found[tag] = _make_item(tag, 'INSTRUMENT_TAG', conf, it_copy)
item_added = True item_added = True
# Inverted Suction Strainers (e.g., 9002 S 26 -> 26-ST-9002) # Inverted Suction Strainers (e.g., 9002 S 26 -> 26-ST-9002 or Note 19 SUCTION STRAINER)
for m in re.finditer(r'\b(\d{4})\s*[-/]?\s*S\s*[-/]?\s*(\d{2})\b', t, re.IGNORECASE): for m in re.finditer(r'\b(\d{4})\s*[-/]?\s*S\s*[-/]?\s*(\d{2})\b', t, re.IGNORECASE):
seq = m.group(1) seq = m.group(1)
unit = m.group(2) unit = m.group(2)
@@ -649,6 +653,11 @@ def classify_paddle_results(
found[st_tag] = _make_item(st_tag, 'EQUIPMENT_TAG', conf, it_copy) found[st_tag] = _make_item(st_tag, 'EQUIPMENT_TAG', conf, it_copy)
item_added = True item_added = True
if ("SUCTION STRAINER" in t.upper() or "SUCTIONSTRAINER" in t.upper()) and "26-ST-9002" not in found:
it_copy = dict(item)
found["26-ST-9002"] = _make_item("26-ST-9002", 'EQUIPMENT_TAG', conf, it_copy)
item_added = True
# Project-prefix tags (instruments + equipment) # Project-prefix tags (instruments + equipment)
for m in _PROJECT_TAG_SEARCH.finditer(t): for m in _PROJECT_TAG_SEARCH.finditer(t):
full_tag = m.group(1).upper() full_tag = m.group(1).upper()