mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
fix: NLP Ingredient Parser Misses Some Fractions (#3618)
This commit is contained in:
parent
3d3279738b
commit
a4c3b0da71
@ -29,24 +29,24 @@ class CRFIngredient(BaseModel):
|
|||||||
input: str = ""
|
input: str = ""
|
||||||
name: str = ""
|
name: str = ""
|
||||||
other: str = ""
|
other: str = ""
|
||||||
qty: str = ""
|
qty: Annotated[str, Field(validate_default=True)] = ""
|
||||||
comment: str = ""
|
comment: str = ""
|
||||||
unit: str = ""
|
unit: str = ""
|
||||||
confidence: CRFConfidence
|
confidence: CRFConfidence
|
||||||
|
|
||||||
@field_validator("qty", mode="before")
|
@field_validator("qty", mode="before")
|
||||||
def validate_qty(qty, info: ValidationInfo): # sourcery skip: merge-nested-ifs
|
def validate_qty(cls, qty, info: ValidationInfo):
|
||||||
if qty is None or qty == "":
|
if qty is not None and qty != "":
|
||||||
# Check if other contains a fraction
|
return qty
|
||||||
try:
|
|
||||||
if info.data["other"] is not None and info.data["other"].find("/") != -1:
|
|
||||||
return round(float(Fraction(info.data["other"])), 3)
|
|
||||||
else:
|
|
||||||
return 1
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return qty
|
# Check if other contains a fraction
|
||||||
|
try:
|
||||||
|
if info.data["other"] is not None and info.data["other"].find("/") != -1:
|
||||||
|
return str(round(float(Fraction(info.data["other"])), 3))
|
||||||
|
else:
|
||||||
|
return "0"
|
||||||
|
except Exception:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def _exec_crf_test(input_text):
|
def _exec_crf_test(input_text):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user