Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -537,7 +537,56 @@ def is_broad_lookup_term(term):
|
|
| 537 |
# ============================================================
|
| 538 |
|
| 539 |
REGULATORY_SYNONYM_REGISTRY = [
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
"key": "dichlorobenzene",
|
| 542 |
"canonical": "Dichlorobenzene",
|
| 543 |
"terms": [
|
|
@@ -937,7 +986,7 @@ def build_ingredient_lookup_terms(material=None, component=None, extra_terms=Non
|
|
| 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 = [
|
| 942 |
"calcium disodium", "disodium", "trisodium", "tetrasodium", "sodium",
|
| 943 |
"dipotassium", "tripotassium", "tetrapotassium", "potassium",
|
|
@@ -2191,7 +2240,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=30
|
|
| 2191 |
f"- In formula ํฉ๊ณ: {format_amount(sum_formula_percent(formula_df))}%\n"
|
| 2192 |
f"- ์ฌ๊ฒํ ํ์ ์ฑ๋ถ: {len(regulatory_df)}๊ฐ\n"
|
| 2193 |
f"- MFDS ์ํ: {mfds_msg}\n"
|
| 2194 |
-
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์ / ๊ตญ๊ฐ๋ณ ํ์ผ ์ง์ ๊ฒ์
|
| 2195 |
f"- ๊ตญ๊ฐ๋ณ ์ธ๋ฑ์ค ์ํ: {' | '.join(index_messages)}\n"
|
| 2196 |
"- ์๋ ๊ฐ์ : ์ ์ฒด ์คํฌ๋ฆฌ๋์์ GPT/LLM ํธ์ถ ์ ๊ฑฐ\n"
|
| 2197 |
)
|
|
@@ -2836,420 +2885,361 @@ def make_restricted_or_positive_result(country, component, match, reg_type):
|
|
| 2836 |
}
|
| 2837 |
|
| 2838 |
|
| 2839 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2840 |
"""
|
| 2841 |
-
|
| 2842 |
-
|
| 2843 |
-
๋ณธ์ง์ ๊ฐ์ :
|
| 2844 |
-
- ์ฑ๋ถ ์ฃผ๋ณ ๋ฌธ์ฅ์ '๊ธ์ง' ํค์๋๊ฐ ์๋๋ผ๋,
|
| 2845 |
-
Annex II / Prohibited / Negative List ํ์ผ์์ ๋ฐ๊ฒฌ๋๋ฉด ๋ฐฐํฉ๊ธ์ง๋ก ํ์ ํ๋ค.
|
| 2846 |
-
- Annex III / Restricted ํ์ผ์์ ๋ฐ๊ฒฌ๋๋ฉด ์ ํ ์ฑ๋ถ์ผ๋ก ํ์ ํ๋ค.
|
| 2847 |
-
- Annex IV/V/VI Positive List์์ ๋ฐ๊ฒฌ๋๋ฉด ํด๋น ๋ชฉ์ ์ ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ๋ก ํ์ ํ๋ค.
|
| 2848 |
-
- ํจ๋ ๏ฟฝ๏ฟฝ๏ฟฝ๋ฌด๋ ๊ธ์ง ํ๋จ์ ์ํฅ์ ์ฃผ์ง ์๋๋ค.
|
| 2849 |
"""
|
| 2850 |
-
|
|
|
|
| 2851 |
|
| 2852 |
-
|
| 2853 |
-
korean_name = safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 2854 |
-
cas_no = safe_str(component.get("CAS.No", ""))
|
| 2855 |
|
| 2856 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2857 |
|
| 2858 |
-
|
| 2859 |
-
|
| 2860 |
-
material=material,
|
| 2861 |
-
component=component,
|
| 2862 |
-
)
|
| 2863 |
|
| 2864 |
-
|
| 2865 |
-
|
| 2866 |
-
|
| 2867 |
-
|
| 2868 |
-
|
| 2869 |
-
|
| 2870 |
-
"CRITICAL_COUNTRY_RULE",
|
| 2871 |
-
critical_result.get("๋น๊ณ ", "-"),
|
| 2872 |
-
)
|
| 2873 |
-
return critical_result
|
| 2874 |
|
| 2875 |
-
|
| 2876 |
-
|
| 2877 |
-
"๋ํ INCI": representative if representative != "-" else "Water",
|
| 2878 |
-
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 2879 |
-
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 2880 |
-
"๋น๊ณ ": "์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ",
|
| 2881 |
-
}
|
| 2882 |
-
log_search_context(
|
| 2883 |
-
target_id,
|
| 2884 |
-
country,
|
| 2885 |
-
component,
|
| 2886 |
-
result["๊ฒฐ๊ณผ"],
|
| 2887 |
-
"ALWAYS_PASS_RULE",
|
| 2888 |
-
result["๋น๊ณ "],
|
| 2889 |
-
)
|
| 2890 |
-
return result
|
| 2891 |
|
| 2892 |
-
|
| 2893 |
-
material=material,
|
| 2894 |
-
component=component,
|
| 2895 |
-
extra_terms=[inci_name, korean_name, cas_no],
|
| 2896 |
-
)
|
| 2897 |
|
| 2898 |
-
matches, cache_status = find_matching_regulatory_sections_fast(
|
| 2899 |
-
country=country,
|
| 2900 |
-
ingredient_names=lookup_terms,
|
| 2901 |
-
max_sections=30,
|
| 2902 |
-
)
|
| 2903 |
|
| 2904 |
-
|
| 2905 |
-
|
| 2906 |
-
|
| 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 |
-
|
| 2916 |
-
|
| 2917 |
-
|
| 2918 |
-
|
| 2919 |
-
|
| 2920 |
-
|
|
|
|
| 2921 |
|
| 2922 |
-
|
| 2923 |
-
|
| 2924 |
|
| 2925 |
-
|
| 2926 |
-
"๋ํ INCI": representative,
|
| 2927 |
-
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 2928 |
-
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 2929 |
-
"๋น๊ณ ": "๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 2930 |
-
}
|
| 2931 |
-
log_search_context(
|
| 2932 |
-
target_id,
|
| 2933 |
-
country,
|
| 2934 |
-
component,
|
| 2935 |
-
result["๊ฒฐ๊ณผ"],
|
| 2936 |
-
"COUNTRY_FILE_FAST_NO_HIT",
|
| 2937 |
-
f"cache_status={cache_status}",
|
| 2938 |
-
)
|
| 2939 |
-
return result
|
| 2940 |
|
| 2941 |
-
|
| 2942 |
-
|
| 2943 |
-
reg_kind = reg_type.get("type", "unknown")
|
| 2944 |
-
reg_label = reg_type.get("label", "๊ท์ ์ ํ ๋ฏธ๋ถ๋ฅ")
|
| 2945 |
-
context = best.get("context", "")
|
| 2946 |
-
evidence = context[:5000]
|
| 2947 |
-
lower = evidence.lower()
|
| 2948 |
|
| 2949 |
-
|
| 2950 |
-
|
| 2951 |
-
|
| 2952 |
-
lookup_terms=lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no],
|
| 2953 |
-
):
|
| 2954 |
-
result = {
|
| 2955 |
-
"๋ํ INCI": representative,
|
| 2956 |
-
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 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 |
-
|
| 2968 |
-
|
| 2969 |
|
| 2970 |
-
|
| 2971 |
-
target_id,
|
| 2972 |
-
country,
|
| 2973 |
-
component,
|
| 2974 |
-
result["๊ฒฐ๊ณผ"],
|
| 2975 |
-
"COUNTRY_FILE_BROAD_MATCH_IGNORED",
|
| 2976 |
-
context,
|
| 2977 |
-
)
|
| 2978 |
-
return result
|
| 2979 |
|
| 2980 |
-
|
| 2981 |
-
|
| 2982 |
-
|
| 2983 |
-
|
| 2984 |
-
|
| 2985 |
-
|
| 2986 |
-
|
| 2987 |
-
|
| 2988 |
-
|
| 2989 |
-
|
| 2990 |
-
|
| 2991 |
-
|
| 2992 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2993 |
|
| 2994 |
if reg_kind == "prohibited":
|
| 2995 |
result = {
|
| 2996 |
"๋ํ INCI": representative,
|
| 2997 |
-
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ํ์ธ",
|
| 2998 |
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 2999 |
-
"๋น๊ณ ":
|
| 3000 |
}
|
| 3001 |
-
log_search_context(
|
| 3002 |
-
target_id,
|
| 3003 |
-
country,
|
| 3004 |
-
component,
|
| 3005 |
-
result["๊ฒฐ๊ณผ"],
|
| 3006 |
-
"COUNTRY_FILE_ANNEX_II_PROHIBITED",
|
| 3007 |
-
context,
|
| 3008 |
-
)
|
| 3009 |
return result
|
| 3010 |
|
| 3011 |
-
# 2. Annex III / Restricted / Negative List
|
| 3012 |
-
# ํ๋ ์์น๊ฐ ์ถ์ถ๋๋ฉด ํ๋ ํ์, ์๋๋ฉด ํ์ธ ํ์.
|
| 3013 |
if reg_kind == "restricted":
|
| 3014 |
-
|
| 3015 |
-
evidence_text=context,
|
| 3016 |
-
ingredient_names=lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no],
|
| 3017 |
-
)
|
| 3018 |
-
|
| 3019 |
-
if verified is not None:
|
| 3020 |
-
display = verified["limit_text"]
|
| 3021 |
-
note = verified["evidence"]
|
| 3022 |
-
else:
|
| 3023 |
-
display = NEED_CHECK_TEXT
|
| 3024 |
-
note = evidence[:1000]
|
| 3025 |
-
|
| 3026 |
result = {
|
| 3027 |
"๋ํ INCI": representative,
|
| 3028 |
-
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ํ์ธ",
|
| 3029 |
-
"ํ์๋ฌธ๊ตฌ":
|
| 3030 |
-
"๋น๊ณ ":
|
| 3031 |
}
|
| 3032 |
-
log_search_context(
|
| 3033 |
-
target_id,
|
| 3034 |
-
country,
|
| 3035 |
-
component,
|
| 3036 |
-
result["๊ฒฐ๊ณผ"],
|
| 3037 |
-
"COUNTRY_FILE_ANNEX_III_RESTRICTED",
|
| 3038 |
-
context,
|
| 3039 |
-
)
|
| 3040 |
return result
|
| 3041 |
|
| 3042 |
-
|
| 3043 |
-
|
| 3044 |
-
if reg_kind in ["positive_colorant", "positive_preservative", "positive_uv"]:
|
| 3045 |
-
verified = extract_verified_limit_from_evidence(
|
| 3046 |
-
evidence_text=context,
|
| 3047 |
-
ingredient_names=lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no],
|
| 3048 |
-
)
|
| 3049 |
-
|
| 3050 |
-
if verified is not None:
|
| 3051 |
-
display = verified["limit_text"]
|
| 3052 |
-
note = verified["evidence"]
|
| 3053 |
-
else:
|
| 3054 |
-
# Positive List ๋ฑ์ฌ ์์ฒด๋ ๊ธ์ง/์ ํ์ด ์๋๋ผ ํ์ฉ๋ชฉ๋ก ํ์ธ.
|
| 3055 |
-
# ๋ค๋ง ์กฐ๊ฑด ๋ฌธ๊ตฌ๊ฐ ์์ ์ ์์ผ๋ฏ๋ก ์์ธ ๋น๊ณ ์ ๊ทผ๊ฑฐ๋ฅผ ๋จ๊น.
|
| 3056 |
-
display = "ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ"
|
| 3057 |
-
note = evidence[:1000]
|
| 3058 |
-
|
| 3059 |
result = {
|
| 3060 |
"๋ํ INCI": representative,
|
| 3061 |
-
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ํ์ธ",
|
| 3062 |
-
"ํ์๋ฌธ๊ตฌ":
|
| 3063 |
-
"๋น๊ณ ":
|
| 3064 |
}
|
| 3065 |
-
log_search_context(
|
| 3066 |
-
target_id,
|
| 3067 |
-
country,
|
| 3068 |
-
component,
|
| 3069 |
-
result["๊ฒฐ๊ณผ"],
|
| 3070 |
-
"COUNTRY_FILE_POSITIVE_LIST",
|
| 3071 |
-
context,
|
| 3072 |
-
)
|
| 3073 |
return result
|
| 3074 |
|
| 3075 |
-
#
|
| 3076 |
-
#
|
| 3077 |
-
|
| 3078 |
-
|
| 3079 |
-
|
| 3080 |
-
|
| 3081 |
-
|
| 3082 |
-
|
| 3083 |
-
|
| 3084 |
-
|
| 3085 |
-
log_search_context(
|
| 3086 |
-
target_id,
|
| 3087 |
-
country,
|
| 3088 |
-
component,
|
| 3089 |
-
result["๊ฒฐ๊ณผ"],
|
| 3090 |
-
"COUNTRY_FILE_GROUP_PROHIBITED",
|
| 3091 |
-
context,
|
| 3092 |
-
)
|
| 3093 |
-
return result
|
| 3094 |
|
| 3095 |
-
if reg_kind == "restricted" or "restricted" in lower or "restriction" in lower or "์ ํ" in evidence:
|
| 3096 |
-
result = {
|
| 3097 |
-
"๋ํ INCI": representative,
|
| 3098 |
-
"๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ๋ณ ํ์ผ์์ ๊ทธ๋ฃนํ ์ ํ ๊ทผ๊ฑฐ ํ์ธ",
|
| 3099 |
-
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 3100 |
-
"๋น๊ณ ": evidence[:1000],
|
| 3101 |
-
}
|
| 3102 |
-
log_search_context(
|
| 3103 |
-
target_id,
|
| 3104 |
-
country,
|
| 3105 |
-
component,
|
| 3106 |
-
result["๊ฒฐ๊ณผ"],
|
| 3107 |
-
"COUNTRY_FILE_GROUP_RESTRICTED",
|
| 3108 |
-
context,
|
| 3109 |
-
)
|
| 3110 |
-
return result
|
| 3111 |
|
| 3112 |
-
|
| 3113 |
-
|
| 3114 |
-
|
| 3115 |
-
|
| 3116 |
-
|
| 3117 |
-
|
| 3118 |
-
|
| 3119 |
-
|
| 3120 |
-
|
| 3121 |
-
|
| 3122 |
-
|
| 3123 |
-
|
| 3124 |
-
]
|
| 3125 |
|
| 3126 |
-
|
| 3127 |
-
|
| 3128 |
-
|
| 3129 |
-
|
| 3130 |
-
"shall not be used",
|
| 3131 |
-
"must not be used",
|
| 3132 |
-
"not be used in cosmetic products",
|
| 3133 |
-
"not be used in cosmetics",
|
| 3134 |
-
"forbidden",
|
| 3135 |
-
]
|
| 3136 |
|
| 3137 |
-
|
| 3138 |
-
|
| 3139 |
-
|
| 3140 |
-
|
| 3141 |
-
|
| 3142 |
-
]
|
| 3143 |
|
| 3144 |
-
if
|
| 3145 |
-
any(k in evidence for k in prohibited_keywords_ko)
|
| 3146 |
-
or any(k in lower for k in prohibited_keywords_en)
|
| 3147 |
-
or any(k in evidence for k in prohibited_keywords_jp_cn)
|
| 3148 |
-
):
|
| 3149 |
-
result = {
|
| 3150 |
-
"๋ํ INCI": representative,
|
| 3151 |
-
"๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ๋ณ ํ์ผ์์ ๊ธ์ง ๊ทผ๊ฑฐ ํ์ธ",
|
| 3152 |
-
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 3153 |
-
"๋น๊ณ ": evidence[:1000],
|
| 3154 |
-
}
|
| 3155 |
log_search_context(
|
| 3156 |
target_id,
|
| 3157 |
country,
|
| 3158 |
component,
|
| 3159 |
-
|
| 3160 |
-
"
|
| 3161 |
-
|
| 3162 |
)
|
| 3163 |
-
return
|
| 3164 |
-
|
| 3165 |
-
verified = extract_verified_limit_from_evidence(
|
| 3166 |
-
evidence_text=context,
|
| 3167 |
-
ingredient_names=lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no],
|
| 3168 |
-
)
|
| 3169 |
|
| 3170 |
-
if
|
| 3171 |
result = {
|
| 3172 |
-
"๋ํ INCI": representative,
|
| 3173 |
-
"๊ฒฐ๊ณผ":
|
| 3174 |
-
"ํ์๋ฌธ๊ตฌ":
|
| 3175 |
-
"๋น๊ณ ":
|
| 3176 |
}
|
| 3177 |
-
log_search_context(
|
| 3178 |
-
target_id,
|
| 3179 |
-
country,
|
| 3180 |
-
component,
|
| 3181 |
-
result["๊ฒฐ๊ณผ"],
|
| 3182 |
-
"COUNTRY_FILE_DIRECT_LIMIT",
|
| 3183 |
-
context,
|
| 3184 |
-
)
|
| 3185 |
return result
|
| 3186 |
|
| 3187 |
-
|
| 3188 |
-
|
| 3189 |
-
|
| 3190 |
-
|
| 3191 |
-
|
| 3192 |
-
|
| 3193 |
-
"์ดํ",
|
| 3194 |
-
"์ฃผ์",
|
| 3195 |
-
"๊ฒฝ๊ณ ",
|
| 3196 |
-
"ํ์",
|
| 3197 |
-
"๋ผ๋ฒจ",
|
| 3198 |
-
]
|
| 3199 |
-
|
| 3200 |
-
restriction_keywords_en = [
|
| 3201 |
-
"restriction",
|
| 3202 |
-
"restricted",
|
| 3203 |
-
"limit",
|
| 3204 |
-
"maximum",
|
| 3205 |
-
"max.",
|
| 3206 |
-
"warning",
|
| 3207 |
-
"label",
|
| 3208 |
-
"labelling",
|
| 3209 |
-
"labeling",
|
| 3210 |
-
"condition of use",
|
| 3211 |
-
"conditions of use",
|
| 3212 |
-
]
|
| 3213 |
|
| 3214 |
-
if
|
| 3215 |
-
|
| 3216 |
-
or any(k in lower for k in restriction_keywords_en)
|
| 3217 |
-
):
|
| 3218 |
-
result = {
|
| 3219 |
-
"๋ํ INCI": representative,
|
| 3220 |
-
"๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ๋ณ ํ์ผ์์ ์ ํ ๊ฐ๋ฅ ๋ฌธ๊ตฌ ํ์ธ / ์ธ๋ถ ์กฐ๊ฑด ํ์ธ ํ์",
|
| 3221 |
-
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 3222 |
-
"๋น๊ณ ": evidence[:1000],
|
| 3223 |
-
}
|
| 3224 |
-
log_search_context(
|
| 3225 |
-
target_id,
|
| 3226 |
-
country,
|
| 3227 |
-
component,
|
| 3228 |
-
result["๊ฒฐ๊ณผ"],
|
| 3229 |
-
"COUNTRY_FILE_DIRECT_RESTRICTION_KEYWORD",
|
| 3230 |
-
context,
|
| 3231 |
-
)
|
| 3232 |
-
return result
|
| 3233 |
|
| 3234 |
result = {
|
| 3235 |
"๋ํ INCI": representative,
|
| 3236 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3237 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3238 |
-
"๋น๊ณ ": "๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ
|
| 3239 |
}
|
| 3240 |
log_search_context(
|
| 3241 |
target_id,
|
| 3242 |
country,
|
| 3243 |
component,
|
| 3244 |
result["๊ฒฐ๊ณผ"],
|
| 3245 |
-
"
|
| 3246 |
-
|
| 3247 |
)
|
| 3248 |
return result
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
-
|
| 3253 |
def shorten_for_table(value, max_len=80):
|
| 3254 |
value = safe_str(value)
|
| 3255 |
|
|
@@ -3522,7 +3512,7 @@ def process_single_ingredient(
|
|
| 3522 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 3523 |
f"- MFDS ์ํ: {mfds_live_msg}\n"
|
| 3524 |
f"- MFDS ์กฐํ ๋์: {', '.join(terms) if terms else '์์'}\n"
|
| 3525 |
-
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์, ๊ตญ๊ฐ๋ณ ํ์ผ
|
| 3526 |
"- ๊ธ์ง ์ฑ๋ถ: ํจ๋ ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ํ์\n"
|
| 3527 |
"- ์์ฝ์ฒ ๋ธ๋ผ์ฐ์ ์คํจ ์์๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๊ฒ์ ๊ฒฐ๊ณผ๋ ๊ณ์ ํ์๋จ\n"
|
| 3528 |
"- MFDS ๊ท์ ๋งค์นญ 0ํ์ ์์ฝ์ฒ์์ ๊ธ์ง/์ ํ ์์ธ๊ฐ ํ์ธ๋์ง ์์๋ค๋ ์๋ฏธ\n"
|
|
|
|
| 537 |
# ============================================================
|
| 538 |
|
| 539 |
REGULATORY_SYNONYM_REGISTRY = [
|
| 540 |
+
{
|
| 541 |
+
"key": "edta_and_salts",
|
| 542 |
+
"canonical": "EDTA and salts",
|
| 543 |
+
"terms": [
|
| 544 |
+
"edta",
|
| 545 |
+
"EDTA",
|
| 546 |
+
"edta and salts",
|
| 547 |
+
"edta salts",
|
| 548 |
+
"edta and derivatives",
|
| 549 |
+
"ethylenediaminetetraacetic acid",
|
| 550 |
+
"ethylenediamine tetraacetic acid",
|
| 551 |
+
"edetic acid",
|
| 552 |
+
"edetate",
|
| 553 |
+
"edetates",
|
| 554 |
+
"disodium edta",
|
| 555 |
+
"Disodium EDTA",
|
| 556 |
+
"trisodium edta",
|
| 557 |
+
"Trisodium EDTA",
|
| 558 |
+
"tetrasodium edta",
|
| 559 |
+
"Tetrasodium EDTA",
|
| 560 |
+
"calcium disodium edta",
|
| 561 |
+
"Calcium Disodium EDTA",
|
| 562 |
+
"dipotassium edta",
|
| 563 |
+
"Dipotassium EDTA",
|
| 564 |
+
"diammonium edta",
|
| 565 |
+
"Diammonium EDTA",
|
| 566 |
+
"disodium edetate",
|
| 567 |
+
"Disodium Edetate",
|
| 568 |
+
"tetrasodium edetate",
|
| 569 |
+
"Tetrasodium Edetate",
|
| 570 |
+
"๋์๋์ด๋ํฐ์์ด",
|
| 571 |
+
"๋ค์ด์๋์ด๋ํฐ์์ด",
|
| 572 |
+
"๋์๋ ์ด๋ํฐ์์ด",
|
| 573 |
+
"๋ค์ด์๋ ์ด๋ํฐ์์ด",
|
| 574 |
+
"ํ
ํธ๋ผ์๋์ด๋ํฐ์์ด",
|
| 575 |
+
"ํ
ํธ๋ผ์๋ ์ด๋ํฐ์์ด",
|
| 576 |
+
"ํธ๋ฆฌ์๋์ด๋ํฐ์์ด",
|
| 577 |
+
"ํธ๋ฆฌ์๋ ์ด๋ํฐ์์ด",
|
| 578 |
+
"์นผ์๋์๋์ด๋ํฐ์์ด",
|
| 579 |
+
"์นผ์ ๋์๋ ์ด๋ํฐ์์ด",
|
| 580 |
+
"๋ํฌํ์์ด๋ํฐ์์ด",
|
| 581 |
+
"๋ํฌํ์ ์ด๋ํฐ์์ด",
|
| 582 |
+
"์๋ฐํธ์ฐ",
|
| 583 |
+
"์๋ฐํ
์ดํธ",
|
| 584 |
+
"์ด๋ํฐ์์ด",
|
| 585 |
+
"์ด๋ํฐ์์ด์ผ",
|
| 586 |
+
"EDTA์ผ",
|
| 587 |
+
],
|
| 588 |
+
},
|
| 589 |
+
{
|
| 590 |
"key": "dichlorobenzene",
|
| 591 |
"canonical": "Dichlorobenzene",
|
| 592 |
"terms": [
|
|
|
|
| 986 |
raw_terms.append(safe_str(reg_term))
|
| 987 |
|
| 988 |
expanded = []
|
| 989 |
+
strong_abbrev_allowlist = {"EDTA", "EDETATE", "BHT", "BHA", "MEA", "DEA", "TEA", "D4", "D5", "D6", "PFAS", "PFOA", "PFOS"}
|
| 990 |
salt_prefixes = [
|
| 991 |
"calcium disodium", "disodium", "trisodium", "tetrasodium", "sodium",
|
| 992 |
"dipotassium", "tripotassium", "tetrapotassium", "potassium",
|
|
|
|
| 2240 |
f"- In formula ํฉ๊ณ: {format_amount(sum_formula_percent(formula_df))}%\n"
|
| 2241 |
f"- ์ฌ๊ฒํ ํ์ ์ฑ๋ถ: {len(regulatory_df)}๊ฐ\n"
|
| 2242 |
f"- MFDS ์ํ: {mfds_msg}\n"
|
| 2243 |
+
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์ / ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ rowยทline ์ง์ ๊ฒ์\n"
|
| 2244 |
f"- ๊ตญ๊ฐ๋ณ ์ธ๋ฑ์ค ์ํ: {' | '.join(index_messages)}\n"
|
| 2245 |
"- ์๋ ๊ฐ์ : ์ ์ฒด ์คํฌ๋ฆฌ๋์์ GPT/LLM ํธ์ถ ์ ๊ฑฐ\n"
|
| 2246 |
)
|
|
|
|
| 2885 |
}
|
| 2886 |
|
| 2887 |
|
| 2888 |
+
|
| 2889 |
+
# ============================================================
|
| 2890 |
+
# ์์ค ํ์ผ ๊ธฐ๋ฐ ๊ท์ ์ธ๋ฑ์ค
|
| 2891 |
+
# - ์ฑ๋ถ๋ณ ํ๋์ฝ๋ฉ registry ๋์ , ๊ตญ๊ฐ ํด๋ ๋ด ์
๋ก๋๋ ๊ท์ ํ์ผ ์์ฒด๋ฅผ row/line ๋จ์๋ก ์ธ๋ฑ์ฑ
|
| 2892 |
+
# - ํ์ผ ์์์ ์ง์ ํ์ธ๋ ํ/๋ฌธ๋งฅ๋ง ๊ทผ๊ฑฐ๋ก ํ์
|
| 2893 |
+
# ============================================================
|
| 2894 |
+
|
| 2895 |
+
SOURCE_RECORD_INDEX_CACHE = {}
|
| 2896 |
+
|
| 2897 |
+
|
| 2898 |
+
def is_noise_source_row_text(text):
|
| 2899 |
+
text = safe_str(text)
|
| 2900 |
+
compact = normalize_compact(text)
|
| 2901 |
+
low = text.lower()
|
| 2902 |
+
|
| 2903 |
+
if not compact:
|
| 2904 |
+
return True
|
| 2905 |
+
|
| 2906 |
+
noise_terms = [
|
| 2907 |
+
"no", "๋ฒํธ", "์๋ฒ", "ingredientname", "inci", "function", "casno", "source",
|
| 2908 |
+
"๊ตฌ๋ถ", "๊ตญ๊ฐ", "๊ณ ์์๋ฃ๋ช
", "๋จ์์กฐํญ", "์ ํ์ฌํญ", "๊ธฐ์ค์ผ์",
|
| 2909 |
+
"productname", "formularingredientsstatement", "formulaingredientsstatement",
|
| 2910 |
+
]
|
| 2911 |
+
|
| 2912 |
+
# header-only row
|
| 2913 |
+
hit = sum(1 for n in noise_terms if n in compact)
|
| 2914 |
+
if hit >= 4 and len(compact) < 120:
|
| 2915 |
+
return True
|
| 2916 |
+
|
| 2917 |
+
if "copyright" in low or "page " in low:
|
| 2918 |
+
return True
|
| 2919 |
+
|
| 2920 |
+
return False
|
| 2921 |
+
|
| 2922 |
+
|
| 2923 |
+
def source_match_terms_for_component(material=None, component=None):
|
| 2924 |
"""
|
| 2925 |
+
ํ์ผ ์ง์ ๋งค์นญ์ ์ฌ์ฉํ ๊ฒ์์ด.
|
| 2926 |
+
broad alias ์์ฑ ๊ธ์ง. ์
๋ ฅ ์ฑ๋ถ๋ช
/๊ตญ๋ฌธ/CAS/์๋ฃ๋ช
๋ง ์ฌ์ฉ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2927 |
"""
|
| 2928 |
+
material = material or {}
|
| 2929 |
+
component = component or {}
|
| 2930 |
|
| 2931 |
+
terms = []
|
|
|
|
|
|
|
| 2932 |
|
| 2933 |
+
for v in [
|
| 2934 |
+
component.get("INCI Name", ""),
|
| 2935 |
+
component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""),
|
| 2936 |
+
component.get("CAS.No", ""),
|
| 2937 |
+
material.get("Trade name(๊ตญ๋ฌธ)", ""),
|
| 2938 |
+
material.get("Trade name(์๋ฌธ)", ""),
|
| 2939 |
+
]:
|
| 2940 |
+
v = safe_str(v)
|
| 2941 |
|
| 2942 |
+
if not v:
|
| 2943 |
+
continue
|
|
|
|
|
|
|
|
|
|
| 2944 |
|
| 2945 |
+
# ์๋ฃํ์์ ์๊ธด header/๋ฉํ๊ฐ ๋ฐฉ์ง
|
| 2946 |
+
if normalize_compact(v) in [
|
| 2947 |
+
"ingredientname", "ingredientnameinci", "function", "casno", "source",
|
| 2948 |
+
"productname", "no", "๋ฒํธ",
|
| 2949 |
+
]:
|
| 2950 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2951 |
|
| 2952 |
+
if len(normalize_compact(v)) >= 3 and v not in terms:
|
| 2953 |
+
terms.append(v)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2954 |
|
| 2955 |
+
return terms
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2956 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2957 |
|
| 2958 |
+
def infer_record_regulation_type(country, source_file, sheet_name="", row_text=""):
|
| 2959 |
+
basis = f"{source_file}\n{sheet_name}\n{row_text[:1500]}"
|
| 2960 |
+
return infer_regulation_type_from_source_text(basis, country=country)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2961 |
|
|
|
|
|
|
|
| 2962 |
|
| 2963 |
+
def build_country_source_record_index(country):
|
| 2964 |
+
"""
|
| 2965 |
+
๊ตญ๊ฐ๋ณ ๊ท์ ํ์ผ์ row/line ๋จ์ record๋ก ๋ง๋ ๋ค.
|
| 2966 |
+
Excel/CSV: row ๋จ์
|
| 2967 |
+
PDF/TXT: line window ๋จ์
|
| 2968 |
+
"""
|
| 2969 |
+
folder = resolve_country_folder(country)
|
| 2970 |
|
| 2971 |
+
if not folder or not os.path.isdir(folder):
|
| 2972 |
+
return [], "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ํด๋ ์์"
|
| 2973 |
|
| 2974 |
+
files = get_regulatory_file_list(folder)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2975 |
|
| 2976 |
+
if not files:
|
| 2977 |
+
return [], "ํด๋น ๊ตญ๊ฐ/์ฑ๋ ๊ท์ ํ์ผ ์์"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2978 |
|
| 2979 |
+
signature = tuple((f["relative_path"], f["size"], f["mtime_ns"]) for f in files)
|
| 2980 |
+
sig_hash = stable_hash(signature)
|
| 2981 |
+
cache_key = f"{folder}|source_records|{sig_hash}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2982 |
|
| 2983 |
+
if cache_key in SOURCE_RECORD_INDEX_CACHE:
|
| 2984 |
+
return SOURCE_RECORD_INDEX_CACHE[cache_key], "MEMORY_CACHE"
|
| 2985 |
|
| 2986 |
+
records = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2987 |
|
| 2988 |
+
for item in files:
|
| 2989 |
+
path = item["path"]
|
| 2990 |
+
rel = item["relative_path"]
|
| 2991 |
+
ext = item["ext"]
|
| 2992 |
+
|
| 2993 |
+
try:
|
| 2994 |
+
if ext in [".xlsx", ".xls"]:
|
| 2995 |
+
sheets = pd.read_excel(path, sheet_name=None, header=None, dtype=str)
|
| 2996 |
+
|
| 2997 |
+
for sheet_name, df in sheets.items():
|
| 2998 |
+
df = df.fillna("")
|
| 2999 |
+
|
| 3000 |
+
for ridx, row in df.iterrows():
|
| 3001 |
+
cells = [safe_str(x) for x in row.tolist() if safe_str(x)]
|
| 3002 |
+
row_text = " | ".join(cells)
|
| 3003 |
+
|
| 3004 |
+
if is_noise_source_row_text(row_text):
|
| 3005 |
+
continue
|
| 3006 |
+
|
| 3007 |
+
reg_type = infer_record_regulation_type(country, rel, sheet_name, row_text)
|
| 3008 |
+
|
| 3009 |
+
records.append({
|
| 3010 |
+
"country": display_country(country),
|
| 3011 |
+
"source_file": rel,
|
| 3012 |
+
"sheet": safe_str(sheet_name),
|
| 3013 |
+
"row_index": int(ridx) + 1,
|
| 3014 |
+
"text": row_text,
|
| 3015 |
+
"text_norm": normalize_compact(row_text),
|
| 3016 |
+
"regulation_type": reg_type,
|
| 3017 |
+
})
|
| 3018 |
+
|
| 3019 |
+
elif ext == ".csv":
|
| 3020 |
+
try:
|
| 3021 |
+
df = pd.read_csv(path, header=None, dtype=str).fillna("")
|
| 3022 |
+
except UnicodeDecodeError:
|
| 3023 |
+
df = pd.read_csv(path, header=None, dtype=str, encoding="cp949").fillna("")
|
| 3024 |
+
|
| 3025 |
+
for ridx, row in df.iterrows():
|
| 3026 |
+
cells = [safe_str(x) for x in row.tolist() if safe_str(x)]
|
| 3027 |
+
row_text = " | ".join(cells)
|
| 3028 |
+
|
| 3029 |
+
if is_noise_source_row_text(row_text):
|
| 3030 |
+
continue
|
| 3031 |
+
|
| 3032 |
+
reg_type = infer_record_regulation_type(country, rel, "", row_text)
|
| 3033 |
+
|
| 3034 |
+
records.append({
|
| 3035 |
+
"country": display_country(country),
|
| 3036 |
+
"source_file": rel,
|
| 3037 |
+
"sheet": "",
|
| 3038 |
+
"row_index": int(ridx) + 1,
|
| 3039 |
+
"text": row_text,
|
| 3040 |
+
"text_norm": normalize_compact(row_text),
|
| 3041 |
+
"regulation_type": reg_type,
|
| 3042 |
+
})
|
| 3043 |
+
|
| 3044 |
+
else:
|
| 3045 |
+
raw = extract_text_from_regulatory_file(item)
|
| 3046 |
+
lines = [safe_str(x) for x in raw.splitlines() if safe_str(x)]
|
| 3047 |
+
|
| 3048 |
+
for i, line in enumerate(lines):
|
| 3049 |
+
if is_noise_source_row_text(line):
|
| 3050 |
+
continue
|
| 3051 |
+
|
| 3052 |
+
window = "\n".join(lines[max(0, i - 3): min(len(lines), i + 4)])
|
| 3053 |
+
reg_type = infer_record_regulation_type(country, rel, "", window)
|
| 3054 |
+
|
| 3055 |
+
records.append({
|
| 3056 |
+
"country": display_country(country),
|
| 3057 |
+
"source_file": rel,
|
| 3058 |
+
"sheet": "",
|
| 3059 |
+
"row_index": i + 1,
|
| 3060 |
+
"text": window,
|
| 3061 |
+
"text_norm": normalize_compact(window),
|
| 3062 |
+
"regulation_type": reg_type,
|
| 3063 |
+
})
|
| 3064 |
+
|
| 3065 |
+
except Exception as e:
|
| 3066 |
+
print(f"source record index error: {path} / {e}")
|
| 3067 |
+
|
| 3068 |
+
SOURCE_RECORD_INDEX_CACHE[cache_key] = records
|
| 3069 |
+
return records, "BUILT_SOURCE_RECORD_INDEX"
|
| 3070 |
+
|
| 3071 |
+
|
| 3072 |
+
def pick_best_source_record(records):
|
| 3073 |
+
priority = {
|
| 3074 |
+
"prohibited": 100,
|
| 3075 |
+
"restricted": 80,
|
| 3076 |
+
"positive_uv": 50,
|
| 3077 |
+
"positive_preservative": 50,
|
| 3078 |
+
"positive_colorant": 50,
|
| 3079 |
+
"unknown": 10,
|
| 3080 |
+
}
|
| 3081 |
+
|
| 3082 |
+
return sorted(
|
| 3083 |
+
records,
|
| 3084 |
+
key=lambda r: priority.get(r.get("regulation_type", {}).get("type", "unknown"), 0),
|
| 3085 |
+
reverse=True,
|
| 3086 |
+
)[0] if records else None
|
| 3087 |
+
|
| 3088 |
+
|
| 3089 |
+
def evaluate_component_from_uploaded_source_records(country, material, component, target_id=""):
|
| 3090 |
+
"""
|
| 3091 |
+
๊ตญ๊ฐ ํด๋ ํ์ผ๋ง ๋ณด๊ณ ํ์ .
|
| 3092 |
+
ํ์ผ record ์์ ํ์ฌ ์ฑ๋ถ๋ช
/๊ตญ๋ฌธ/CAS๊ฐ ์ง์ ์์ ๋๋ง ํ์ ํ๋ค.
|
| 3093 |
+
"""
|
| 3094 |
+
terms = source_match_terms_for_component(material, component)
|
| 3095 |
+
term_norms = [normalize_compact(t) for t in terms if len(normalize_compact(t)) >= 3]
|
| 3096 |
+
|
| 3097 |
+
representative = (
|
| 3098 |
+
safe_str(component.get("INCI Name", ""))
|
| 3099 |
+
or safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 3100 |
+
or safe_str(component.get("CAS.No", ""))
|
| 3101 |
+
or "-"
|
| 3102 |
+
)
|
| 3103 |
+
|
| 3104 |
+
if not term_norms:
|
| 3105 |
+
return None
|
| 3106 |
+
|
| 3107 |
+
records, status = build_country_source_record_index(country)
|
| 3108 |
+
hits = []
|
| 3109 |
+
|
| 3110 |
+
for rec in records:
|
| 3111 |
+
rec_norm = rec.get("text_norm", "")
|
| 3112 |
+
|
| 3113 |
+
if any(tn in rec_norm for tn in term_norms):
|
| 3114 |
+
hits.append(rec)
|
| 3115 |
+
|
| 3116 |
+
if not hits:
|
| 3117 |
+
return None
|
| 3118 |
+
|
| 3119 |
+
best = pick_best_source_record(hits)
|
| 3120 |
+
reg_type = best.get("regulation_type", {})
|
| 3121 |
+
reg_kind = reg_type.get("type", "unknown")
|
| 3122 |
+
reg_label = reg_type.get("label", "๊ท์ ์ ํ ๋ฏธ๋ถ๋ฅ")
|
| 3123 |
+
context = best.get("text", "")
|
| 3124 |
+
country_col = display_country(country)
|
| 3125 |
|
| 3126 |
if reg_kind == "prohibited":
|
| 3127 |
result = {
|
| 3128 |
"๋ํ INCI": representative,
|
| 3129 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ",
|
| 3130 |
"ํ์๋ฌธ๊ตฌ": "๋ฐฐํฉ๊ธ์ง",
|
| 3131 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3132 |
}
|
| 3133 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_PROHIBITED", result["๋น๊ณ "])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3134 |
return result
|
| 3135 |
|
|
|
|
|
|
|
| 3136 |
if reg_kind == "restricted":
|
| 3137 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3138 |
result = {
|
| 3139 |
"๋ํ INCI": representative,
|
| 3140 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 3141 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else NEED_CHECK_TEXT,
|
| 3142 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3143 |
}
|
| 3144 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_RESTRICTED", result["๋น๊ณ "])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3145 |
return result
|
| 3146 |
|
| 3147 |
+
if reg_kind.startswith("positive_"):
|
| 3148 |
+
limit_text, condition_text = extract_limit_condition_from_context(context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3149 |
result = {
|
| 3150 |
"๋ํ INCI": representative,
|
| 3151 |
+
"๊ฒฐ๊ณผ": f"{country_col} {reg_label}์์ ์ฑ๋ถ ์ง์ ํ์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
|
| 3152 |
+
"ํ์๋ฌธ๊ตฌ": f"๋ฐฐํฉํ๋: {limit_text}" if limit_text else "ํ์ฉ๋ชฉ๋ก ๋ฑ์ฌ / ํ๋ ํ์ธ ํ์",
|
| 3153 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3154 |
}
|
| 3155 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_POSITIVE", result["๋น๊ณ "])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3156 |
return result
|
| 3157 |
|
| 3158 |
+
# ํ์ผ์์๋ ์ฑ๋ถ์ ์ฐพ์์ง๋ง ํ์ผ ์ ํ์ด ๋ถ๋ช
ํํ ๊ฒฝ์ฐ:
|
| 3159 |
+
# PASS๋ก ๋จ์ ํ์ง ์๊ณ ํ์ธ ํ์๋ก ํ์. ๋จ, ์ด ๊ฒฝ์ฐ๋ "ํ์ผ ์ง์ ํ์ธ"์ ๋จ๊ธด๋ค.
|
| 3160 |
+
result = {
|
| 3161 |
+
"๋ํ INCI": representative,
|
| 3162 |
+
"๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ๋ณ ํ์ผ์์ ์ฑ๋ถ ์ง์ ํ์ธ / ํ์ผ ์ ํ ๋ฏธ๋ถ๋ฅ",
|
| 3163 |
+
"ํ์๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
|
| 3164 |
+
"๋น๊ณ ": f"[์ถ์ฒํ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
|
| 3165 |
+
}
|
| 3166 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_UNKNOWN", result["๋น๊ณ "])
|
| 3167 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3169 |
|
| 3170 |
+
def evaluate_component_from_country_files_only(country, material, component, target_id=""):
|
| 3171 |
+
"""
|
| 3172 |
+
๊ตญ๊ฐ๋ณ ์
๋ก๋ ํ์ผ ๊ธฐ๋ฐ ํ์ .
|
| 3173 |
+
์ฑ๋ถ๋ณ ํ๋์ฝ๋ฉ registry๋ณด๋ค ์
๋ก๋๋ ๊ตญ๊ฐ ํ์ผ row/line record๋ฅผ ์ฐ์ ์ฌ์ฉํ๋ค.
|
| 3174 |
+
|
| 3175 |
+
์์น:
|
| 3176 |
+
- ์
๋ก๋ ํ์ผ record์ ํ์ฌ ์ฑ๋ถ๋ช
/๊ตญ๋ฌธ/CAS๊ฐ ์ง์ ์์ผ๋ฉด ๊ทธ ํ์ผ ์ ํ์ ๋ฐ๋ผ ํ์
|
| 3177 |
+
- ๊ธ์ง/์ ํ/Positive List ํ์ผ๋ช
๋๋ row ๋ฌธ๋งฅ์ผ๋ก ์ ํ ํ๋จ
|
| 3178 |
+
- ํ์ผ์์ ์ง์ ๊ทผ๊ฑฐ๊ฐ ์์ผ๋ฉด Pass
|
| 3179 |
+
- broad alias/glycol/extract ๊ฐ์ ๋์ ๊ฒ์์ด๋ก ๊ธ์ง/์ ํ ๋ง๋ค์ง ์์
|
| 3180 |
+
"""
|
| 3181 |
+
country_col = display_country(country)
|
|
|
|
| 3182 |
|
| 3183 |
+
inci_name = safe_str(component.get("INCI Name", ""))
|
| 3184 |
+
korean_name = safe_str(component.get("ํ๊ธ ์ฑ๋ถ๋ช
", ""))
|
| 3185 |
+
cas_no = safe_str(component.get("CAS.No", ""))
|
| 3186 |
+
representative = inci_name or korean_name or cas_no or "-"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3187 |
|
| 3188 |
+
critical_result = evaluate_critical_country_rule(
|
| 3189 |
+
country=country,
|
| 3190 |
+
material=material,
|
| 3191 |
+
component=component,
|
| 3192 |
+
)
|
|
|
|
| 3193 |
|
| 3194 |
+
if critical_result is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3195 |
log_search_context(
|
| 3196 |
target_id,
|
| 3197 |
country,
|
| 3198 |
component,
|
| 3199 |
+
critical_result.get("๊ฒฐ๊ณผ", ""),
|
| 3200 |
+
"CRITICAL_COUNTRY_RULE",
|
| 3201 |
+
critical_result.get("๋น๊ณ ", "-"),
|
| 3202 |
)
|
| 3203 |
+
return critical_result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3204 |
|
| 3205 |
+
if is_always_pass_component(material, component):
|
| 3206 |
result = {
|
| 3207 |
+
"๋ํ INCI": representative if representative != "-" else "Water",
|
| 3208 |
+
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3209 |
+
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3210 |
+
"๋น๊ณ ": "์ ์ ์/Water/Aqua ๊ธฐ๋ณธ Pass ์ฒ๋ฆฌ",
|
| 3211 |
}
|
| 3212 |
+
log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "ALWAYS_PASS_RULE", result["๋น๊ณ "])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3213 |
return result
|
| 3214 |
|
| 3215 |
+
source_result = evaluate_component_from_uploaded_source_records(
|
| 3216 |
+
country=country,
|
| 3217 |
+
material=material,
|
| 3218 |
+
component=component,
|
| 3219 |
+
target_id=target_id,
|
| 3220 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3221 |
|
| 3222 |
+
if source_result is not None:
|
| 3223 |
+
return source_result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3224 |
|
| 3225 |
result = {
|
| 3226 |
"๋ํ INCI": representative,
|
| 3227 |
"๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
|
| 3228 |
"ํ์๋ฌธ๊ตฌ": "Pass",
|
| 3229 |
+
"๋น๊ณ ": "์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๋ด ํ์ฌ ์ฑ๋ถ ์ง์ ๊ทผ๊ฑฐ ์์",
|
| 3230 |
}
|
| 3231 |
log_search_context(
|
| 3232 |
target_id,
|
| 3233 |
country,
|
| 3234 |
component,
|
| 3235 |
result["๊ฒฐ๊ณผ"],
|
| 3236 |
+
"UPLOADED_SOURCE_RECORD_NO_HIT",
|
| 3237 |
+
result["๋น๊ณ "],
|
| 3238 |
)
|
| 3239 |
return result
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
|
|
|
| 3243 |
def shorten_for_table(value, max_len=80):
|
| 3244 |
value = safe_str(value)
|
| 3245 |
|
|
|
|
| 3512 |
f"- ์ ํ ๊ตญ๊ฐ ์: {len(countries)}๊ฐ\n"
|
| 3513 |
f"- MFDS ์ํ: {mfds_live_msg}\n"
|
| 3514 |
f"- MFDS ์กฐํ ๋์: {', '.join(terms) if terms else '์์'}\n"
|
| 3515 |
+
"- ํ์ ๋ฐฉ์: GPT ํ์ ์์, ์
๋ก๋๋ ๊ตญ๊ฐ๋ณ ํ์ผ row/line ์ง์ ๊ฒ์ + ์์ฝ์ฒ ์ฒดํฌ ON ์ ์ค์๊ฐ ๊ฒฐ๊ณผ ์ฌ์ฉ\n"
|
| 3516 |
"- ๊ธ์ง ์ฑ๋ถ: ํจ๋ ์ ๋ฌด์ ๋ฌด๊ดํ๊ฒ ๋ฐฐํฉ๊ธ์ง ์ฐ์ ํ์\n"
|
| 3517 |
"- ์์ฝ์ฒ ๋ธ๋ผ์ฐ์ ์คํจ ์์๋ ๊ตญ๊ฐ๋ณ ํ์ผ ๊ฒ์ ๊ฒฐ๊ณผ๋ ๊ณ์ ํ์๋จ\n"
|
| 3518 |
"- MFDS ๊ท์ ๋งค์นญ 0ํ์ ์์ฝ์ฒ์์ ๊ธ์ง/์ ํ ์์ธ๊ฐ ํ์ธ๋์ง ์์๋ค๋ ์๋ฏธ\n"
|