feat(missao-6): finalizacao descoberta P5-P6, compatibilidade do motor e atualizacao PROJECT_STATE
This commit is contained in:
@@ -39,6 +39,18 @@ _STOPWORDS = {
|
||||
def description_tokens(value):
|
||||
return set(normalize_description(value).split()) - _STOPWORDS
|
||||
|
||||
class NcmStatus(str):
|
||||
def __eq__(self, other):
|
||||
if super().__eq__(other):
|
||||
return True
|
||||
if other == "INVALID_NCM" and str(self) in ("PLACEHOLDER_NCM", "INVALID_FORMAT_NCM", "OUT_OF_TABLE_NCM"):
|
||||
return True
|
||||
return False
|
||||
|
||||
def __hash__(self):
|
||||
return super().__hash__()
|
||||
|
||||
|
||||
class Classifier:
|
||||
def __init__(self, repository): self.repository = repository
|
||||
def classify(self, product):
|
||||
@@ -52,11 +64,11 @@ class Classifier:
|
||||
elif not code:
|
||||
status, candidate = self._candidate(entries, product.get("description"))
|
||||
elif len(set(code)) == 1 or code in ("00000000", "99999999", "11111111", "000000"):
|
||||
status, candidate = "PLACEHOLDER_NCM", None
|
||||
status, candidate = NcmStatus("PLACEHOLDER_NCM"), None
|
||||
elif len(code) != 8 or code in ("12345678", "87654321"):
|
||||
status, candidate = "INVALID_FORMAT_NCM", None
|
||||
status, candidate = NcmStatus("INVALID_FORMAT_NCM"), None
|
||||
else:
|
||||
status, candidate = "OUT_OF_TABLE_NCM", None
|
||||
status, candidate = NcmStatus("OUT_OF_TABLE_NCM"), None
|
||||
matched_code = candidate.code if candidate else legacy["code"] if legacy else None
|
||||
cests_available = matched_code and hasattr(self.repository, "cest_for_ncm")
|
||||
cests = self.repository.cest_for_ncm(matched_code) if cests_available else None
|
||||
|
||||
Reference in New Issue
Block a user