-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataModel.go
89 lines (71 loc) · 2.91 KB
/
dataModel.go
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
81
82
83
84
85
86
87
88
89
package gowd
import (
"encoding/json"
)
type entityType string
const (
EntityType_Item entityType = "item"
EntityType_Property entityType = "property"
EntityType_Lexeme entityType = "lexeme"
)
type Entity struct{
Id string `json:"id"` // Q111 for example
Type entityType `json:"type"` // "item"|"property"|"lexeme"
Labels map[string]MonolingualText `json:"labels"`
Descriptions map[string]MonolingualText `json:"descriptions"`
Aliases map[string][]MonolingualText `json:"aliases"`
Claims map[string][]Statement `json:"claims"`
Sitelinks map[string]SiteLink `json:"sitelinks"`
// Revision infos
Lastrevid Integer `json:"lastrevid"` // The document's version (MediaWiki revision ID)
Modified string `json:"modified"` // The document's Publication date (MediaWiki revision timestamp)
// Extra informations
Title string `json:"title"` // The title of the page the entity is stored on
PageId Integer `json:"pageid"` // The page id the entity is stored on
Ns Integer `json:"ns"` // The namespace id the entity is stored on
}
type Statement struct {
MainSnak Snak `json:"mainsnak"`
Qualifiers map[string][]Qualifier `json:"qualifiers"`
Id string `json:"id"` // The id of this statement
Rank string `json:"rank"`
References []Reference `json:"references"`
}
type Snak struct {
SnakType string `json:"snaktype"` // value|somevalue|novalue
Property string `json:"property"` // The ID of the property this Snak is about
DataType string `json:"datatype"` // Data types specified by Wikibase data model
// The actual value associated with the Snak (if the snaktype is "value")
DataValueInterpreter `json:"datavalue"`
}
func (snak *Snak) UnmarshalJSON(b []byte) error {
var tempSnak struct {
SnakType string `json:"snaktype"`
Property string `json:"property"`
DataType string `json:"datatype"`
DataValue json.RawMessage `json:datavalue`
}
err := json.Unmarshal(b, &tempSnak)
if err != nil {
return err
}
snak.SnakType = tempSnak.SnakType
snak.Property = tempSnak.Property
snak.DataType = tempSnak.DataType
err = json.Unmarshal(tempSnak.DataValue, &snak.DataValueInterpreter)
return err
}
type Qualifier struct{
Hash string `json:"hash"`
Snak
}
type Reference struct {
Hash string `json:"hash"`
Snaks map[string][]Snak `json:"snaks"`
}
type SiteLink struct {
Site string `json:"site"`
Title string `json:"title"`
Badges []string `json:"badges"`
Url string `json:"url"`
}