Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -506,21 +506,30 @@ def preview_input_file(file):
|
|
| 506 |
except Exception as e: return pd.DataFrame({"์ค๋ฅ":[str(e)]})
|
| 507 |
|
| 508 |
|
| 509 |
-
def build_ingredient_lookup_terms(material=None, component=None, extra_terms=None):
|
| 510 |
-
"""
|
| 511 |
-
๊ตญ๊ฐ๋ณ ํ์ผ ์ง์ ๊ฒ์์ฉ ์ฑ๋ถ ๊ฒ์์ด ํ์ฅ.
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
|
|
|
|
|
|
|
|
|
| 518 |
|
| 519 |
-
|
| 520 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
material = material or {}
|
| 522 |
component = component or {}
|
| 523 |
-
|
| 524 |
raw_terms = []
|
| 525 |
|
| 526 |
for v in [
|
|
@@ -538,106 +547,68 @@ def build_ingredient_lookup_terms(material=None, component=None, extra_terms=Non
|
|
| 538 |
raw_terms.append(safe_str(v))
|
| 539 |
|
| 540 |
expanded = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
|
| 542 |
-
def add(term):
|
| 543 |
term = safe_str(term)
|
| 544 |
if not term:
|
| 545 |
return
|
| 546 |
-
|
| 547 |
-
norm = normalize_compact(term)
|
| 548 |
-
|
| 549 |
-
# ๋๋ฌด ์งง๊ฑฐ๋ ์ผ๋ฐ์ ์ธ ๋จ์ด๋ ์คํ ๋ฐฉ์ง
|
| 550 |
-
blocked = {
|
| 551 |
-
"acid", "oil", "water", "aqua", "extract", "powder", "solution",
|
| 552 |
-
"sodium", "potassium", "calcium", "magnesium", "zinc", "ammonium",
|
| 553 |
-
"and", "or", "the", "of", "for", "skin", "agent",
|
| 554 |
-
"์ ์จ๋", "์ค์ผ", "์ถ์ถ๋ฌผ", "์ ์ ์", "์", "๋ฌผ",
|
| 555 |
-
}
|
| 556 |
-
|
| 557 |
-
if len(norm) < 3:
|
| 558 |
return
|
| 559 |
-
|
| 560 |
-
if normalize_text(term) in blocked or norm in blocked:
|
| 561 |
return
|
| 562 |
-
|
| 563 |
if term not in expanded:
|
| 564 |
expanded.append(term)
|
| 565 |
|
| 566 |
-
salt_prefixes = [
|
| 567 |
-
"disodium", "trisodium", "tetrasodium", "sodium",
|
| 568 |
-
"dipotassium", "tripotassium", "tetrapotassium", "potassium",
|
| 569 |
-
"calcium disodium", "calcium", "magnesium", "zinc", "ammonium",
|
| 570 |
-
"mono", "di", "tri", "tetra",
|
| 571 |
-
]
|
| 572 |
-
|
| 573 |
for term in raw_terms:
|
| 574 |
t = safe_str(term)
|
| 575 |
add(t)
|
|
|
|
|
|
|
| 576 |
|
| 577 |
-
# ๊ดํธ ์ ์ฝ์ด/๋ณ์นญ
|
| 578 |
for p in re.findall(r"\(([^)]+)\)", t):
|
| 579 |
-
|
|
|
|
|
|
|
| 580 |
|
| 581 |
-
# ๋๋ฌธ์ ์ฝ์ด: EDTA, BHT, BHA, MEA ๋ฑ
|
| 582 |
for abbr in re.findall(r"\b[A-Z][A-Z0-9]{2,}\b", t):
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
# ํ์ดํ/์ฌ๋์ ๋ณํ
|
| 586 |
-
add(t.replace("-", " "))
|
| 587 |
-
add(t.replace("/", " "))
|
| 588 |
|
| 589 |
low = t.lower().strip()
|
| 590 |
-
|
| 591 |
-
# ์ผ/๊ธ์์ผ prefix ์ ๊ฑฐ: Disodium EDTA -> EDTA
|
| 592 |
for prefix in salt_prefixes:
|
| 593 |
if low.startswith(prefix + " "):
|
| 594 |
base = t[len(prefix):].strip(" -_/")
|
| 595 |
-
|
|
|
|
|
|
|
| 596 |
|
| 597 |
-
# Calcium Disodium EDTA์ฒ๋ผ ๋ ๋จ๊ณ prefix ์ ๊ฑฐ
|
| 598 |
tokens = re.split(r"[\s\-/]+", t)
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
# ์ผ๋ฐ INCI ์ ๋ฏธ/๊ทธ๋ฃน ํ๋ณด
|
| 606 |
-
# Sodium Benzoate -> Benzoate, Potassium Sorbate -> Sorbate
|
| 607 |
-
if len(tokens) >= 2 and tokens[0].lower() in {
|
| 608 |
-
"sodium", "potassium", "calcium", "magnesium", "zinc", "ammonium",
|
| 609 |
-
"disodium", "trisodium", "tetrasodium", "dipotassium",
|
| 610 |
-
}:
|
| 611 |
-
add(" ".join(tokens[1:]))
|
| 612 |
-
|
| 613 |
-
# compact ๊ธฐ์ค ์ค๋ณต ์ ๊ฑฐ
|
| 614 |
seen = set()
|
| 615 |
final_terms = []
|
| 616 |
-
|
| 617 |
for term in expanded:
|
| 618 |
norm = normalize_compact(term)
|
| 619 |
-
|
| 620 |
if norm in seen:
|
| 621 |
continue
|
| 622 |
-
|
| 623 |
seen.add(norm)
|
| 624 |
final_terms.append(term)
|
| 625 |
|
| 626 |
-
|
| 627 |
-
final_terms = sorted(final_terms, key=lambda x: len(normalize_compact(x)), reverse=True)
|
| 628 |
-
|
| 629 |
-
return final_terms
|
| 630 |
-
|
| 631 |
|
| 632 |
def context_has_group_regulation_for_terms(context, lookup_terms):
|
| 633 |
-
"""
|
| 634 |
-
'EDTA and derivatives', 'X and salts', 'X derivatives' ๊ฐ์ ๊ทธ๋ฃนํ ๋ฌธ๊ตฌ ํ์ธ.
|
| 635 |
-
ํน์ ์ฑ๋ถ ํ๋์ฝ๋ฉ ์์ด alias์ ๋ฌธ๋งฅ ํจํด์ผ๋ก ํ๋จํ๋ค.
|
| 636 |
-
"""
|
| 637 |
text = safe_str(context)
|
| 638 |
compact = normalize_compact(text)
|
| 639 |
low = text.lower()
|
| 640 |
-
|
| 641 |
if not text or not lookup_terms:
|
| 642 |
return False
|
| 643 |
|
|
@@ -646,22 +617,43 @@ def context_has_group_regulation_for_terms(context, lookup_terms):
|
|
| 646 |
"and its salts", "and their salts", "and derivatives", "and its derivatives",
|
| 647 |
"๋ฐ์ ๋์ฒด", "์ ๋์ฒด", "์ผ๋ฅ", "๊ทธ์ผ", "๊ทธ ์ ๋์ฒด",
|
| 648 |
]
|
| 649 |
-
|
| 650 |
if not any(normalize_compact(w) in compact or w in low for w in group_words):
|
| 651 |
return False
|
| 652 |
|
| 653 |
for term in lookup_terms:
|
|
|
|
|
|
|
| 654 |
norm = normalize_compact(term)
|
|
|
|
|
|
|
|
|
|
| 655 |
|
| 656 |
-
|
| 657 |
-
|
|
|
|
|
|
|
|
|
|
| 658 |
|
| 659 |
-
|
|
|
|
|
|
|
| 660 |
return True
|
| 661 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
return False
|
| 663 |
|
| 664 |
|
|
|
|
|
|
|
| 665 |
# country db
|
| 666 |
|
| 667 |
def resolve_country_folder(country):
|
|
@@ -2517,6 +2509,27 @@ def evaluate_component_from_country_files_only(country, material, component, tar
|
|
| 2517 |
evidence = context[:5000]
|
| 2518 |
lower = evidence.lower()
|
| 2519 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2520 |
# 1. Annex II / Prohibited / Negative List
|
| 2521 |
# ํต์ฌ: ์ฑ๋ถ ์ฃผ๋ณ์ ๊ธ์ง๋ผ๋ ๋จ์ด๊ฐ ์์ด๋ ํด๋น ํ์ผ์์ ๋ฐ๊ฒฌ๋๋ฉด ๋ฐฐํฉ๊ธ์ง.
|
| 2522 |
if reg_kind == "restricted" or reg_kind.startswith("positive_"):
|
|
|
|
| 506 |
except Exception as e: return pd.DataFrame({"์ค๋ฅ":[str(e)]})
|
| 507 |
|
| 508 |
|
|
|
|
|
|
|
|
|
|
| 509 |
|
| 510 |
+
BROAD_LOOKUP_TERMS = {
|
| 511 |
+
"acid", "acids", "alcohol", "alcohols", "glycol", "glycols", "oil", "oils",
|
| 512 |
+
"extract", "extracts", "water", "aqua", "powder", "solution", "agent",
|
| 513 |
+
"sodium", "potassium", "calcium", "magnesium", "zinc", "ammonium",
|
| 514 |
+
"skin", "conditioning", "cosmetic", "quality", "system",
|
| 515 |
+
"stem", "flower", "leaf", "root", "fruit", "seed", "peel",
|
| 516 |
+
"์ ์จ๋", "์์ฝ์ฌ", "๊ธ๋ผ์ด์ฝ", "์ค์ผ", "์ถ์ถ๋ฌผ", "์ ์ ์", "์", "๋ฌผ",
|
| 517 |
+
}
|
| 518 |
|
| 519 |
+
def is_broad_lookup_term(term):
|
| 520 |
+
norm = normalize_compact(term)
|
| 521 |
+
text = normalize_text(term)
|
| 522 |
+
if not norm or len(norm) < 4:
|
| 523 |
+
return True
|
| 524 |
+
if norm in {normalize_compact(x) for x in BROAD_LOOKUP_TERMS}:
|
| 525 |
+
return True
|
| 526 |
+
if text in BROAD_LOOKUP_TERMS:
|
| 527 |
+
return True
|
| 528 |
+
return False
|
| 529 |
+
|
| 530 |
+
def build_ingredient_lookup_terms(material=None, component=None, extra_terms=None):
|
| 531 |
material = material or {}
|
| 532 |
component = component or {}
|
|
|
|
| 533 |
raw_terms = []
|
| 534 |
|
| 535 |
for v in [
|
|
|
|
| 547 |
raw_terms.append(safe_str(v))
|
| 548 |
|
| 549 |
expanded = []
|
| 550 |
+
strong_abbrev_allowlist = {"EDTA", "BHT", "BHA", "MEA", "DEA", "TEA", "D4", "D5", "D6", "PFAS", "PFOA", "PFOS"}
|
| 551 |
+
salt_prefixes = [
|
| 552 |
+
"calcium disodium", "disodium", "trisodium", "tetrasodium", "sodium",
|
| 553 |
+
"dipotassium", "tripotassium", "tetrapotassium", "potassium",
|
| 554 |
+
"calcium", "magnesium", "zinc", "ammonium",
|
| 555 |
+
]
|
| 556 |
|
| 557 |
+
def add(term, allow_broad=False):
|
| 558 |
term = safe_str(term)
|
| 559 |
if not term:
|
| 560 |
return
|
| 561 |
+
if len(normalize_compact(term)) < 3:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
return
|
| 563 |
+
if not allow_broad and is_broad_lookup_term(term):
|
|
|
|
| 564 |
return
|
|
|
|
| 565 |
if term not in expanded:
|
| 566 |
expanded.append(term)
|
| 567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
for term in raw_terms:
|
| 569 |
t = safe_str(term)
|
| 570 |
add(t)
|
| 571 |
+
add(t.replace("-", " "))
|
| 572 |
+
add(t.replace("/", " "))
|
| 573 |
|
|
|
|
| 574 |
for p in re.findall(r"\(([^)]+)\)", t):
|
| 575 |
+
p = safe_str(p)
|
| 576 |
+
if p.upper() in strong_abbrev_allowlist or len(normalize_compact(p)) >= 5:
|
| 577 |
+
add(p, allow_broad=(p.upper() in strong_abbrev_allowlist))
|
| 578 |
|
|
|
|
| 579 |
for abbr in re.findall(r"\b[A-Z][A-Z0-9]{2,}\b", t):
|
| 580 |
+
if abbr.upper() in strong_abbrev_allowlist:
|
| 581 |
+
add(abbr, allow_broad=True)
|
|
|
|
|
|
|
|
|
|
| 582 |
|
| 583 |
low = t.lower().strip()
|
|
|
|
|
|
|
| 584 |
for prefix in salt_prefixes:
|
| 585 |
if low.startswith(prefix + " "):
|
| 586 |
base = t[len(prefix):].strip(" -_/")
|
| 587 |
+
# Disodium EDTA -> EDTA๋ ํ์ฉ, Sodium Benzoate -> Benzoate๋ ํ์ฉ
|
| 588 |
+
# ํ์ง๋ง Butylene Glycol -> Glycol์ฒ๋ผ broad term๋ง ๋จ๊ธฐ๋ ํ์ฅ์ ํ์ง ์์
|
| 589 |
+
add(base, allow_broad=(base.upper() in strong_abbrev_allowlist))
|
| 590 |
|
|
|
|
| 591 |
tokens = re.split(r"[\s\-/]+", t)
|
| 592 |
+
for i in range(1, min(4, len(tokens))):
|
| 593 |
+
base = " ".join(tokens[i:]).strip()
|
| 594 |
+
if base.upper() in strong_abbrev_allowlist:
|
| 595 |
+
add(base, allow_broad=True)
|
| 596 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 597 |
seen = set()
|
| 598 |
final_terms = []
|
|
|
|
| 599 |
for term in expanded:
|
| 600 |
norm = normalize_compact(term)
|
|
|
|
| 601 |
if norm in seen:
|
| 602 |
continue
|
|
|
|
| 603 |
seen.add(norm)
|
| 604 |
final_terms.append(term)
|
| 605 |
|
| 606 |
+
return sorted(final_terms, key=lambda x: len(normalize_compact(x)), reverse=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
def context_has_group_regulation_for_terms(context, lookup_terms):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
text = safe_str(context)
|
| 610 |
compact = normalize_compact(text)
|
| 611 |
low = text.lower()
|
|
|
|
| 612 |
if not text or not lookup_terms:
|
| 613 |
return False
|
| 614 |
|
|
|
|
| 617 |
"and its salts", "and their salts", "and derivatives", "and its derivatives",
|
| 618 |
"๋ฐ์ ๋์ฒด", "์ ๋์ฒด", "์ผ๋ฅ", "๊ทธ์ผ", "๊ทธ ์ ๋์ฒด",
|
| 619 |
]
|
|
|
|
| 620 |
if not any(normalize_compact(w) in compact or w in low for w in group_words):
|
| 621 |
return False
|
| 622 |
|
| 623 |
for term in lookup_terms:
|
| 624 |
+
if is_broad_lookup_term(term):
|
| 625 |
+
continue
|
| 626 |
norm = normalize_compact(term)
|
| 627 |
+
if len(norm) >= 4 and norm in compact:
|
| 628 |
+
return True
|
| 629 |
+
return False
|
| 630 |
|
| 631 |
+
def validate_country_file_match_context(context, component, lookup_terms):
|
| 632 |
+
text = safe_str(context)
|
| 633 |
+
compact = normalize_compact(text)
|
| 634 |
+
if not text:
|
| 635 |
+
return False
|
| 636 |
|
| 637 |
+
for term in [component.get("INCI Name", ""), component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""), component.get("CAS.No", "")]:
|
| 638 |
+
norm = normalize_compact(term)
|
| 639 |
+
if len(norm) >= 4 and norm in compact:
|
| 640 |
return True
|
| 641 |
|
| 642 |
+
for term in lookup_terms or []:
|
| 643 |
+
if is_broad_lookup_term(term):
|
| 644 |
+
continue
|
| 645 |
+
norm = normalize_compact(term)
|
| 646 |
+
if len(norm) >= 4 and norm in compact:
|
| 647 |
+
return True
|
| 648 |
+
|
| 649 |
+
if context_has_group_regulation_for_terms(context, lookup_terms):
|
| 650 |
+
return True
|
| 651 |
+
|
| 652 |
return False
|
| 653 |
|
| 654 |
|
| 655 |
+
|
| 656 |
+
|
| 657 |
# country db
|
| 658 |
|
| 659 |
def resolve_country_folder(country):
|
|
|
|
| 2509 |
evidence = context[:5000]
|
| 2510 |
lower = evidence.lower()
|
| 2511 |
|
| 2512 |
+
if not validate_country_file_match_context(
|
| 2513 |
+
context=context,
|
| 2514 |
+
component=component,
|
| 2515 |
+
lookup_terms=lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no],
|
| 2516 |
+
):
|
| 2517 |
+
result = {
|
| 2518 |
+
"๋ํ INCI": representative,
|
| 2519 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 2520 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 2521 |
+
"๋น๊ณ ": "๊ตญ๊ฐ๋ณ ํ์ผ์์ ๋์ ๊ฒ์์ด๋ง ๋งค์นญ๋์ด ์คํ์ผ๋ก ์ ์ธ",
|
| 2522 |
+
}
|
| 2523 |
+
log_search_context(
|
| 2524 |
+
target_id,
|
| 2525 |
+
country,
|
| 2526 |
+
component,
|
| 2527 |
+
result["๊ฒฐ๊ณผ"],
|
| 2528 |
+
"COUNTRY_FILE_BROAD_MATCH_IGNORED",
|
| 2529 |
+
context,
|
| 2530 |
+
)
|
| 2531 |
+
return result
|
| 2532 |
+
|
| 2533 |
# 1. Annex II / Prohibited / Negative List
|
| 2534 |
# ํต์ฌ: ์ฑ๋ถ ์ฃผ๋ณ์ ๊ธ์ง๋ผ๋ ๋จ์ด๊ฐ ์์ด๋ ํด๋น ํ์ผ์์ ๋ฐ๊ฒฌ๋๋ฉด ๋ฐฐํฉ๊ธ์ง.
|
| 2535 |
if reg_kind == "restricted" or reg_kind.startswith("positive_"):
|