This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
/
lookups.go
292 lines (249 loc) · 7.06 KB
/
lookups.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
// Copyright 2019 eBay Inc.
// Primary authors: Simon Fell, Diego Ongaro,
// Raymond Kroeker, and Sathish Kandasamy.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package plandef
import (
"fmt"
"strings"
)
// InferPO is an Operator that starts at the given object and transitively
// follows predicate edges backwards to yield all reachable subjects.
type InferPO struct {
ID FreeTerm
Subject FreeTerm
Predicate FixedTerm
Object FixedTerm
}
func (op *InferPO) anOperator() {}
func (op *InferPO) String() string {
return fmt.Sprintf("InferPO(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *InferPO) Key(b *strings.Builder) {
lookupKey(b, "InferPO", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *InferPO) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// InferSP is an Operator that finds all transitive paths from a subject using
// the given predicate edges.
type InferSP struct {
ID FreeTerm
Subject FixedTerm
Predicate FixedTerm
Object FreeTerm
}
func (op *InferSP) anOperator() {}
func (op *InferSP) String() string {
return fmt.Sprintf("InferSP(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *InferSP) Key(b *strings.Builder) {
lookupKey(b, "InferSP", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *InferSP) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// InferSPO is an Operator that finds all transitive paths from subject to
// object using predicate edges.
type InferSPO struct {
ID FreeTerm
Subject FixedTerm
Predicate FixedTerm
// It's a bit of an open question, but we think this may only be an OID or a
// binding to an OID, never a literal or binding to a literal value.
// -Diego 2018-06-21
Object FixedTerm
}
func (op *InferSPO) anOperator() {}
func (op *InferSPO) String() string {
return fmt.Sprintf("InferSPO(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *InferSPO) Key(b *strings.Builder) {
lookupKey(b, "InferSPO", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *InferSPO) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// LookupPO is an Operator that finds static facts with the given predicate and object.
type LookupPO struct {
ID FreeTerm
Subject FreeTerm
Predicate FixedTerm
Object FixedTerm
}
func (op *LookupPO) anOperator() {}
func (op *LookupPO) String() string {
return fmt.Sprintf("LookupPO(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *LookupPO) Key(b *strings.Builder) {
lookupKey(b, "LookupPO", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *LookupPO) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// LookupPOCmp is an Operator that finds static facts with the given predicate
// and whose object is a literal value satisfying the given filter.
type LookupPOCmp struct {
ID FreeTerm
Subject FreeTerm
Predicate FixedTerm
Object *Variable
Cmp SelectClause
}
func (op *LookupPOCmp) anOperator() {}
func (op *LookupPOCmp) String() string {
return fmt.Sprintf("LookupPOCmp(%v %v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object, op.Cmp)
}
// Key implements cmp.Key.
func (op *LookupPOCmp) Key(b *strings.Builder) {
lookupKey(b, "LookupPOCmp", op.ID, op.Subject, op.Predicate, op.Object)
b.WriteByte(' ')
op.Cmp.Key(b)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *LookupPOCmp) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// LookupS is an Operator that finds static facts with the given subject.
type LookupS struct {
ID FreeTerm
Subject FixedTerm
Predicate FreeTerm
Object FreeTerm
}
func (op *LookupS) anOperator() {}
func (op *LookupS) String() string {
return fmt.Sprintf("LookupS(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *LookupS) Key(b *strings.Builder) {
lookupKey(b, "LookupS", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *LookupS) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// LookupSP is an Operator that finds static facts with the given subject and predicate.
type LookupSP struct {
ID FreeTerm
Subject FixedTerm
Predicate FixedTerm
Object FreeTerm
}
func (op *LookupSP) anOperator() {}
func (op *LookupSP) String() string {
return fmt.Sprintf("LookupSP(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *LookupSP) Key(b *strings.Builder) {
lookupKey(b, "LookupSP", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *LookupSP) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// LookupSPO is an Operator that finds the(?) static fact with the given subject, predicate, and object.
type LookupSPO struct {
ID FreeTerm
Subject FixedTerm
Predicate FixedTerm
Object FixedTerm
}
func (op *LookupSPO) anOperator() {}
func (op *LookupSPO) String() string {
return fmt.Sprintf("LookupSPO(%v %v %v %v)",
op.ID, op.Subject, op.Predicate, op.Object)
}
// Key implements cmp.Key.
func (op *LookupSPO) Key(b *strings.Builder) {
lookupKey(b, "LookupSPO", op.ID, op.Subject, op.Predicate, op.Object)
}
// Terms is a convenience method to fetch the ID, Subject, Predicate, Object in
// an iterable slice.
func (op *LookupSPO) Terms() []Term {
return []Term{
op.ID,
op.Subject,
op.Predicate,
op.Object,
}
}
// lookupKey is a helper for the Lookup/Infer Key() methods.
func lookupKey(b *strings.Builder, op string, id, subject, predicate, object Term) {
b.WriteString(op)
b.WriteByte(' ')
id.Key(b)
b.WriteByte(' ')
subject.Key(b)
b.WriteByte(' ')
predicate.Key(b)
b.WriteByte(' ')
object.Key(b)
}