Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#35: check if the title in GuaranteedAnalysis is minimal #47

Merged
merged 8 commits into from
Oct 9, 2024
10 changes: 9 additions & 1 deletion pipeline/inspection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from typing import List, Optional
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field, field_validator, model_validator

class npkError(ValueError):
pass
Expand Down Expand Up @@ -44,6 +44,7 @@ def convert_value(cls, v):
class GuaranteedAnalysis(BaseModel):
title: Optional[str] = None
nutrients: List[NutrientValue] = []
title_is_minimal: bool = False
k-allagbe marked this conversation as resolved.
Show resolved Hide resolved

@field_validator(
"nutrients",
Expand All @@ -53,6 +54,13 @@ def replace_none_with_empty_list(cls, v):
if v is None:
v = []
return v

@model_validator(mode="after")
def set_title_is_minimal(self):
k-allagbe marked this conversation as resolved.
Show resolved Hide resolved
pattern = r'\bminim\w*\b'
if self.title and re.search(pattern, self.title, re.IGNORECASE):
self.title_is_minimal = True
return self

class Specification(BaseModel):
humidity: Optional[float] = Field(..., alias='humidity')
Expand Down
Loading