-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
97 lines (81 loc) · 3.04 KB
/
test.ts
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
import {QueryEngine} from "@comunica/query-sparql";
console.log("Hello world")
function buildQuery(
query: readonly string[],
prefixes: Record<string, string>): string {
return `
${Object.keys(prefixes).map(prefix => `PREFIX ${prefix}: <${prefixes[prefix]}>`).join("\n")}
SELECT *
WHERE {
${query.join(". \n")} .
}
`
}
const prefixes = {
schema: "http://schema.org/",
mv: "http://schema.mobivoc.org/",
gr: "http://purl.org/goodrelations/v1#",
vp: "https://data.velopark.be/openvelopark/vocabulary#",
vpt: "https://data.velopark.be/openvelopark/terms#"
}
const queryWithShape = `
?parking a <http://schema.mobivoc.org/BicycleParkingStation>.
GRAPH ?g {
VALUES ?type { vpt:BicycleLocker vpt:BicycleStand vpt:ResidentBicycleParking vpt:PublicBicycleParking }.
?section a ?type.
OPTIONAL {
?section schema:geo [
a schema:GeoCoordinates ;
schema:latitude ?latitude ;
schema:longitude ?longitude
] }.
OPTIONAL {
?x schema:geo [
a schema:GeoShape ;
schema:polygon ?shape
]
}.
}`
const queryWithoutShape = `
?parking a <http://schema.mobivoc.org/BicycleParkingStation>.
GRAPH ?g {
VALUES ?type { vpt:BicycleLocker vpt:BicycleStand vpt:ResidentBicycleParking vpt:PublicBicycleParking }.
?section a ?type.
OPTIONAL {
?section schema:geo [
a schema:GeoCoordinates ;
schema:latitude ?latitude ;
schema:longitude ?longitude
] }.
}`
const queryWithoutCoords = `
?parking a <http://schema.mobivoc.org/BicycleParkingStation>.
GRAPH ?g {
VALUES ?type { vpt:BicycleLocker vpt:BicycleStand vpt:ResidentBicycleParking vpt:PublicBicycleParking }.
?section a ?type.
OPTIONAL { ?section schema:geo ?geo }.
}`
let sources = ["NoShape.jsonld", "Shape.jsonld", "NoGeo.jsonld"]
let queries: Record<string, string> = {
withShape: queryWithShape,
withoutShape: queryWithoutShape,
noCoords: queryWithoutCoords
}
async function main() {
const comunica = new QueryEngine()
for (const source of sources) {
for (const queryName in queries) {
const query = queries[queryName]
const q = buildQuery([query], prefixes)
const url = "http://127.0.0.1:8080/"+source
// console.log("source is", url, q)
const bindingsStream = await comunica.queryBindings(
q, {sources: [url], lenient: true},
)
const bindings = await bindingsStream.toArray()
console.log("Got "+bindings.length+" bindings for "+url+" with query "+queryName+":")
// console.log(bindings.map(b => b.toString()).join(","))
}
}
}
main()