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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|