-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdf.go
120 lines (101 loc) · 2.11 KB
/
rdf.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (c) 2023 Z5Labs and Contributors
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package rdf
import (
rdfpb "github.com/z5labs/rdf/proto"
)
type Predicate string
func NewTriple(subject *rdfpb.Subject, predicate Predicate, object *rdfpb.Object) *rdfpb.Triple {
return &rdfpb.Triple{
Subject: subject,
Predicate: string(predicate),
Object: object,
}
}
func IriSubject(iri string) *rdfpb.Subject {
return &rdfpb.Subject{
Value: &rdfpb.Subject_Iri{
Iri: iri,
},
}
}
func BlankNodeSubject(blankNode string) *rdfpb.Subject {
return &rdfpb.Subject{
Value: &rdfpb.Subject_BlankNode{
BlankNode: blankNode,
},
}
}
func IriObject(iri string) *rdfpb.Object {
return &rdfpb.Object{
Value: &rdfpb.Object_Iri{
Iri: iri,
},
}
}
func BlankNodeObject(blankNode string) *rdfpb.Object {
return &rdfpb.Object{
Value: &rdfpb.Object_BlankNode{
BlankNode: blankNode,
},
}
}
func LiteralObject(literal *rdfpb.Literal) *rdfpb.Object {
return &rdfpb.Object{
Value: &rdfpb.Object_Literal{
Literal: literal,
},
}
}
func StringLiteral(s string) *rdfpb.Literal {
return &rdfpb.Literal{
Value: &rdfpb.Literal_String_{
String_: s,
},
}
}
func StringObject(s string) *rdfpb.Object {
return LiteralObject(StringLiteral(s))
}
func IntLiteral(i int64) *rdfpb.Literal {
return &rdfpb.Literal{
Value: &rdfpb.Literal_Int{
Int: i,
},
}
}
func IntObject(i int64) *rdfpb.Object {
return LiteralObject(IntLiteral(i))
}
func Float64Literal(f float64) *rdfpb.Literal {
return &rdfpb.Literal{
Value: &rdfpb.Literal_Float64{
Float64: f,
},
}
}
func Float64Object(f float64) *rdfpb.Object {
return LiteralObject(Float64Literal(f))
}
func BoolLiteral(b bool) *rdfpb.Literal {
return &rdfpb.Literal{
Value: &rdfpb.Literal_Bool{
Bool: b,
},
}
}
func BoolObject(b bool) *rdfpb.Object {
return LiteralObject(BoolLiteral(b))
}
func BytesLiteral(b []byte) *rdfpb.Literal {
return &rdfpb.Literal{
Value: &rdfpb.Literal_Bytes{
Bytes: b,
},
}
}
func BytesObject(b []byte) *rdfpb.Object {
return LiteralObject(BytesLiteral(b))
}