jin2li commited on
Commit
73d3ca1
ยท
verified ยท
1 Parent(s): e97f1c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +338 -348
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 ํŒ์ • ์—†์Œ / ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์ง์ ‘ ๊ฒ€์ƒ‰ / COUNTRY_FILE_FAST\n"
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
- def evaluate_component_from_country_files_only(country, material, component, target_id=""):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2840
  """
2841
- GPT ํŒ์ • ์—†์ด ์‚ฌ์šฉ์ž๊ฐ€ ์—…๋ฐ์ดํŠธํ•œ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ๋งŒ ์ง์ ‘ ๊ฒ€์ƒ‰ํ•ด์„œ ํŒ์ •ํ•œ๋‹ค.
2842
-
2843
- ๋ณธ์งˆ์  ๊ฐœ์„ :
2844
- - ์„ฑ๋ถ„ ์ฃผ๋ณ€ ๋ฌธ์žฅ์— '๊ธˆ์ง€' ํ‚ค์›Œ๋“œ๊ฐ€ ์—†๋”๋ผ๋„,
2845
- Annex II / Prohibited / Negative List ํŒŒ์ผ์—์„œ ๋ฐœ๊ฒฌ๋˜๋ฉด ๋ฐฐํ•ฉ๊ธˆ์ง€๋กœ ํŒ์ •ํ•œ๋‹ค.
2846
- - Annex III / Restricted ํŒŒ์ผ์—์„œ ๋ฐœ๊ฒฌ๋˜๋ฉด ์ œํ•œ ์„ฑ๋ถ„์œผ๋กœ ํŒ์ •ํ•œ๋‹ค.
2847
- - Annex IV/V/VI Positive List์—์„œ ๋ฐœ๊ฒฌ๋˜๋ฉด ํ•ด๋‹น ๋ชฉ์ ์˜ ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ๋กœ ํŒ์ •ํ•œ๋‹ค.
2848
- - ํ•จ๋Ÿ‰ ๏ฟฝ๏ฟฝ๏ฟฝ๋ฌด๋Š” ๊ธˆ์ง€ ํŒ๋‹จ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๋Š”๋‹ค.
2849
  """
2850
- country_col = display_country(country)
 
2851
 
2852
- inci_name = safe_str(component.get("INCI Name", ""))
2853
- korean_name = safe_str(component.get("ํ•œ๊ธ€ ์„ฑ๋ถ„๋ช…", ""))
2854
- cas_no = safe_str(component.get("CAS.No", ""))
2855
 
2856
- representative = inci_name or korean_name or cas_no or "-"
 
 
 
 
 
 
 
2857
 
2858
- critical_result = evaluate_critical_country_rule(
2859
- country=country,
2860
- material=material,
2861
- component=component,
2862
- )
2863
 
2864
- if critical_result is not None:
2865
- log_search_context(
2866
- target_id,
2867
- country,
2868
- component,
2869
- critical_result.get("๊ฒฐ๊ณผ", ""),
2870
- "CRITICAL_COUNTRY_RULE",
2871
- critical_result.get("๋น„๊ณ ", "-"),
2872
- )
2873
- return critical_result
2874
 
2875
- if is_always_pass_component(material, component):
2876
- result = {
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
- lookup_terms = build_ingredient_lookup_terms(
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
- 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,
2918
- component=component,
2919
- target_id=target_id,
2920
- )
 
2921
 
2922
- if alias_result is not None:
2923
- return alias_result
2924
 
2925
- result = {
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
- best = pick_best_regulatory_match(matches)
2942
- reg_type = best.get("regulation_type", {"type": "unknown", "label": "๊ทœ์ œ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜"})
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
- if not validate_country_file_match_context(
2950
- context=context,
2951
- component=component,
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
- if registry_result is not None:
2968
- return registry_result
2969
 
2970
- log_search_context(
2971
- target_id,
2972
- country,
2973
- component,
2974
- result["๊ฒฐ๊ณผ"],
2975
- "COUNTRY_FILE_BROAD_MATCH_IGNORED",
2976
- context,
2977
- )
2978
- return result
2979
 
2980
- # 1. Annex II / Prohibited / Negative List
2981
- # ํ•ต์‹ฌ: ์„ฑ๋ถ„ ์ฃผ๋ณ€์— ๊ธˆ์ง€๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ์—†์–ด๋„ ํ•ด๋‹น ํŒŒ์ผ์—์„œ ๋ฐœ๊ฒฌ๋˜๋ฉด ๋ฐฐํ•ฉ๊ธˆ์ง€.
2982
- if reg_kind == "restricted" or reg_kind.startswith("positive_"):
2983
- result = make_restricted_or_positive_result(country, component, best, reg_type)
2984
- log_search_context(
2985
- target_id,
2986
- country,
2987
- component,
2988
- result["๊ฒฐ๊ณผ"],
2989
- "COUNTRY_FILE_FAST",
2990
- result["๋น„๊ณ "],
2991
- )
2992
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2993
 
2994
  if reg_kind == "prohibited":
2995
  result = {
2996
  "๋Œ€ํ‘œ INCI": representative,
2997
- "๊ฒฐ๊ณผ": f"{country_col} {reg_label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ",
2998
  "ํ‘œ์‹œ๋ฌธ๊ตฌ": "๋ฐฐํ•ฉ๊ธˆ์ง€",
2999
- "๋น„๊ณ ": evidence[:1000],
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
- verified = extract_verified_limit_from_evidence(
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
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": display,
3030
- "๋น„๊ณ ": note,
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
- # 3. Annex IV/V/VI Positive List
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
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": display,
3063
- "๋น„๊ณ ": note,
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
- # 4. ๊ทธ๋ฃนํ˜• ๊ธˆ์ง€/์ œํ•œ ๋ฌธ๊ตฌ ๋ณด์กฐ ํŒ๋‹จ
3076
- # ์˜ˆ: "EDTA and derivatives Prohibited", "X and salts restricted"
3077
- if context_has_group_regulation_for_terms(context, lookup_terms if "lookup_terms" in locals() else [inci_name, korean_name, cas_no]):
3078
- if reg_kind == "prohibited" or "prohibited" in lower or "banned" in lower or "๊ธˆ์ง€" in evidence:
3079
- result = {
3080
- "๋Œ€ํ‘œ INCI": representative,
3081
- "๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ๊ทธ๋ฃนํ˜• ๊ธˆ์ง€ ๊ทผ๊ฑฐ ํ™•์ธ",
3082
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": "๋ฐฐํ•ฉ๊ธˆ์ง€",
3083
- "๋น„๊ณ ": evidence[:1000],
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
- # 4. ํŒŒ์ผ ์œ ํ˜•์„ ๋ชป ์•Œ์•„๋‚ธ ๊ฒฝ์šฐ์—๋งŒ ๊ธฐ์กด ํ‚ค์›Œ๋“œ ๋ฐฉ์‹์œผ๋กœ ๋ณด์กฐ ํŒ๋‹จ
3113
- prohibited_keywords_ko = [
3114
- "๋ฐฐํ•ฉ๊ธˆ์ง€",
3115
- "์‚ฌ์šฉ๊ธˆ์ง€",
3116
- "์‚ฌ์šฉ ๊ธˆ์ง€",
3117
- "๊ธˆ์ง€์›๋ฃŒ",
3118
- "๊ธˆ์ง€ ์›๋ฃŒ",
3119
- "๊ธˆ์ง€์„ฑ๋ถ„",
3120
- "๊ธˆ์ง€ ์„ฑ๋ถ„",
3121
- "์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค",
3122
- "์‚ฌ์šฉํ•˜์—ฌ์„œ๋Š” ์•„๋‹ˆ",
3123
- "ํ™”์žฅํ’ˆ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Œ",
3124
- ]
3125
 
3126
- prohibited_keywords_en = [
3127
- "prohibited",
3128
- "banned",
3129
- "not allowed",
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
- prohibited_keywords_jp_cn = [
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
- result["๊ฒฐ๊ณผ"],
3160
- "COUNTRY_FILE_DIRECT_PROHIBITED_KEYWORD",
3161
- context,
3162
  )
3163
- return result
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 verified is not None:
3171
  result = {
3172
- "๋Œ€ํ‘œ INCI": representative,
3173
- "๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ๋ฐฐํ•ฉํ•œ๋„ ๊ทผ๊ฑฐ ํ™•์ธ",
3174
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": verified["limit_text"],
3175
- "๋น„๊ณ ": verified["evidence"],
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
- restriction_keywords_ko = [
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
- any(k in evidence for k in restriction_keywords_ko)
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
- "COUNTRY_FILE_DIRECT_UNCLASSIFIED",
3246
- context,
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 ํŒ์ • ์—†์Œ, ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ ์ž๋™ ์บ์‹œ ๊ฒ€์ƒ‰ + ์‹์•ฝ์ฒ˜ ์ฒดํฌ ON ์‹œ ์‹ค์‹œ๊ฐ„ ๊ฒฐ๊ณผ ์‚ฌ์šฉ\n"
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"