Repository navigation
Expand file tree
/
Copy pathexample_4.bql
More file actions
78 lines (70 loc) · 2.34 KB
/
Copy pathexample_4.bql
File metadata and controls
78 lines (70 loc) · 2.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2016 Google Inc. All rights reserved.
#
# 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
#
# http://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.
# Create graph.
CREATE GRAPH ?info;
# Insert some data into the ?info graph.
INSERT DATA INTO ?info {
/u<joe> "bought"@[2016-01-01T00:00:00-08:00] /car<model x> .
/u<mary> "bought"@[2018-01-01T00:00:00-08:00] /car<model y> .
/u<joe> "bought"@[2020-01-01T00:00:00-08:00] /car<model z> .
/u<bob> "bought"@[2021-01-01T00:00:00-08:00] /car<model x> .
/u<joe> "meet"@[2012-01-01T00:00:00-08:00] /u<mary> .
/u<bob> "meet"@[2014-01-01T00:00:00-08:00] /u<joe> .
/u<joe> "height_cm"@[] "172"^^type:int64 .
/u<mary> "height_cm"@[] "174"^^type:int64 .
/u<bob> "height_cm"@[] "168"^^type:int64 .
/_<bn1> "_predicate"@[] "bought"@[2018-01-01T00:00:00-08:00] .
/_<bn2> "_predicate"@[] "height_cm"@[]
};
# What are all the immutable triples of the ?info graph?
SELECT ?s, ?p, ?o
FROM ?info
WHERE {
?s ?p ?o .
FILTER isImmutable(?p)
};
# What are all the temporal triples of the ?info graph?
SELECT ?s, ?p, ?o
FROM ?info
WHERE {
?s ?p ?o .
FILTER isTemporal(?p)
};
# What is all the information we have regarding the latest "bought"
# event in our graph? (Who was the last to buy what, and when?)
SELECT ?s, ?p, ?o
FROM ?info
WHERE {
?s "bought"@[?time] AS ?p ?o .
FILTER latest(?p)
};
# What are the latest triples of each time series present in the ?info
# graph?
SELECT ?s, ?p, ?o
FROM ?info
WHERE {
?s ?p ?o .
FILTER latest(?p)
};
# (note how "latest" automatically skips the immutable triples).
# What are the triples of the ?info graph for which the object is an
# immutable predicate (eg: reification scenario)?
SELECT ?s, ?p, ?o
FROM ?info
WHERE {
?s ?p ?o .
FILTER isImmutable(?o)
};
# Drop graph.
DROP GRAPH ?info;