Skip to content

Commit

Permalink
Update serialise_value.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Nov 15, 2024
1 parent 8a8ab88 commit 66f7d2c
Showing 1 changed file with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,26 @@
from dsp_tools.utils.date_util import SingleDate
from dsp_tools.utils.date_util import StartEnd

ValueTypes: TypeAlias = Union[str, Date]

@dataclass
class Interval:
start: str
end: str

def interval_start(self) -> dict[str, str]:
return self._to_dict(self.start)

def interval_end(self) -> dict[str, str]:
return self._to_dict(self.end)

def _to_dict(self, interval_value: str) -> dict[str, str]:
return {
"@type": "xsd:decimal",
"@value": interval_value,
}


ValueTypes: TypeAlias = Union[str, Date, Interval]


@dataclass(frozen=True)
Expand Down Expand Up @@ -133,23 +152,18 @@ def serialise(self) -> dict[str, Any]:


class SerialiseInterval(SerialiseValue):
"""A IntervalValue to be serialised."""
"""An IntervalValue to be serialised."""

value: Interval

@dataclass
class Interval:
start: str
end: str

def interval_start(self) -> dict[str, str]: ...

def interval_end(self) -> dict[str, str]: ...

def _to_dict(self, inverval_value: str) -> dict[str, str]:
return {
"@type": "xsd:decimal",
"@value": inverval_value,
def serialise(self) -> dict[str, Any]:
serialised = {
"@type": "knora-api:IntervalValue",
"knora-api:intervalValueHasStart": self.value.interval_start(),
"knora-api:intervalValueHasEnd": self.value.interval_end(),
}
serialised.update(self._get_optionals())
return serialised


class SerialiseSimpletext(SerialiseValue):
Expand Down

0 comments on commit 66f7d2c

Please sign in to comment.