jin2li commited on
Commit
1efc57c
ยท
verified ยท
1 Parent(s): e4fdf3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +154 -74
app.py CHANGED
@@ -75,6 +75,17 @@ REG_INDEX_CACHE_DIR = ".reg_index_cache"
75
  NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
76
  NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
77
  LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
 
 
 
 
 
 
 
 
 
 
 
78
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
79
  # ์†๋„ ์‘๊ธ‰ํŒจ์น˜
80
  # - ์ „์ฒด ์ „์„ฑ๋ถ„ ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” MFDS ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
@@ -2203,14 +2214,15 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
2203
  final_result = None
2204
  source = ""
2205
 
2206
- final_result = evaluate_critical_country_rule(
2207
- country=country,
2208
- material=mat,
2209
- component=comp,
2210
- )
 
2211
 
2212
- if final_result is not None:
2213
- source = "CRITICAL_COUNTRY_RULE"
2214
 
2215
  if final_result is None and is_always_pass_component(mat, comp):
2216
  final_result = {
@@ -2221,7 +2233,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
2221
  }
2222
  source = "ALWAYS_PASS_RULE"
2223
 
2224
- if final_result is None:
2225
  fragrance_result = evaluate_plain_fragrance_rule(
2226
  country=country,
2227
  material=mat,
@@ -2256,7 +2268,7 @@ def process(countries,file,product_name="",use_mfds_live=False,live_max_terms=5,
2256
  final_result = file_result
2257
  source = "COUNTRY_FILE_FAST"
2258
 
2259
- if final_result is None:
2260
  local_result = evaluate_local_rules(
2261
  country=country,
2262
  material=mat,
@@ -2903,32 +2915,81 @@ def warmup_country_indexes(countries):
2903
 
2904
 
2905
  def extract_limit_condition_from_context(context):
 
 
 
 
 
 
 
 
2906
  text = safe_str(context)
2907
  compact = re.sub(r"\s+", " ", text).strip()
 
2908
  if not compact:
2909
  return "", ""
2910
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2911
  patterns = [
2912
  r"([0-9]+(?:\.[0-9]+)?\s*%)",
2913
- r"([0-9]+(?:\.[0-9]+)?\s*ppm)",
2914
  r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
2915
  r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
2916
- r"([0-9]+(?:\.[0-9]+)?\s*mg\s*/\s*kg)",
2917
  ]
 
2918
  limits = []
2919
  for pat in patterns:
2920
- for m in re.finditer(pat, compact, flags=re.IGNORECASE):
2921
  v = m.group(1).replace(" ", "")
2922
  if v not in limits:
2923
  limits.append(v)
2924
 
 
 
 
 
 
 
 
 
 
2925
  condition_keywords = [
2926
  "leave-on", "rinse-off", "oral", "mucosa", "washed away",
2927
  "๋ณด์กด์ œ", "๋ฐฉ๋ถ€์ œ", "์ž์™ธ์„ ", "์ƒ‰์†Œ", "์ ๋ง‰", "๊ตฌ๊ฐ•",
2928
- "์ œํ•œ์‚ฌํ•ญ", "๊ฒฝ๊ณ ", "warning", "condition", "ํ•œ๋„", "์ œํ•œ",
2929
  ]
 
2930
  condition_lines = []
2931
- for line in [safe_str(x) for x in text.splitlines() if safe_str(x)]:
2932
  l = line.lower()
2933
  if any(k.lower() in l for k in condition_keywords):
2934
  cleaned = re.sub(r"\s+", " ", line).strip()
@@ -2949,8 +3010,8 @@ def make_restricted_or_positive_result(country, component, match, reg_type):
2949
  display = f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}"
2950
  result = f"{display_country(country)} {label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ / ํ•œ๋„ {limit_text}"
2951
  elif kind.startswith("positive_"):
2952
- display = "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ / ํ•œ๋„ ํ™•์ธ ํ•„์š”"
2953
- result = f"{display_country(country)} {label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ / ๋ชฉ์ ๋ณ„ ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ, ํ•œ๋„ยท์กฐ๊ฑด ํ™•์ธ ํ•„์š”"
2954
  else:
2955
  display = "๋ฐฐํ•ฉํ•œ๋„/์ œํ•œ ํ™•์ธ"
2956
  result = f"{display_country(country)} {label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ / ํ•œ๋„ยท์กฐ๊ฑด ํ™•์ธ ํ•„์š”"
@@ -3227,24 +3288,37 @@ def evaluate_component_from_uploaded_source_records(country, material, component
3227
 
3228
  if reg_kind.startswith("positive_"):
3229
  limit_text, condition_text = extract_limit_condition_from_context(context)
3230
- result = {
3231
- "๋Œ€ํ‘œ INCI": representative,
3232
- "๊ฒฐ๊ณผ": f"{country_col} {reg_label}์—์„œ ์„ฑ๋ถ„ ์ง์ ‘ ํ™•์ธ" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
3233
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}" if limit_text else "ํ—ˆ์šฉ๋ชฉ๋ก ๋“ฑ์žฌ / ํ•œ๋„ ํ™•์ธ ํ•„์š”",
3234
- "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
3235
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
3236
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_POSITIVE", result["๋น„๊ณ "])
3237
  return result
3238
 
3239
  # ํŒŒ์ผ์—์„œ๋Š” ์„ฑ๋ถ„์„ ์ฐพ์•˜์ง€๋งŒ ํŒŒ์ผ ์œ ํ˜•์ด ๋ถˆ๋ช…ํ™•ํ•œ ๊ฒฝ์šฐ:
3240
- # PASS๋กœ ๋‹จ์ •ํ•˜์ง€ ์•Š๊ณ  ํ™•์ธ ํ•„์š”๋กœ ํ‘œ์‹œ. ๋‹จ, ์ด ๊ฒฝ์šฐ๋„ "ํŒŒ์ผ ์ง์ ‘ ํ™•์ธ"์€ ๋‚จ๊ธด๋‹ค.
3241
  result = {
3242
  "๋Œ€ํ‘œ INCI": representative,
3243
- "๊ฒฐ๊ณผ": f"{country_col} ๊ตญ๊ฐ€๋ณ„ ํŒŒ์ผ์—์„œ ์„ฑ๋ถ„ ์ง์ ‘ ํ™•์ธ / ํŒŒ์ผ ์œ ํ˜• ๋ฏธ๋ถ„๋ฅ˜",
3244
- "ํ‘œ์‹œ๋ฌธ๊ตฌ": NEED_CHECK_TEXT,
3245
- "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
3246
  }
3247
- log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_UNKNOWN", result["๋น„๊ณ "])
3248
  return result
3249
 
3250
 
@@ -3266,22 +3340,24 @@ def evaluate_component_from_country_files_only(country, material, component, tar
3266
  cas_no = safe_str(component.get("CAS.No", ""))
3267
  representative = inci_name or korean_name or cas_no or "-"
3268
 
3269
- critical_result = evaluate_critical_country_rule(
3270
- country=country,
3271
- material=material,
3272
- component=component,
3273
- )
3274
-
3275
- if critical_result is not None:
3276
- log_search_context(
3277
- target_id,
3278
- country,
3279
- component,
3280
- critical_result.get("๊ฒฐ๊ณผ", ""),
3281
- "CRITICAL_COUNTRY_RULE",
3282
- critical_result.get("๋น„๊ณ ", "-"),
3283
  )
3284
- return critical_result
 
 
 
 
 
 
 
 
 
 
3285
 
3286
  if is_always_pass_component(material, component):
3287
  result = {
@@ -3448,32 +3524,34 @@ def process_single_ingredient(
3448
  final_result = None
3449
  source = ""
3450
 
3451
- critical_result = evaluate_critical_country_rule(
3452
- country=country,
3453
- material=material,
3454
- component=component,
3455
- )
 
 
3456
 
3457
- if critical_result is not None:
3458
- result_rows.append({
3459
- "๊ตญ๊ฐ€": country_col,
3460
- "๊ฒ€์ƒ‰์–ด": shorten_for_table(single_query, 80),
3461
- "๋ฐฐํ•ฉํ•œ๋„/๊ธˆ์ง€": critical_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", "๋ฐฐํ•ฉ๊ธˆ์ง€"),
3462
- "์ƒ์„ธ ํŒ์ •": critical_result.get("๊ฒฐ๊ณผ", ""),
3463
- "ํŒ์ • ์ถœ์ฒ˜": "CRITICAL_COUNTRY_RULE",
3464
- "๋น„๊ณ ": simplify_single_note(critical_result.get("๋น„๊ณ ", "-")),
3465
- })
3466
 
3467
- log_search_context(
3468
- "single_ingredient",
3469
- country,
3470
- component,
3471
- critical_result.get("๊ฒฐ๊ณผ", ""),
3472
- "CRITICAL_COUNTRY_RULE",
3473
- critical_result.get("๋น„๊ณ ", "-"),
3474
- )
3475
 
3476
- continue
3477
 
3478
  if is_always_pass_component(material, component):
3479
  result_rows.append({
@@ -3496,15 +3574,17 @@ def process_single_ingredient(
3496
 
3497
  continue
3498
 
3499
- fragrance_result = evaluate_plain_fragrance_rule(
3500
- country=country,
3501
- material=material,
3502
- component=component,
3503
- )
 
 
3504
 
3505
- if fragrance_result is not None:
3506
- final_result = fragrance_result
3507
- source = "FRAGRANCE_RULE"
3508
 
3509
  if final_result is None and mfds_df is not None and not mfds_df.empty:
3510
  mfds_result = evaluate_live_detail_rule(
@@ -3530,7 +3610,7 @@ def process_single_ingredient(
3530
  final_result = file_result
3531
  source = "COUNTRY_FILE_FAST"
3532
 
3533
- if final_result is None:
3534
  local_result = evaluate_local_rules(
3535
  country=country,
3536
  material=material,
 
75
  NO_EVIDENCE_TEXT = "ํ•ด๋‹น ์ž๋ฃŒ ๋‚ด ์ œํ•œ ๊ทผ๊ฑฐ ์—†์Œ"
76
  NEED_CHECK_TEXT = "ํ™•์ธ ํ•„์š”"
77
  LIMIT_CHECK_TEXT = "๋ฐฐํ•ฉํ•œ๋„ ํ™•์ธ ํ•„์š”"
78
+
79
+ # ============================================================
80
+ # SOURCE_ONLY_MODE
81
+ # True:
82
+ # - ์—…๋กœ๋“œ๋œ ๊ตญ๊ฐ€๋ณ„ ๊ทœ์ œ ํŒŒ์ผ์—์„œ ์ง์ ‘ ์ฐพ์€ ๊ทผ๊ฑฐ๋งŒ ํŒ์ •์— ์‚ฌ์šฉ
83
+ # - UV_FILTER_RULES / PRESERVATIVE_RULES / CRITICAL_COUNTRY_RULES ๊ฐ™์€ ํ•˜๋“œ์ฝ”๋”ฉ ํ•œ๋„ยท๊ธˆ์ง€ ์ž๋™ํŒ์ • ๋น„ํ™œ์„ฑํ™”
84
+ # - ํŒŒ์ผ์—์„œ ์„ฑ๋ถ„๋ช…์ด ๋ฐœ๊ฒฌ๋˜์–ด๋„ ๊ธˆ์ง€/์ œํ•œ/ํ•œ๋„ ํ‘œํ˜„์ด ์—†์œผ๋ฉด ๋ฌธ์ œ ์„ฑ๋ถ„์œผ๋กœ ํ‘œ์‹œํ•˜์ง€ ์•Š์Œ
85
+ # False:
86
+ # - ๊ธฐ์กด์ฒ˜๋Ÿผ ๋กœ์ปฌ ํ•˜๋“œ์ฝ”๋”ฉ ๊ทœ์น™๋„ ํ•จ๊ป˜ ์‚ฌ์šฉ
87
+ # ============================================================
88
+ SOURCE_ONLY_MODE = True
89
  MFDS_LIVE_URL = "https://nedrug.mfds.go.kr/pbp/CCBDF01"
90
  # ์†๋„ ์‘๊ธ‰ํŒจ์น˜
91
  # - ์ „์ฒด ์ „์„ฑ๋ถ„ ์Šคํฌ๋ฆฌ๋‹์—์„œ๋Š” MFDS ์‚ฌ์ดํŠธ ์‹ค์‹œ๊ฐ„ ์กฐํšŒ๋ฅผ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.
 
2214
  final_result = None
2215
  source = ""
2216
 
2217
+ if not SOURCE_ONLY_MODE:
2218
+ final_result = evaluate_critical_country_rule(
2219
+ country=country,
2220
+ material=mat,
2221
+ component=comp,
2222
+ )
2223
 
2224
+ if final_result is not None:
2225
+ source = "CRITICAL_COUNTRY_RULE"
2226
 
2227
  if final_result is None and is_always_pass_component(mat, comp):
2228
  final_result = {
 
2233
  }
2234
  source = "ALWAYS_PASS_RULE"
2235
 
2236
+ if final_result is None and not SOURCE_ONLY_MODE:
2237
  fragrance_result = evaluate_plain_fragrance_rule(
2238
  country=country,
2239
  material=mat,
 
2268
  final_result = file_result
2269
  source = "COUNTRY_FILE_FAST"
2270
 
2271
+ if final_result is None and not SOURCE_ONLY_MODE:
2272
  local_result = evaluate_local_rules(
2273
  country=country,
2274
  material=mat,
 
2915
 
2916
 
2917
  def extract_limit_condition_from_context(context):
2918
+ """
2919
+ ํ•œ๋„ ์ถ”์ถœ ๊ฐ•ํ™” ๋ฒ„์ „.
2920
+ ๊ธฐ์กด ๋ฌธ์ œ:
2921
+ - ๋ฌธ๋งฅ์— ์ˆซ์ž/%๊ฐ€ ์žˆ๊ธฐ๋งŒ ํ•ด๋„ ๋ฐฐํ•ฉํ•œ๋„์ฒ˜๋Ÿผ ์žกํž ์ˆ˜ ์žˆ์Œ.
2922
+ ๊ฐœ์„ :
2923
+ - ์„ฑ๋ถ„ ์ฃผ๋ณ€ ๋ฌธ๋งฅ์— '๋ฐฐํ•ฉํ•œ๋„/maximum/limit/not exceed/์ดํ•˜/์ตœ๋Œ€/์ œํ•œ์‚ฌํ•ญ' ๊ฐ™์€ ์ œํ•œ ํ‚ค์›Œ๋“œ๊ฐ€ ์žˆ์–ด์•ผ๋งŒ ํ•œ๋„ ์ถ”์ถœ.
2924
+ - ํ‘œ์‹œ/๋ผ๋ฒจ/์•Œ๋ ˆ๋ฅด๊ฒ/๋ถˆ์ˆœ๋ฌผ/์‹œํ—˜๋ฒ•/ppm ๊ด€๋ฆฌ๊ฐ’ ๋“ฑ์€ ๋ฐฐํ•ฉํ•œ๋„๋กœ ๋ณด์ง€ ์•Š์Œ.
2925
+ """
2926
  text = safe_str(context)
2927
  compact = re.sub(r"\s+", " ", text).strip()
2928
+
2929
  if not compact:
2930
  return "", ""
2931
 
2932
+ limit_keywords = [
2933
+ "๋ฐฐํ•ฉํ•œ๋„", "๋ฐฐํ•ฉ ํ•œ๋„", "์‚ฌ์šฉํ•œ๋„", "์‚ฌ์šฉ ํ•œ๋„", "์ œํ•œ์‚ฌํ•ญ", "์‚ฌ์šฉ์ œํ•œ", "์‚ฌ์šฉ ์ œํ•œ",
2934
+ "์ตœ๋Œ€", "์ดํ•˜", "ํ•œ๋„", "maximum", "max.", "limit", "limits", "limited",
2935
+ "restriction", "restricted", "not exceed", "not exceeding", "no more than",
2936
+ ]
2937
+
2938
+ false_limit_keywords = [
2939
+ "label", "labeling", "labelling", "๋ผ๋ฒจ", "ํ‘œ์‹œ", "์•Œ๋ ˆ๋ฅด๊ฒ", "allergen",
2940
+ "warning", "๊ฒฝ๊ณ ", "๋ถˆ์ˆœ๋ฌผ", "impurity", "์‹œํ—˜", "์‹œํ—˜๋ฒ•", "test method",
2941
+ "analysis", "๊ฒ€์‚ฌ", "๊ด€๋ฆฌ๊ฐ’", "๊ฒ€์ถœํ•œ๊ณ„", "detection limit",
2942
+ "peroxide value", "์‚ฐ๊ฐ€", "์ˆœ๋„", "purity",
2943
+ ]
2944
+
2945
+ candidate_lines = []
2946
+ lines = [safe_str(x) for x in text.splitlines() if safe_str(x)]
2947
+
2948
+ for line in lines:
2949
+ low = line.lower()
2950
+ if any(k.lower() in low for k in false_limit_keywords):
2951
+ continue
2952
+ if any(k.lower() in low for k in limit_keywords):
2953
+ candidate_lines.append(line)
2954
+
2955
+ search_text = "\n".join(candidate_lines)
2956
+ if not search_text and any(k.lower() in compact.lower() for k in limit_keywords):
2957
+ if not any(k.lower() in compact.lower() for k in false_limit_keywords):
2958
+ search_text = compact
2959
+
2960
+ if not search_text:
2961
+ return "", ""
2962
+
2963
  patterns = [
2964
  r"([0-9]+(?:\.[0-9]+)?\s*%)",
 
2965
  r"([0-9]+(?:\.[0-9]+)?\s*g\s*/\s*100\s*g)",
2966
  r"([0-9]+(?:\.[0-9]+)?\s*g\s+per\s+100\s*g)",
 
2967
  ]
2968
+
2969
  limits = []
2970
  for pat in patterns:
2971
+ for m in re.finditer(pat, search_text, flags=re.IGNORECASE):
2972
  v = m.group(1).replace(" ", "")
2973
  if v not in limits:
2974
  limits.append(v)
2975
 
2976
+ # ppm์€ ๋ถˆ์ˆœ๋ฌผ ๊ด€๋ฆฌ๊ฐ’์ธ ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์œผ๋ฏ€๋กœ 'maximum concentration/๋ฐฐํ•ฉํ•œ๋„'๊ฐ€ ๊ฐ™์€ ๋ฌธ์žฅ์— ์žˆ์„ ๋•Œ๋งŒ ํ—ˆ์šฉ
2977
+ for line in candidate_lines:
2978
+ low = line.lower()
2979
+ if ("ppm" in low) and any(k in low for k in ["maximum concentration", "max concentration", "๋ฐฐํ•ฉํ•œ๋„", "์‚ฌ์šฉํ•œ๋„"]):
2980
+ for m in re.finditer(r"([0-9]+(?:\.[0-9]+)?\s*ppm)", line, flags=re.IGNORECASE):
2981
+ v = m.group(1).replace(" ", "")
2982
+ if v not in limits:
2983
+ limits.append(v)
2984
+
2985
  condition_keywords = [
2986
  "leave-on", "rinse-off", "oral", "mucosa", "washed away",
2987
  "๋ณด์กด์ œ", "๋ฐฉ๋ถ€์ œ", "์ž์™ธ์„ ", "์ƒ‰์†Œ", "์ ๋ง‰", "๊ตฌ๊ฐ•",
2988
+ "์ œํ•œ์‚ฌํ•ญ", "condition", "ํ•œ๋„", "์ œํ•œ", "maximum", "limit",
2989
  ]
2990
+
2991
  condition_lines = []
2992
+ for line in candidate_lines:
2993
  l = line.lower()
2994
  if any(k.lower() in l for k in condition_keywords):
2995
  cleaned = re.sub(r"\s+", " ", line).strip()
 
3010
  display = f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}"
3011
  result = f"{display_country(country)} {label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ / ํ•œ๋„ {limit_text}"
3012
  elif kind.startswith("positive_"):
3013
+ display = "Pass"
3014
+ result = NO_EVIDENCE_TEXT
3015
  else:
3016
  display = "๋ฐฐํ•ฉํ•œ๋„/์ œํ•œ ํ™•์ธ"
3017
  result = f"{display_country(country)} {label}์—์„œ ์„ฑ๋ถ„ ํ™•์ธ / ํ•œ๋„ยท์กฐ๊ฑด ํ™•์ธ ํ•„์š”"
 
3288
 
3289
  if reg_kind.startswith("positive_"):
3290
  limit_text, condition_text = extract_limit_condition_from_context(context)
3291
+
3292
+ # Positive List์— ์„ฑ๋ถ„์ด ์žˆ๋‹ค๋Š” ์‚ฌ์‹ค๋งŒ์œผ๋กœ๋Š” ๋ฌธ์ œ ์„ฑ๋ถ„์ด ์•„๋‹ˆ๋‹ค.
3293
+ # ๋ช…ํ™•ํ•œ ํ•œ๋„ ์ˆ˜์น˜๊ฐ€ ์žˆ์„ ๋•Œ๋งŒ ๋ฐฐํ•ฉํ•œ๋„๋กœ ํ‘œ์‹œํ•˜๊ณ ,
3294
+ # ํ•œ๋„ ์ˆ˜์น˜๊ฐ€ ์—†์œผ๋ฉด Pass๋กœ ๋‘๋˜ ๊ทผ๊ฑฐํŒŒ์ผ์€ ๋น„๊ณ /Evidence Log์— ๋‚จ๊ธด๋‹ค.
3295
+ if limit_text:
3296
+ result = {
3297
+ "๋Œ€ํ‘œ INCI": representative,
3298
+ "๊ฒฐ๊ณผ": f"{country_col} {reg_label}์—์„œ ์„ฑ๋ถ„ ์ง์ ‘ ํ™•์ธ / ํ•œ๋„ {limit_text}" + (f" / ์กฐ๊ฑด: {condition_text}" if condition_text else ""),
3299
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": f"๋ฐฐํ•ฉํ•œ๋„: {limit_text}",
3300
+ "๋น„๊ณ ": f"[์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
3301
+ }
3302
+ else:
3303
+ result = {
3304
+ "๋Œ€ํ‘œ INCI": representative,
3305
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
3306
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
3307
+ "๋น„๊ณ ": f"ํ—ˆ์šฉ๋ชฉ๋ก์—์„œ ์„ฑ๋ถ„๋ช…์€ ํ™•์ธ๋˜์—ˆ์œผ๋‚˜ ๋ฐฐํ•ฉํ•œ๋„ ์ˆ˜์น˜ ๊ทผ๊ฑฐ ์—†์Œ / [์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
3308
+ }
3309
+
3310
  log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_POSITIVE", result["๋น„๊ณ "])
3311
  return result
3312
 
3313
  # ํŒŒ์ผ์—์„œ๋Š” ์„ฑ๋ถ„์„ ์ฐพ์•˜์ง€๋งŒ ํŒŒ์ผ ์œ ํ˜•์ด ๋ถˆ๋ช…ํ™•ํ•œ ๊ฒฝ์šฐ:
3314
+ # ๊ธˆ์ง€/์ œํ•œ/ํ•œ๋„ ํ‚ค์›Œ๋“œ๊ฐ€ ๋ช…ํ™•ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฌธ์ œ ์„ฑ๋ถ„์œผ๋กœ ๋งŒ๋“ค์ง€ ์•Š๋Š”๋‹ค.
3315
  result = {
3316
  "๋Œ€ํ‘œ INCI": representative,
3317
+ "๊ฒฐ๊ณผ": NO_EVIDENCE_TEXT,
3318
+ "ํ‘œ์‹œ๋ฌธ๊ตฌ": "Pass",
3319
+ "๋น„๊ณ ": f"ํŒŒ์ผ์—์„œ ์„ฑ๋ถ„๋ช…์€ ๋ฐœ๊ฒฌ๋˜์—ˆ์œผ๋‚˜ ๊ธˆ์ง€/์ œํ•œ/ํ•œ๋„ ๊ทผ๊ฑฐ ์—†์Œ / [์ถœ์ฒ˜ํŒŒ์ผ: {best.get('source_file', '')}] [row: {best.get('row_index', '')}] {context[:900]}",
3320
  }
3321
+ log_search_context(target_id, country, component, result["๊ฒฐ๊ณผ"], "UPLOADED_SOURCE_RECORD_UNKNOWN_PASS", result["๋น„๊ณ "])
3322
  return result
3323
 
3324
 
 
3340
  cas_no = safe_str(component.get("CAS.No", ""))
3341
  representative = inci_name or korean_name or cas_no or "-"
3342
 
3343
+ critical_result = None
3344
+ if not SOURCE_ONLY_MODE:
3345
+ critical_result = evaluate_critical_country_rule(
3346
+ country=country,
3347
+ material=material,
3348
+ component=component,
 
 
 
 
 
 
 
 
3349
  )
3350
+
3351
+ if critical_result is not None:
3352
+ log_search_context(
3353
+ target_id,
3354
+ country,
3355
+ component,
3356
+ critical_result.get("๊ฒฐ๊ณผ", ""),
3357
+ "CRITICAL_COUNTRY_RULE",
3358
+ critical_result.get("๋น„๊ณ ", "-"),
3359
+ )
3360
+ return critical_result
3361
 
3362
  if is_always_pass_component(material, component):
3363
  result = {
 
3524
  final_result = None
3525
  source = ""
3526
 
3527
+ critical_result = None
3528
+ if not SOURCE_ONLY_MODE:
3529
+ critical_result = evaluate_critical_country_rule(
3530
+ country=country,
3531
+ material=material,
3532
+ component=component,
3533
+ )
3534
 
3535
+ if critical_result is not None:
3536
+ result_rows.append({
3537
+ "๊ตญ๊ฐ€": country_col,
3538
+ "๊ฒ€์ƒ‰์–ด": shorten_for_table(single_query, 80),
3539
+ "๋ฐฐํ•ฉํ•œ๋„/๊ธˆ์ง€": critical_result.get("ํ‘œ์‹œ๋ฌธ๊ตฌ", "๋ฐฐํ•ฉ๊ธˆ์ง€"),
3540
+ "์ƒ์„ธ ํŒ์ •": critical_result.get("๊ฒฐ๊ณผ", ""),
3541
+ "ํŒ์ • ์ถœ์ฒ˜": "CRITICAL_COUNTRY_RULE",
3542
+ "๋น„๊ณ ": simplify_single_note(critical_result.get("๋น„๊ณ ", "-")),
3543
+ })
3544
 
3545
+ log_search_context(
3546
+ "single_ingredient",
3547
+ country,
3548
+ component,
3549
+ critical_result.get("๊ฒฐ๊ณผ", ""),
3550
+ "CRITICAL_COUNTRY_RULE",
3551
+ critical_result.get("๋น„๊ณ ", "-"),
3552
+ )
3553
 
3554
+ continue
3555
 
3556
  if is_always_pass_component(material, component):
3557
  result_rows.append({
 
3574
 
3575
  continue
3576
 
3577
+ fragrance_result = None
3578
+ if not SOURCE_ONLY_MODE:
3579
+ fragrance_result = evaluate_plain_fragrance_rule(
3580
+ country=country,
3581
+ material=material,
3582
+ component=component,
3583
+ )
3584
 
3585
+ if fragrance_result is not None:
3586
+ final_result = fragrance_result
3587
+ source = "FRAGRANCE_RULE"
3588
 
3589
  if final_result is None and mfds_df is not None and not mfds_df.empty:
3590
  mfds_result = evaluate_live_detail_rule(
 
3610
  final_result = file_result
3611
  source = "COUNTRY_FILE_FAST"
3612
 
3613
+ if final_result is None and not SOURCE_ONLY_MODE:
3614
  local_result = evaluate_local_rules(
3615
  country=country,
3616
  material=material,