Spaces:
Sleeping
Sleeping
Upload hts_validator.py
Browse files- hts_validator.py +34 -31
hts_validator.py
CHANGED
|
@@ -88,14 +88,14 @@ SCENARIO_SUMMARIES = {
|
|
| 88 |
"L7": "Aluminum HTS + alum+copper keywords - Alum 232 + 99030133",
|
| 89 |
"L8": "Aluminum HTS + all keywords - Alum 232 + 99030133",
|
| 90 |
# Level 3: Single HTS - Copper
|
| 91 |
-
"U1": "Copper HTS, no keyword -
|
| 92 |
"U2": "Copper HTS + metal keyword - 99030125 (mismatch)",
|
| 93 |
-
"U3": "Copper HTS + aluminum keyword -
|
| 94 |
-
"U4": "Copper HTS + copper keyword -
|
| 95 |
-
"U5": "Copper HTS + metal+alum keywords -
|
| 96 |
-
"U6": "Copper HTS + metal+copper keywords -
|
| 97 |
-
"U7": "Copper HTS + alum+copper keywords -
|
| 98 |
-
"U8": "Copper HTS + all keywords -
|
| 99 |
# Level 4: No HTS Match
|
| 100 |
"N1": "No metal HTS, no keyword - no action",
|
| 101 |
"N2": "No metal HTS + metal keyword - 99030125",
|
|
@@ -949,17 +949,18 @@ class HTSValidator:
|
|
| 949 |
)
|
| 950 |
|
| 951 |
# H3: Copper Only
|
|
|
|
| 952 |
if in_copper and not in_steel and not in_aluminum:
|
| 953 |
-
if keyword_cat == "K0": # U1: No keyword
|
| 954 |
return self._create_result(
|
| 955 |
entry_number, description, primary_hts, additional_hts,
|
| 956 |
scenario_id="U1",
|
| 957 |
-
expected_codes=
|
| 958 |
-
forbidden_codes={MISMATCH_CODE},
|
| 959 |
additional_set=additional_set,
|
| 960 |
**indicators
|
| 961 |
)
|
| 962 |
-
elif keyword_cat == "K1": # U2: Metal only
|
| 963 |
return self._create_result(
|
| 964 |
entry_number, description, primary_hts, additional_hts,
|
| 965 |
scenario_id="U2",
|
|
@@ -968,59 +969,61 @@ class HTSValidator:
|
|
| 968 |
additional_set=additional_set,
|
| 969 |
**indicators
|
| 970 |
)
|
| 971 |
-
elif keyword_cat == "K2": # U3: Aluminum only
|
| 972 |
return self._create_result(
|
| 973 |
entry_number, description, primary_hts, additional_hts,
|
| 974 |
scenario_id="U3",
|
| 975 |
-
expected_codes=[
|
| 976 |
-
forbidden_codes=
|
| 977 |
additional_set=additional_set,
|
| 978 |
**indicators
|
| 979 |
)
|
| 980 |
-
elif keyword_cat == "K3": # U4: Copper only
|
| 981 |
return self._create_result(
|
| 982 |
entry_number, description, primary_hts, additional_hts,
|
| 983 |
scenario_id="U4",
|
| 984 |
-
expected_codes=
|
| 985 |
-
forbidden_codes={MISMATCH_CODE},
|
| 986 |
additional_set=additional_set,
|
| 987 |
**indicators
|
| 988 |
)
|
| 989 |
-
elif keyword_cat == "K4": # U5: Metal + Aluminum
|
| 990 |
return self._create_result(
|
| 991 |
entry_number, description, primary_hts, additional_hts,
|
| 992 |
scenario_id="U5",
|
| 993 |
-
expected_codes=[
|
| 994 |
-
forbidden_codes=
|
| 995 |
additional_set=additional_set,
|
| 996 |
**indicators
|
| 997 |
)
|
| 998 |
-
elif keyword_cat == "K5": # U6: Metal + Copper
|
| 999 |
return self._create_result(
|
| 1000 |
entry_number, description, primary_hts, additional_hts,
|
| 1001 |
scenario_id="U6",
|
| 1002 |
-
expected_codes=
|
| 1003 |
-
forbidden_codes={MISMATCH_CODE},
|
| 1004 |
additional_set=additional_set,
|
| 1005 |
**indicators
|
| 1006 |
)
|
| 1007 |
-
elif keyword_cat == "K6": # U7: Aluminum + Copper
|
| 1008 |
return self._create_result(
|
| 1009 |
entry_number, description, primary_hts, additional_hts,
|
| 1010 |
scenario_id="U7",
|
| 1011 |
-
expected_codes=
|
| 1012 |
-
forbidden_codes={MISMATCH_CODE},
|
| 1013 |
additional_set=additional_set,
|
| 1014 |
-
|
|
|
|
|
|
|
| 1015 |
)
|
| 1016 |
-
elif keyword_cat == "K7": # U8: All three
|
| 1017 |
return self._create_result(
|
| 1018 |
entry_number, description, primary_hts, additional_hts,
|
| 1019 |
scenario_id="U8",
|
| 1020 |
-
expected_codes=
|
| 1021 |
-
forbidden_codes={MISMATCH_CODE},
|
| 1022 |
additional_set=additional_set,
|
| 1023 |
-
|
|
|
|
|
|
|
| 1024 |
)
|
| 1025 |
|
| 1026 |
# =====================================================================
|
|
|
|
| 88 |
"L7": "Aluminum HTS + alum+copper keywords - Alum 232 + 99030133",
|
| 89 |
"L8": "Aluminum HTS + all keywords - Alum 232 + 99030133",
|
| 90 |
# Level 3: Single HTS - Copper
|
| 91 |
+
"U1": "Copper HTS, no keyword - 99037802 (no copper content)",
|
| 92 |
"U2": "Copper HTS + metal keyword - 99030125 (mismatch)",
|
| 93 |
+
"U3": "Copper HTS + aluminum keyword - 99037802 + Alum 232",
|
| 94 |
+
"U4": "Copper HTS + copper keyword - 99037801 (copper content)",
|
| 95 |
+
"U5": "Copper HTS + metal+alum keywords - 99037802 + Alum 232",
|
| 96 |
+
"U6": "Copper HTS + metal+copper keywords - 99037801 (copper content)",
|
| 97 |
+
"U7": "Copper HTS + alum+copper keywords - FLAG ambiguous",
|
| 98 |
+
"U8": "Copper HTS + all keywords - FLAG ambiguous",
|
| 99 |
# Level 4: No HTS Match
|
| 100 |
"N1": "No metal HTS, no keyword - no action",
|
| 101 |
"N2": "No metal HTS + metal keyword - 99030125",
|
|
|
|
| 949 |
)
|
| 950 |
|
| 951 |
# H3: Copper Only
|
| 952 |
+
# New logic: Copper keyword -> 99037801, No copper keyword -> 99037802
|
| 953 |
if in_copper and not in_steel and not in_aluminum:
|
| 954 |
+
if keyword_cat == "K0": # U1: No keyword -> 99037802 (no copper content)
|
| 955 |
return self._create_result(
|
| 956 |
entry_number, description, primary_hts, additional_hts,
|
| 957 |
scenario_id="U1",
|
| 958 |
+
expected_codes=["99037802"],
|
| 959 |
+
forbidden_codes={MISMATCH_CODE, "99037801"},
|
| 960 |
additional_set=additional_set,
|
| 961 |
**indicators
|
| 962 |
)
|
| 963 |
+
elif keyword_cat == "K1": # U2: Metal only -> mismatch
|
| 964 |
return self._create_result(
|
| 965 |
entry_number, description, primary_hts, additional_hts,
|
| 966 |
scenario_id="U2",
|
|
|
|
| 969 |
additional_set=additional_set,
|
| 970 |
**indicators
|
| 971 |
)
|
| 972 |
+
elif keyword_cat == "K2": # U3: Aluminum only -> 99037802 + Alum 232
|
| 973 |
return self._create_result(
|
| 974 |
entry_number, description, primary_hts, additional_hts,
|
| 975 |
scenario_id="U3",
|
| 976 |
+
expected_codes=["99037802"] + list(ALUMINUM_232_CODES) + [GENERAL_301_CODE],
|
| 977 |
+
forbidden_codes={MISMATCH_CODE, "99037801"},
|
| 978 |
additional_set=additional_set,
|
| 979 |
**indicators
|
| 980 |
)
|
| 981 |
+
elif keyword_cat == "K3": # U4: Copper only -> 99037801 (copper content)
|
| 982 |
return self._create_result(
|
| 983 |
entry_number, description, primary_hts, additional_hts,
|
| 984 |
scenario_id="U4",
|
| 985 |
+
expected_codes=["99037801"],
|
| 986 |
+
forbidden_codes={MISMATCH_CODE, "99037802"},
|
| 987 |
additional_set=additional_set,
|
| 988 |
**indicators
|
| 989 |
)
|
| 990 |
+
elif keyword_cat == "K4": # U5: Metal + Aluminum -> 99037802 + Alum 232
|
| 991 |
return self._create_result(
|
| 992 |
entry_number, description, primary_hts, additional_hts,
|
| 993 |
scenario_id="U5",
|
| 994 |
+
expected_codes=["99037802"] + list(ALUMINUM_232_CODES) + [GENERAL_301_CODE],
|
| 995 |
+
forbidden_codes={MISMATCH_CODE, "99037801"},
|
| 996 |
additional_set=additional_set,
|
| 997 |
**indicators
|
| 998 |
)
|
| 999 |
+
elif keyword_cat == "K5": # U6: Metal + Copper -> 99037801 (copper keyword present)
|
| 1000 |
return self._create_result(
|
| 1001 |
entry_number, description, primary_hts, additional_hts,
|
| 1002 |
scenario_id="U6",
|
| 1003 |
+
expected_codes=["99037801"],
|
| 1004 |
+
forbidden_codes={MISMATCH_CODE, "99037802"},
|
| 1005 |
additional_set=additional_set,
|
| 1006 |
**indicators
|
| 1007 |
)
|
| 1008 |
+
elif keyword_cat == "K6": # U7: Aluminum + Copper -> FLAG ambiguous
|
| 1009 |
return self._create_result(
|
| 1010 |
entry_number, description, primary_hts, additional_hts,
|
| 1011 |
scenario_id="U7",
|
| 1012 |
+
expected_codes=[], forbidden_codes=set(),
|
|
|
|
| 1013 |
additional_set=additional_set,
|
| 1014 |
+
**indicators,
|
| 1015 |
+
always_flag=True,
|
| 1016 |
+
flag_reason="Copper HTS with both aluminum and copper keywords - ambiguous"
|
| 1017 |
)
|
| 1018 |
+
elif keyword_cat == "K7": # U8: All three -> FLAG ambiguous
|
| 1019 |
return self._create_result(
|
| 1020 |
entry_number, description, primary_hts, additional_hts,
|
| 1021 |
scenario_id="U8",
|
| 1022 |
+
expected_codes=[], forbidden_codes=set(),
|
|
|
|
| 1023 |
additional_set=additional_set,
|
| 1024 |
+
**indicators,
|
| 1025 |
+
always_flag=True,
|
| 1026 |
+
flag_reason="Copper HTS with all keywords - ambiguous"
|
| 1027 |
)
|
| 1028 |
|
| 1029 |
# =====================================================================
|