Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -528,17 +528,11 @@ def is_broad_lookup_term(term):
|
|
| 528 |
return False
|
| 529 |
|
| 530 |
|
|
|
|
| 531 |
def build_chemical_name_variants(term):
|
| 532 |
"""
|
| 533 |
-
ํํ๋ช
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
์:
|
| 537 |
-
Dichlorobenzene
|
| 538 |
-
-> Dichlorobenzenes
|
| 539 |
-
-> 1,2-Dichlorobenzene / 1,3-Dichlorobenzene / 1,4-Dichlorobenzene
|
| 540 |
-
-> o-Dichlorobenzene / m-Dichlorobenzene / p-Dichlorobenzene
|
| 541 |
-
-> ๋ํด๋ก๋ก๋ฒค์ / 1,4-๋ํด๋ก๋ก๋ฒค์ / p-๋ํด๋ก๋ก๋ฒค์
|
| 542 |
"""
|
| 543 |
term = safe_str(term)
|
| 544 |
if not term:
|
|
@@ -560,7 +554,6 @@ def build_chemical_name_variants(term):
|
|
| 560 |
if low.endswith("benzenes"):
|
| 561 |
add(term[:-1])
|
| 562 |
|
| 563 |
-
translit = term
|
| 564 |
replacements = [
|
| 565 |
("Dichloro", "๋ํด๋ก๋ก"), ("dichloro", "๋ํด๋ก๋ก"),
|
| 566 |
("Trichloro", "ํธ๋ฆฌํด๋ก๋ก"), ("trichloro", "ํธ๋ฆฌํด๋ก๋ก"),
|
|
@@ -568,6 +561,7 @@ def build_chemical_name_variants(term):
|
|
| 568 |
("Chloro", "ํด๋ก๋ก"), ("chloro", "ํด๋ก๋ก"),
|
| 569 |
("Dibromo", "๋๋ธ๋ก๋ชจ"), ("dibromo", "๋๋ธ๋ก๋ชจ"),
|
| 570 |
("Bromo", "๋ธ๋ก๋ชจ"), ("bromo", "๋ธ๋ก๋ชจ"),
|
|
|
|
| 571 |
("Fluoro", "ํ๋ฃจ์ค๋ก"), ("fluoro", "ํ๋ฃจ์ค๋ก"),
|
| 572 |
("Iodo", "์์ด์ค๋"), ("iodo", "์์ด์ค๋"),
|
| 573 |
("Benzene", "๋ฒค์ "), ("benzene", "๋ฒค์ "),
|
|
@@ -575,6 +569,7 @@ def build_chemical_name_variants(term):
|
|
| 575 |
("Phenol", "ํ๋"), ("phenol", "ํ๋"),
|
| 576 |
]
|
| 577 |
|
|
|
|
| 578 |
for a, b in replacements:
|
| 579 |
translit = translit.replace(a, b)
|
| 580 |
|
|
@@ -589,6 +584,7 @@ def build_chemical_name_variants(term):
|
|
| 589 |
("chlorobenzene", "Chlorobenzene", "ํด๋ก๋ก๋ฒค์ "),
|
| 590 |
("dibromobenzene", "Dibromobenzene", "๋๋ธ๋ก๋ชจ๋ฒค์ "),
|
| 591 |
("bromobenzene", "Bromobenzene", "๋ธ๋ก๋ชจ๋ฒค์ "),
|
|
|
|
| 592 |
("fluorobenzene", "Fluorobenzene", "ํ๋ฃจ์ค๋ก๋ฒค์ "),
|
| 593 |
("iodobenzene", "Iodobenzene", "์์ด์ค๋๋ฒค์ "),
|
| 594 |
]
|
|
@@ -598,19 +594,122 @@ def build_chemical_name_variants(term):
|
|
| 598 |
add(en)
|
| 599 |
add(en + "s")
|
| 600 |
add(ko)
|
|
|
|
| 601 |
|
| 602 |
-
for pos in ["1,2", "1,3", "1,4", "o", "m", "p", "ortho", "meta", "para"]:
|
| 603 |
-
|
| 604 |
-
add(f"{
|
| 605 |
-
add(f"{
|
| 606 |
-
add(f"{
|
|
|
|
| 607 |
|
| 608 |
add(f"1,4-{ko}(p-{ko})")
|
| 609 |
add(f"1,4-{en} (p-{en})")
|
|
|
|
|
|
|
| 610 |
|
| 611 |
return variants
|
| 612 |
|
| 613 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
def build_ingredient_lookup_terms(material=None, component=None, extra_terms=None):
|
| 615 |
material = material or {}
|
| 616 |
component = component or {}
|
|
@@ -746,6 +845,17 @@ def validate_country_file_match_context(context, component, lookup_terms):
|
|
| 746 |
if len(norm) >= 4 and norm in compact:
|
| 747 |
return True
|
| 748 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
if context_has_group_regulation_for_terms(context, lookup_terms):
|
| 750 |
return True
|
| 751 |
|
|
@@ -2585,6 +2695,16 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 2585 |
)
|
| 2586 |
|
| 2587 |
if not matches:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2588 |
result = {
|
| 2589 |
"๋ํ INCI": representative,
|
| 2590 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
|
|
|
| 528 |
return False
|
| 529 |
|
| 530 |
|
| 531 |
+
|
| 532 |
def build_chemical_name_variants(term):
|
| 533 |
"""
|
| 534 |
+
ํํ๋ช
ํ๊ธฐ ์ฐจ์ด ๋ณด์ ์ฉ alias ์์ฑ.
|
| 535 |
+
์ด์ฑ์ง์ฒด/๋ณต์ํ/๊ตญ๋ฌธ ์์ญ ํ๊ธฐ๋ฅผ ์์ฑํ๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 536 |
"""
|
| 537 |
term = safe_str(term)
|
| 538 |
if not term:
|
|
|
|
| 554 |
if low.endswith("benzenes"):
|
| 555 |
add(term[:-1])
|
| 556 |
|
|
|
|
| 557 |
replacements = [
|
| 558 |
("Dichloro", "๋ํด๋ก๋ก"), ("dichloro", "๋ํด๋ก๋ก"),
|
| 559 |
("Trichloro", "ํธ๋ฆฌํด๋ก๋ก"), ("trichloro", "ํธ๋ฆฌํด๋ก๋ก"),
|
|
|
|
| 561 |
("Chloro", "ํด๋ก๋ก"), ("chloro", "ํด๋ก๋ก"),
|
| 562 |
("Dibromo", "๋๋ธ๋ก๋ชจ"), ("dibromo", "๋๋ธ๋ก๋ชจ"),
|
| 563 |
("Bromo", "๋ธ๋ก๋ชจ"), ("bromo", "๋ธ๋ก๋ชจ"),
|
| 564 |
+
("Difluoro", "๋ํ๋ฃจ์ค๋ก"), ("difluoro", "๋ํ๋ฃจ์ค๋ก"),
|
| 565 |
("Fluoro", "ํ๋ฃจ์ค๋ก"), ("fluoro", "ํ๋ฃจ์ค๋ก"),
|
| 566 |
("Iodo", "์์ด์ค๋"), ("iodo", "์์ด์ค๋"),
|
| 567 |
("Benzene", "๋ฒค์ "), ("benzene", "๋ฒค์ "),
|
|
|
|
| 569 |
("Phenol", "ํ๋"), ("phenol", "ํ๋"),
|
| 570 |
]
|
| 571 |
|
| 572 |
+
translit = term
|
| 573 |
for a, b in replacements:
|
| 574 |
translit = translit.replace(a, b)
|
| 575 |
|
|
|
|
| 584 |
("chlorobenzene", "Chlorobenzene", "ํด๋ก๋ก๋ฒค์ "),
|
| 585 |
("dibromobenzene", "Dibromobenzene", "๋๋ธ๋ก๋ชจ๋ฒค์ "),
|
| 586 |
("bromobenzene", "Bromobenzene", "๋ธ๋ก๋ชจ๋ฒค์ "),
|
| 587 |
+
("difluorobenzene", "Difluorobenzene", "๋ํ๋ฃจ์ค๋ก๋ฒค์ "),
|
| 588 |
("fluorobenzene", "Fluorobenzene", "ํ๋ฃจ์ค๋ก๋ฒค์ "),
|
| 589 |
("iodobenzene", "Iodobenzene", "์์ด์ค๋๋ฒค์ "),
|
| 590 |
]
|
|
|
|
| 594 |
add(en)
|
| 595 |
add(en + "s")
|
| 596 |
add(ko)
|
| 597 |
+
add(ko + "๋ฅ")
|
| 598 |
|
| 599 |
+
for pos in ["1,2", "1,3", "1,4", "1,2-", "1,3-", "1,4-", "o", "m", "p", "ortho", "meta", "para"]:
|
| 600 |
+
pos_clean = pos.rstrip("-")
|
| 601 |
+
add(f"{pos_clean}-{en}")
|
| 602 |
+
add(f"{pos_clean} {en}")
|
| 603 |
+
add(f"{pos_clean}-{ko}")
|
| 604 |
+
add(f"{pos_clean} {ko}")
|
| 605 |
|
| 606 |
add(f"1,4-{ko}(p-{ko})")
|
| 607 |
add(f"1,4-{en} (p-{en})")
|
| 608 |
+
add(f"p-{ko}")
|
| 609 |
+
add(f"p-{en}")
|
| 610 |
|
| 611 |
return variants
|
| 612 |
|
| 613 |
|
| 614 |
+
def find_chemical_variant_match_in_country_text(country, material, component, target_id=""):
|
| 615 |
+
"""
|
| 616 |
+
๊ตญ๊ฐ๋ณ ์น์
์ธ๋ฑ์ค ๋งค์นญ์ด ์คํจํ ๊ฒฝ์ฐ๋ฅผ ์ํ ํํ๋ช
๋ณํ fallback.
|
| 617 |
+
์ ์ฒด ๊ตญ๊ฐ ํ์ผ ์๋ฌธ์์ ํํ๋ช
๋ณํ alias๋ฅผ ์ง์ ์ฐพ๊ณ ,
|
| 618 |
+
๊ทธ ์น์
/๋ฌธ๋งฅ์ด ๊ธ์ง ๋๋ ์ ํ ํ์ผ์ด๋ฉด ํ์ ํ๋ค.
|
| 619 |
+
"""
|
| 620 |
+
lookup_terms = build_ingredient_lookup_terms(
|
| 621 |
+
material=material,
|
| 622 |
+
component=component,
|
| 623 |
+
extra_terms=[
|
| 624 |
+
component.get("INCI Name", ""),
|
| 625 |
+
component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""),
|
| 626 |
+
component.get("CAS.No", ""),
|
| 627 |
+
],
|
| 628 |
+
)
|
| 629 |
+
|
| 630 |
+
expanded = []
|
| 631 |
+
for t in lookup_terms:
|
| 632 |
+
for v in build_chemical_name_variants(t):
|
| 633 |
+
if safe_str(v) and v not in expanded:
|
| 634 |
+
expanded.append(v)
|
| 635 |
+
|
| 636 |
+
# ๋๋ฌด ์ผ๋ฐ์ ์ธ alias ์ ๊ฑฐ
|
| 637 |
+
expanded = [
|
| 638 |
+
x for x in expanded
|
| 639 |
+
if len(normalize_compact(x)) >= 4 and not is_broad_lookup_term(x)
|
| 640 |
+
]
|
| 641 |
+
|
| 642 |
+
if not expanded:
|
| 643 |
+
return None
|
| 644 |
+
|
| 645 |
+
sections, status = get_country_section_index_cached(country)
|
| 646 |
+
country_col = display_country(country)
|
| 647 |
+
representative = safe_str(component.get("INCI Name", "")) or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", "")) or "-"
|
| 648 |
+
|
| 649 |
+
for section in sections:
|
| 650 |
+
text = safe_str(section.get("text", ""))
|
| 651 |
+
text_norm = normalize_compact(text)
|
| 652 |
+
header = safe_str(section.get("header", ""))
|
| 653 |
+
reg_type = infer_regulation_type_from_source_text(header + "\n" + text[:1500], country=country)
|
| 654 |
+
reg_kind = reg_type.get("type", "unknown")
|
| 655 |
+
reg_label = reg_type.get("label", "๊ท์ ์ ํ ๋ฏธ๋ถ๋ฅ")
|
| 656 |
+
|
| 657 |
+
hit_terms = [v for v in expanded if normalize_compact(v) in text_norm]
|
| 658 |
+
if not hit_terms:
|
| 659 |
+
continue
|
| 660 |
+
|
| 661 |
+
lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
|
| 662 |
+
context_lines = []
|
| 663 |
+
seen = set()
|
| 664 |
+
|
| 665 |
+
for idx, line in enumerate(lines):
|
| 666 |
+
line_norm = normalize_compact(line)
|
| 667 |
+
if any(normalize_compact(v) in line_norm for v in hit_terms):
|
| 668 |
+
for j in range(max(0, idx - 4), min(len(lines), idx + 5)):
|
| 669 |
+
if j not in seen:
|
| 670 |
+
seen.add(j)
|
| 671 |
+
context_lines.append(lines[j])
|
| 672 |
+
|
| 673 |
+
context = (header + "\n" + "\n".join(context_lines))[:5000]
|
| 674 |
+
context_low = context.lower()
|
| 675 |
+
|
| 676 |
+
prohibited_signal = (
|
| 677 |
+
reg_kind == "prohibited"
|
| 678 |
+
or any(k in context for k in ["๋ฐฐํฉ๊ธ์ง", "์ฌ์ฉ๊ธ์ง", "์ฌ์ฉ ๊ธ์ง", "๊ธ์ง์๋ฃ", "๊ธ์ง ์ฑ๋ถ", "๊ธ์ง์ฑ๋ถ"])
|
| 679 |
+
or any(k in context_low for k in ["prohibited", "banned", "not allowed", "shall not be used", "must not be used"])
|
| 680 |
+
)
|
| 681 |
+
|
| 682 |
+
restricted_signal = (
|
| 683 |
+
reg_kind == "restricted"
|
| 684 |
+
or any(k in context for k in ["์ฌ์ฉ์ ํ", "์ฌ์ฉ ์ ํ", "๋ฐฐํฉํ๋", "์ ํ์ฑ๋ถ", "์ ํ ์ฑ๋ถ"])
|
| 685 |
+
or any(k in context_low for k in ["restricted", "restriction", "maximum", "limit"])
|
| 686 |
+
)
|
| 687 |
+
|
| 688 |
+
if prohibited_signal:
|
| 689 |
+
result = {
|
| 690 |
+
"๋ํ INCI": representative,
|
| 691 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ํํ๋ช
๋ณํ alias ํ์ธ",
|
| 692 |
+
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 693 |
+
"๋น๊ณ ": context[:1000],
|
| 694 |
+
}
|
| 695 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "COUNTRY_FILE_CHEMICAL_ALIAS_PROHIBITED", context)
|
| 696 |
+
return result
|
| 697 |
+
|
| 698 |
+
if restricted_signal:
|
| 699 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
| 700 |
+
display = f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT
|
| 701 |
+
result = {
|
| 702 |
+
"๋ํ INCI": representative,
|
| 703 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ํํ๋ช
๋ณํ alias ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 704 |
+
"ํ์๋ฌธ๊ตฌ": display,
|
| 705 |
+
"๋น๊ณ ": context[:1000],
|
| 706 |
+
}
|
| 707 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "COUNTRY_FILE_CHEMICAL_ALIAS_RESTRICTED", context)
|
| 708 |
+
return result
|
| 709 |
+
|
| 710 |
+
return None
|
| 711 |
+
|
| 712 |
+
|
| 713 |
def build_ingredient_lookup_terms(material=None, component=None, extra_terms=None):
|
| 714 |
material = material or {}
|
| 715 |
component = component or {}
|
|
|
|
| 845 |
if len(norm) >= 4 and norm in compact:
|
| 846 |
return True
|
| 847 |
|
| 848 |
+
# ํํ๋ช
๋ณํ alias fallback
|
| 849 |
+
for term in [
|
| 850 |
+
component.get("INCI Name", ""),
|
| 851 |
+
component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""),
|
| 852 |
+
component.get("CAS.No", ""),
|
| 853 |
+
]:
|
| 854 |
+
for variant in build_chemical_name_variants(term):
|
| 855 |
+
norm = normalize_compact(variant)
|
| 856 |
+
if len(norm) >= 4 and norm in compact:
|
| 857 |
+
return True
|
| 858 |
+
|
| 859 |
if context_has_group_regulation_for_terms(context, lookup_terms):
|
| 860 |
return True
|
| 861 |
|
|
|
|
| 2695 |
)
|
| 2696 |
|
| 2697 |
if not matches:
|
| 2698 |
+
alias_result = find_chemical_variant_match_in_country_text(
|
| 2699 |
+
country=country,
|
| 2700 |
+
material=material,
|
| 2701 |
+
component=component,
|
| 2702 |
+
target_id=target_id,
|
| 2703 |
+
)
|
| 2704 |
+
|
| 2705 |
+
if alias_result is not None:
|
| 2706 |
+
return alias_result
|
| 2707 |
+
|
| 2708 |
result = {
|
| 2709 |
"๋ํ INCI": representative,
|
| 2710 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|