Skip to content

Commit

Permalink
chore: generalize sample parser
Browse files Browse the repository at this point in the history
  • Loading branch information
percevalw committed Jun 16, 2024
1 parent 1fd8987 commit 6f37ab4
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions edsnlp/utils/examples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import re
from typing import Any, Dict, List, Tuple, Union

import regex
from confit.utils.xjson import loads
from pydantic import BaseModel, validator


Expand All @@ -19,14 +19,7 @@ class Modifier(BaseModel):

@validator("value")
def optional_dict_parsing(cls, v):
if v in ["True", "False"]:
return v == "True"
if isinstance(v, str):
try:
return json.loads(v.replace("'", '"'))
except json.JSONDecodeError:
return v
return v
return loads(v) if isinstance(v, str) else v


class Entity(BaseModel):
Expand Down

0 comments on commit 6f37ab4

Please sign in to comment.