-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
58 lines (48 loc) · 1.52 KB
/
context.go
File metadata and controls
58 lines (48 loc) · 1.52 KB
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
package wotlib
// SchemaPrefix like wot, schema...
type SchemaPrefix string
// well know schemata
var (
SchemaWoT = SchemaMapping{
Prefix: SchemaPrefix("wot"),
IRI: "https://www.w3.org/2019/wot/td#",
}
SchemaHypermedia = SchemaMapping{
Prefix: SchemaPrefix("hypermedia"),
IRI: "https://www.w3.org/2019/wot/hypermedia#",
}
SchemaRdfType = SchemaMapping{
Prefix: SchemaPrefix("rdftype"),
IRI: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
}
SchemaJSON = SchemaMapping{
Prefix: SchemaPrefix("jsonschema"),
IRI: "https://www.w3.org/2019/wot/json-schema#",
}
)
// SchemaMapping defines a prefix iri mapping
type SchemaMapping struct {
Prefix SchemaPrefix
IRI string
}
// IRIPrefix builds a prefixed node name for referencing elements in
// a thing description. Eg. SchemaWoT.IRIPrefix(PropertyAffordance) would
// return "https://...#PropertyAffordance"
func (s SchemaMapping) IRIPrefix(nodeID string) string {
return string(s.IRI) + nodeID
}
func (p SchemaPrefix) String() string {
return string(p)
}
// AppendSchema appends a schema to the default context
func AppendSchema(m SchemaMapping) {
DefaultContext[m.Prefix.String()] = m.IRI
}
// DefaultContext defines the default context
// Modifications to existing prefixes will corrupt parsing process
var DefaultContext = map[string]interface{}{
SchemaWoT.Prefix.String(): SchemaWoT.IRI,
SchemaHypermedia.Prefix.String(): SchemaHypermedia.IRI,
SchemaRdfType.Prefix.String(): SchemaRdfType.IRI,
SchemaJSON.Prefix.String(): SchemaJSON.IRI,
}