jin2li commited on
Commit
e97f1c4
ยท
verified ยท
1 Parent(s): 8339ec9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +227 -0
app.py CHANGED
@@ -529,6 +529,209 @@ def is_broad_lookup_term(term):
529
 
530
 
531
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
  def build_chemical_name_variants(term):
533
  """
534
  ํ™”ํ•™๋ช… ํ‘œ๊ธฐ ์ฐจ์ด ๋ณด์ •์šฉ alias ์ƒ์„ฑ.
@@ -729,6 +932,10 @@ def build_ingredient_lookup_terms(material=None, component=None, extra_terms=Non
729
  if safe_str(v):
730
  raw_terms.append(safe_str(v))
731
 
 
 
 
 
732
  expanded = []
733
  strong_abbrev_allowlist = {"EDTA", "BHT", "BHA", "MEA", "DEA", "TEA", "D4", "D5", "D6", "PFAS", "PFOA", "PFOS"}
734
  salt_prefixes = [
@@ -2695,6 +2902,16 @@ def evaluate_component_from_country_files_only(country, material, component, tar
2695
  )
2696
 
2697
  if not matches:
 
 
 
 
 
 
 
 
 
 
2698
  alias_result = find_chemical_variant_match_in_country_text(
2699
  country=country,
2700
  material=material,
@@ -2740,6 +2957,16 @@ def evaluate_component_from_country_files_only(country, material, component, tar
2740
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2741
  "๋น„๊ณ ": "๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ๋„“์€ ๊ฒ€์ƒ‰์–ด๋งŒ ๋งค์นญ๋˜์–ด ์˜คํƒ์œผ๋กœ ์ œ์™ธ",
2742
  }
 
 
 
 
 
 
 
 
 
 
2743
  log_search_context(
2744
  target_id,
2745
  country,
 
529
 
530
 
531
 
532
+
533
+ # ============================================================
534
+ # ๊ทœ์ œ ๋™์˜์–ด / CAS / ์ด์„ฑ์งˆ์ฒด ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ
535
+ # - ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ํ‘œ๊ธฐ๊ฐ€ INCI์™€ ๋‹ค๋ฅผ ๋•Œ PASS ์˜คํŒ์„ ๋ง‰๊ธฐ ์œ„ํ•œ ๋ณด์ •์ธต
536
+ # - ๋‹จ์ผ ์„ฑ๋ถ„๊ณผ ์ „์„ฑ๋ถ„ ๋ชจ๋‘ ๋™์ผํ•˜๊ฒŒ ์‚ฌ์šฉ
537
+ # ============================================================
538
+
539
+ REGULATORY_SYNONYM_REGISTRY = [
540
+ {
541
+ "key": "dichlorobenzene",
542
+ "canonical": "Dichlorobenzene",
543
+ "terms": [
544
+ "dichlorobenzene",
545
+ "dichlorobenzenes",
546
+ "Dichlorobenzene",
547
+ "Dichlorobenzenes",
548
+ "106-46-7",
549
+ "95-50-1",
550
+ "541-73-1",
551
+ "1,2-dichlorobenzene",
552
+ "1,3-dichlorobenzene",
553
+ "1,4-dichlorobenzene",
554
+ "o-dichlorobenzene",
555
+ "m-dichlorobenzene",
556
+ "p-dichlorobenzene",
557
+ "ortho-dichlorobenzene",
558
+ "meta-dichlorobenzene",
559
+ "para-dichlorobenzene",
560
+ "1,2-Dichlorobenzene",
561
+ "1,3-Dichlorobenzene",
562
+ "1,4-Dichlorobenzene",
563
+ "o-Dichlorobenzene",
564
+ "m-Dichlorobenzene",
565
+ "p-Dichlorobenzene",
566
+ "1,2-๋””ํด๋กœ๋กœ๋ฒค์  ",
567
+ "1,3-๋””ํด๋กœ๋กœ๋ฒค์  ",
568
+ "1,4-๋””ํด๋กœ๋กœ๋ฒค์  ",
569
+ "o-๋””ํด๋กœ๋กœ๋ฒค์  ",
570
+ "m-๋””ํด๋กœ๋กœ๋ฒค์  ",
571
+ "p-๋””ํด๋กœ๋กœ๋ฒค์  ",
572
+ "๋””ํด๋กœ๋กœ๋ฒค์  ",
573
+ "๋‹ค์ดํด๋กœ๋กœ๋ฒค์  ",
574
+ ],
575
+ },
576
+ {
577
+ "key": "trichlorobenzene",
578
+ "canonical": "Trichlorobenzene",
579
+ "terms": [
580
+ "trichlorobenzene",
581
+ "trichlorobenzenes",
582
+ "Trichlorobenzene",
583
+ "Trichlorobenzenes",
584
+ "120-82-1",
585
+ "87-61-6",
586
+ "108-70-3",
587
+ "1,2,3-trichlorobenzene",
588
+ "1,2,4-trichlorobenzene",
589
+ "1,3,5-trichlorobenzene",
590
+ "1,2,3-Trichlorobenzene",
591
+ "1,2,4-Trichlorobenzene",
592
+ "1,3,5-Trichlorobenzene",
593
+ "1,2,3-ํŠธ๋ฆฌํด๋กœ๋กœ๋ฒค์  ",
594
+ "1,2,4-ํŠธ๋ฆฌํด๋กœ๋กœ๋ฒค์  ",
595
+ "1,3,5-ํŠธ๋ฆฌํด๋กœ๋กœ๋ฒค์  ",
596
+ "ํŠธ๋ฆฌํด๋กœ๋กœ๋ฒค์  ",
597
+ ],
598
+ },
599
+ {
600
+ "key": "tetrachlorobenzene",
601
+ "canonical": "Tetrachlorobenzene",
602
+ "terms": [
603
+ "tetrachlorobenzene",
604
+ "tetrachlorobenzenes",
605
+ "Tetrachlorobenzene",
606
+ "Tetrachlorobenzenes",
607
+ "634-66-2",
608
+ "634-90-2",
609
+ "95-94-3",
610
+ "1,2,3,4-tetrachlorobenzene",
611
+ "1,2,3,5-tetrachlorobenzene",
612
+ "1,2,4,5-tetrachlorobenzene",
613
+ "1,2,3,4-Tetrachlorobenzene",
614
+ "1,2,3,5-Tetrachlorobenzene",
615
+ "1,2,4,5-Tetrachlorobenzene",
616
+ "1,2,3,4-ํ…ŒํŠธ๋ผํด๋กœ๋กœ๋ฒค์  ",
617
+ "1,2,3,5-ํ…ŒํŠธ๋ผํด๋กœ๋กœ๋ฒค์  ",
618
+ "1,2,4,5-ํ…ŒํŠธ๋ผํด๋กœ๋กœ๋ฒค์  ",
619
+ "ํ…ŒํŠธ๋ผํด๋กœ๋กœ๋ฒค์  ",
620
+ ],
621
+ },
622
+ ]
623
+
624
+
625
+ def registry_terms_for_component(material=None, component=None, extra_terms=None):
626
+ material = material or {}
627
+ component = component or {}
628
+
629
+ identity_values = [
630
+ component.get("INCI Name", ""),
631
+ component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""),
632
+ component.get("CAS.No", ""),
633
+ material.get("Trade name(๊ตญ๋ฌธ)", ""),
634
+ material.get("Trade name(์˜๋ฌธ)", ""),
635
+ ] + list(extra_terms or [])
636
+
637
+ identity_norm = normalize_compact(" ".join(safe_str(x) for x in identity_values if safe_str(x)))
638
+
639
+ hits = []
640
+
641
+ for entry in REGULATORY_SYNONYM_REGISTRY:
642
+ terms = entry.get("terms", [])
643
+ term_norms = [normalize_compact(t) for t in terms if safe_str(t)]
644
+
645
+ if any(tn and tn in identity_norm for tn in term_norms):
646
+ for t in terms:
647
+ if safe_str(t) and t not in hits:
648
+ hits.append(safe_str(t))
649
+
650
+ return hits
651
+
652
+
653
+ def registry_direct_regulation_fallback(country, material, component, target_id=""):
654
+ """
655
+ ์ผ๋ฐ˜ ๊ฒ€์ƒ‰/ํ™”ํ•™๋ช… alias ๊ฒ€์ƒ‰์ด ์‹คํŒจํ–ˆ์„ ๋•Œ,
656
+ registry์˜ CAS/๋™์˜์–ด/์ด์„ฑ์งˆ์ฒด๋ช…์œผ๋กœ ๊ตญ๊ฐ€ ํŒŒ์ผ ์›๋ฌธ์„ ๋‹ค์‹œ ๊ฒ€์ƒ‰ํ•œ๋‹ค.
657
+ """
658
+ registry_terms = registry_terms_for_component(material=material, component=component)
659
+
660
+ if not registry_terms:
661
+ return None
662
+
663
+ sections, status = get_country_section_index_cached(country)
664
+ country_col = display_country(country)
665
+ representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", "")) or registry_terms[0]
666
+
667
+ registry_norms = [
668
+ normalize_compact(t)
669
+ for t in registry_terms
670
+ if safe_str(t) and len(normalize_compact(t)) >= 3
671
+ ]
672
+
673
+ for section in sections:
674
+ text = safe_str(section.get("text", ""))
675
+ text_norm = normalize_compact(text)
676
+
677
+ if not any(tn in text_norm for tn in registry_norms):
678
+ continue
679
+
680
+ header = safe_str(section.get("header", ""))
681
+ reg_type = infer_regulation_type_from_source_text(header + "\n" + text[:2000], country=country)
682
+ reg_kind = reg_type.get("type", "unknown")
683
+ reg_label = reg_type.get("label", "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜")
684
+
685
+ lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
686
+ context_lines = []
687
+ seen = set()
688
+
689
+ for idx, line in enumerate(lines):
690
+ ln = normalize_compact(line)
691
+ if any(tn in ln for tn in registry_norms):
692
+ for j in range(max(0, idx - 5), min(len(lines), idx + 6)):
693
+ if j not in seen:
694
+ seen.add(j)
695
+ context_lines.append(lines[j])
696
+
697
+ context = (header + "\n" + "\n".join(context_lines))[:5000]
698
+ low = context.lower()
699
+
700
+ prohibited_signal = (
701
+ reg_kind == "prohibited"
702
+ or any(k in context for k in ["๋ฐฐํ•ฉ๊ธˆ์ง€", "์‚ฌ์šฉ๊ธˆ์ง€", "์‚ฌ์šฉ ๊ธˆ์ง€", "๊ธˆ์ง€์›๋ฃŒ", "๊ธˆ์ง€ ์›๋ฃŒ", "๊ธˆ์ง€์„ฑ๋ถ„", "๊ธˆ์ง€ ์„ฑ๋ถ„", "๊ตฌ๋ถ„ ๊ธˆ์ง€", "๊ตฌ๋ถ„: ๊ธˆ์ง€"])
703
+ or any(k in low for k in ["prohibited", "banned", "not allowed", "shall not be used", "must not be used", "forbidden"])
704
+ )
705
+
706
+ restricted_signal = (
707
+ reg_kind == "restricted"
708
+ or any(k in context for k in ["๋ฐฐํ•ฉํ•œ๋„", "์‚ฌ์šฉ์ œํ•œ", "์‚ฌ์šฉ ์ œํ•œ", "์ œํ•œ์„ฑ๋ถ„", "์ œํ•œ ์„ฑ๋ถ„", "๊ตฌ๋ถ„ ์ œํ•œ", "๊ตฌ๋ถ„: ์ œํ•œ"])
709
+ or any(k in low for k in ["restricted", "restriction", "maximum", "limit"])
710
+ )
711
+
712
+ if prohibited_signal:
713
+ result = {
714
+ "๋Œ€ํ‘œ INCI": representative,
715
+ "๊ฒฐ๊ณผ": f"{country_col} {reg_label}์—์„œ ๋™์˜์–ด/CAS/์ด์„ฑ์งˆ์ฒด ๊ทผ๊ฑฐ ํ™•์ธ",
716
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "๋ฐฐํ•ฉ๊ธˆ์ง€",
717
+ "๋น„๊ณ ": context[:1000],
718
+ }
719
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "REGISTRY_SYNONYM_PROHIBITED", context)
720
+ return result
721
+
722
+ if restricted_signal:
723
+ limit_text, condition_text = extract_limit_condition_from_context(context)
724
+ result = {
725
+ "๋Œ€ํ‘œ INCI": representative,
726
+ "๊ฒฐ๊ณผ": f"{country_col} {reg_label}์—์„œ ๋™์˜์–ด/CAS/์ด์„ฑ์งˆ์ฒด ์ œํ•œ ๊ทผ๊ฑฐ ํ™•์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
727
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}" if limit_text else NEED_CHECK_TEXT,
728
+ "๋น„๊ณ ": context[:1000],
729
+ }
730
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "REGISTRY_SYNONYM_RESTRICTED", context)
731
+ return result
732
+
733
+ return None
734
+
735
  def build_chemical_name_variants(term):
736
  """
737
  ํ™”ํ•™๋ช… ํ‘œ๊ธฐ ์ฐจ์ด ๋ณด์ •์šฉ alias ์ƒ์„ฑ.
 
932
  if safe_str(v):
933
  raw_terms.append(safe_str(v))
934
 
935
+ for reg_term in registry_terms_for_component(material=material, component=component, extra_terms=extra_terms):
936
+ if safe_str(reg_term):
937
+ raw_terms.append(safe_str(reg_term))
938
+
939
  expanded = []
940
  strong_abbrev_allowlist = {"EDTA", "BHT", "BHA", "MEA", "DEA", "TEA", "D4", "D5", "D6", "PFAS", "PFOA", "PFOS"}
941
  salt_prefixes = [
 
2902
  )
2903
 
2904
  if not matches:
2905
+ registry_result = registry_direct_regulation_fallback(
2906
+ country=country,
2907
+ material=material,
2908
+ component=component,
2909
+ target_id=target_id,
2910
+ )
2911
+
2912
+ if registry_result is not None:
2913
+ return registry_result
2914
+
2915
  alias_result = find_chemical_variant_match_in_country_text(
2916
  country=country,
2917
  material=material,
 
2957
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
2958
  "๋น„๊ณ ": "๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ๋„“์€ ๊ฒ€์ƒ‰์–ด๋งŒ ๋งค์นญ๋˜์–ด ์˜คํƒ์œผ๋กœ ์ œ์™ธ",
2959
  }
2960
+ registry_result = registry_direct_regulation_fallback(
2961
+ country=country,
2962
+ material=material,
2963
+ component=component,
2964
+ target_id=target_id,
2965
+ )
2966
+
2967
+ if registry_result is not None:
2968
+ return registry_result
2969
+
2970
  log_search_context(
2971
  target_id,
2972
  country,