-
Notifications
You must be signed in to change notification settings - Fork 4
/
stash_models.py
51 lines (40 loc) · 1.44 KB
/
stash_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
from dataclasses import dataclass
from dsp_tools.models.value import KnoraStandoffXml
from dsp_tools.models.xmlresource import XMLResource
@dataclass(frozen=True)
class StandoffStashItem:
"""
Holds information about a single stashed XML text value.
"""
uuid: str
prop_name: str
value: KnoraStandoffXml
# Permissions missing still
@dataclass(frozen=True)
class StandoffStash:
"""
Holds information about a number of stashed XML text values, organized by resource instance.
"""
res_2_stash_items: dict[str, list[StandoffStashItem]]
res_2_xmlres: dict[str, XMLResource]
@staticmethod
def make(tups: list[tuple[XMLResource, StandoffStashItem]]) -> StandoffStash | None:
"""
Factory method for StandoffStash.
Args:
tups: A list of tuples of XMLResource and StandoffStashItem.
Returns:
StandoffStash | None: A StandoffStash object or None, if an empty list was passed.
"""
if not tups:
return None
res_2_stash_items = {}
res_2_xmlres = {}
for xmlres, stash_item in tups:
if xmlres.id not in res_2_stash_items:
res_2_stash_items[xmlres.id] = [stash_item]
res_2_xmlres[xmlres.id] = xmlres
else:
res_2_stash_items[xmlres.id].append(stash_item)
return StandoffStash(res_2_stash_items, res_2_xmlres)