/
wikibase_types.py
80 lines (56 loc) · 2.23 KB
/
wikibase_types.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from typing import Literal, TypeAlias, TypedDict
from typing_extensions import NotRequired
class Term(TypedDict):
language: str
value: str
remove: NotRequired[Literal['']] # only needed when editing
WikibaseEntityIdDataValueValue = TypedDict('WikibaseEntityIdDataValueValue', {
'entity-type': Literal['item'],
'id': str,
})
class WikibaseEntityIdDataValue(TypedDict):
type: Literal['wikibase-entityid']
value: WikibaseEntityIdDataValueValue
class PropertyValueSnak(TypedDict):
snaktype: Literal['value']
property: str
datatype: Literal['wikibase-item'] # other data types not used in this tool
datavalue: WikibaseEntityIdDataValue
class PropertySomeValueSnak(TypedDict):
snaktype: Literal['somevalue']
property: str
datatype: Literal['wikibase-item'] # other data types not used in this tool
# no datavalue
class PropertyNoValueSnak(TypedDict):
snaktype: Literal['novalue']
property: str
datatype: Literal['wikibase-item'] # other data types not used in this tool
# no datavalue
Snak: TypeAlias = PropertyValueSnak | PropertySomeValueSnak | PropertyNoValueSnak
class Statement(TypedDict):
mainsnak: Snak
# qualifiers and references not used in this tool
type: Literal['statement']
rank: Literal['normal'] # other ranks not used in this tool
StatementGroup: TypeAlias = list[Statement]
Statements: TypeAlias = dict[str, StatementGroup]
LexemeFormRepresentations: TypeAlias = dict[str, Term]
LexemeLemmas: TypeAlias = dict[str, Term]
class LexemeForm(TypedDict):
representations: LexemeFormRepresentations
grammaticalFeatures: list[str]
claims: Statements
add: NotRequired[Literal['']] # only needed when creating
remove: NotRequired[Literal['']] # only needed when editing
id: NotRequired[Literal['']] # only present when editing
class Lexeme(TypedDict):
type: Literal['lexeme']
lemmas: LexemeLemmas
language: str
lexicalCategory: str
claims: Statements
forms: list[LexemeForm]
# senses not used in this tool
id: NotRequired[str] # only needed when editing
base_revision_id: NotRequired[str] # only needed when editing
lastrevid: NotRequired[int] # only available when data returned by API