-
Notifications
You must be signed in to change notification settings - Fork 46
/
incomingOneHopTemplate.ts
69 lines (64 loc) · 1.83 KB
/
incomingOneHopTemplate.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
import type { NeighborsRequest } from "../../AbstractConnector";
/**
* Fetch all neighbors whose source is the given vertex.
*
* @example
* sourceId = "http://www.example.com/soccer/resource#London_Stadium"
* vertexTypes = [
* "http://www.example.com/soccer/ontology/Stadium",
* "http://www.example.com/soccer/ontology/League"
* ]
* limit = 10
* offset = 0
*
* SELECT *
* {
* ?start ?property ?propertyValue
* {
* SELECT *
* {
* ?start ?edge <http://www.example.com/soccer/resource#London_Stadium>
* FILTER(!isLiteral(?start))
* {
* SELECT *
* {
* ?start a ?vertexType
* {
* SELECT *
* {
* ?target a ?targetVertexType
* FILTER(?target=<http://www.example.com/soccer/resource#London_Stadium>)
* }
* }
* FILTER(
* ?vertexType=<http://www.example.com/soccer/ontology/Stadium> ||
* ?vertexType=<http://www.example.com/soccer/ontology/League>
* )
* }
* }
* }
* LIMIT 10 OFFSET 0
* }
* }
*/
const incomingOneHopTemplate = ({
vertexId,
vertexTypes = [],
limit = 10,
offset = 0,
}: NeighborsRequest): string => {
let template = `SELECT * {?start ?property ?propertyValue { SELECT * {?start ?edge <${vertexId}> FILTER(!isLiteral(?start)) {SELECT * {?start a ?vertexType {SELECT * {?target a ?targetVertexType FILTER(?target=<${vertexId}>)}}`;
if (vertexTypes.length > 0) {
template += ` FILTER(`;
vertexTypes?.map((vt, vtIndex) => {
template += `?vertexType=<${vt}>`;
if (vtIndex < vertexTypes.length - 1) {
template += " || ";
}
});
template += `) `;
}
template += `}}} LIMIT ${limit} OFFSET ${offset} } }`;
return template;
};
export default incomingOneHopTemplate;