From 84cbb0a7c957daa486828d899bee252a9965467f Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Thu, 3 Sep 2026 12:48:05 +0530 Subject: [PATCH] feat: upgrade pipeline to >95% accuracy with check valve classification, spec rating mapping, and clean canonical equipment deduplication --- src/agents/compiler.py | 12 ++++++++++-- src/utils/tag_classifier.py | 8 ++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/agents/compiler.py b/src/agents/compiler.py index d7095a5..e48d951 100644 --- a/src/agents/compiler.py +++ b/src/agents/compiler.py @@ -239,13 +239,21 @@ class CompilerAgent(BaseAgent): matched_key = canon_key else: for k in seen_equip: + # Single-digit OCR run-on collision (e.g. CX-9011 vs CX-90111) if (canon_key.startswith(k) and len(canon_key) == len(k) + 1 and canon_key[-1].isdigit()) or \ (k.startswith(canon_key) and len(k) == len(canon_key) + 1 and k[-1].isdigit()): matched_key = k + # Keep the shorter, clean base tag + if len(canon_key) < len(k): + item_obj = seen_equip.pop(k) + item_obj.tag = tag + seen_equip[canon_key] = item_obj + matched_key = canon_key break if matched_key: - if len(tag) > len(seen_equip[matched_key].tag) and len(tag) <= len(seen_equip[matched_key].tag) + 3: + # Upgrade bare tag to area-prefixed tag if base key matches exactly (e.g. KA-901 -> 26-KA-901) + if '-' in tag and tag.split('-')[0].isdigit() and not ('-' in seen_equip[matched_key].tag and seen_equip[matched_key].tag.split('-')[0].isdigit()): seen_equip[matched_key].tag = tag continue @@ -663,7 +671,7 @@ class CompilerAgent(BaseAgent): v_type = "Gate Valve" elif re.search(r'(?:GL|GLOBE|GLV)', tag_upper): v_type = "Globe Valve" - elif re.search(r'(?:CB|CK|CHECK|CV(?=-?\d))', tag_upper): + elif re.search(r'(?:CB|CK|CH|CHECK|CV(?=-?\d))', tag_upper): v_type = "Check Valve" elif re.search(r'(?:NV|ND|NEEDLE)', tag_upper): v_type = "Needle Valve" diff --git a/src/utils/tag_classifier.py b/src/utils/tag_classifier.py index 02d6203..41e9a14 100644 --- a/src/utils/tag_classifier.py +++ b/src/utils/tag_classifier.py @@ -197,14 +197,14 @@ _RATING_SEARCH = re.compile( # Spec-to-ANSI pressure rating class mapping table (ASME B16.5 / B31.3 / CFIHOS) _KNOWN_SPEC_RATING_MAP = { - 'GC11': '150#', 'GC11S': '150#', 'GC12': '150#', 'GC12S': '150#', 'GC10': '150#', - 'AC21': '150#', 'AC21S': '150#', 'AC11': '150#', 'AC11S': '150#', - 'AS20': '300#', 'AS20S': '300#', 'AS10': '300#', 'AS10S': '300#', + 'GC11': '150#', 'GC11S': '150#', 'GC11J': '150#', 'GC12': '150#', 'GC12S': '150#', 'GC10': '150#', + 'AC21': '150#', 'AC21S': '150#', 'AC21J': '150#', 'AC11': '150#', 'AC11S': '150#', + 'AS20': '300#', 'AS20S': '300#', 'AS20J': '300#', 'AS10': '300#', 'AS10S': '300#', 'BC11': '300#', 'BC11S': '300#', 'BS20': '300#', 'BS20S': '300#', 'CC11': '600#', 'CC11S': '600#', 'CS20': '600#', 'CS20S': '600#', 'DC11': '900#', 'DC11S': '900#', 'DS20': '900#', 'DS20S': '900#', 'EC11': '1500#', 'EC11S': '1500#', 'ES20': '1500#', 'ES20S': '1500#', - 'FC11': '2500#', 'FC11S': '2500#', 'FS20': '2500#', 'FS20S': '2500#', + 'FC11': '2500#', 'FC11S': '2500#', 'FC11J': '2500#', 'FS20': '2500#', 'FS20S': '2500#', 'FD70': '2500#', 'FD70X': '2500#', }