Skip to content

Commit

Permalink
feat: make text and tokens immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
dcfidalgo committed Mar 7, 2022
1 parent 1501da8 commit c0b5900
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rubrix/client/models.py
Expand Up @@ -231,7 +231,7 @@ class TokenClassificationRecord(_Validators):
"""

text: str = Field(min_length=1)
tokens: List[str] = Field(min_items=1)
tokens: Tuple[str, ...] = Field(min_items=1)

prediction: Optional[
List[Union[Tuple[str, int, int], Tuple[str, int, int, float]]]
Expand All @@ -248,6 +248,12 @@ class TokenClassificationRecord(_Validators):
metrics: Optional[Dict[str, Any]] = None
search_keywords: Optional[List[str]] = None

def __setattr__(self, name: str, value: Any):
"""Make text and tokens immutable"""
if name in ["text", "tokens"]:
raise AttributeError(f"You cannot assign a new value to `{name}`")
super().__setattr__(name, value)

@validator("prediction")
def add_default_score(
cls,
Expand Down

0 comments on commit c0b5900

Please sign in to comment.