-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueryBuilder.js
133 lines (117 loc) · 3.82 KB
/
queryBuilder.js
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
function queryForConceptId(family, uri, version) {
const uriParts = uri.split('/');
uriParts.pop();
const newUri = uriParts.join('/') + '/';
const depth = family === "prodcom" ? "3" : "5";
return `
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>
PREFIX : <${newUri}>
SELECT ?ID ?CODE ?LABEL
WHERE {
?conceptUri a skos:Concept;
skos:inScheme :${family}${version};
dc:identifier ?ID;
skos:notation ?CODE;
skos:altLabel ?LABEL.
FILTER (datatype(?CODE) = xsd:string && LANG(?LABEL) = "en")
?ClassLevel a xkos:ClassificationLevel;
skos:member ?conceptUri;
xkos:depth "${depth}"^^xsd:positiveInteger.
}
ORDER BY ASC(?ID)
`;
}
function correspondenceQuery(family){
return `
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?thisNotation ?thisYear ?pastYear ?nextYear ?correspondenceUri ?conceptSchemeUri
WHERE {
?conceptSchemeUri a skos:ConceptScheme ;
skos:notation ?thisNotation ;
xkos:belongsTo ?classSeries ;
owl:versionInfo ?thisYear .
OPTIONAL {
?conceptSchemeUri xkos:follows ?previousURI .
?previousURI owl:versionInfo ?pastYear .
}
OPTIONAL {
?nextURI xkos:follows ?conceptSchemeUri .
?nextURI owl:versionInfo ?nextYear .
OPTIONAL {
?correspondenceUri xkos:compares ?conceptSchemeUri, ?nextURI ;
xkos:madeOf ?association .
?association xkos:sourceConcept ?concept .
?concept skos:inScheme ?conceptSchemeUri .
}
}
#FILTER(regex(?thisYear, "\\d{4}"))
VALUES ?classSeries {
<http://data.europa.eu/2en/class-series/${family}>
<http://data.europa.eu/2en/classification-series/${family}>
}
}
ORDER BY DESC(?thisYear)
`
}
function forwardQuery(uri){
return `
PREFIX : <${uri}>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?ID ?CODE
WHERE {
: xkos:targetConcept ?targetConcept .
?targetConcept skos:notation ?CODE;
dc:identifier ?ID.
FILTER (DATATYPE(?CODE) = xsd:string)
}
`
}
function backwardQuery(uri, conceptId) {
return `
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX xkos: <http://rdf-vocabulary.ddialliance.org/xkos#>
PREFIX : <${uri}>
SELECT ?ID ?CODE
WHERE {
: xkos:madeOf ?Association.
?Association xkos:targetConcept ?Target.
?Target dc:identifier ?targetId.
FILTER(?targetId= "${conceptId}")
?Association xkos:sourceConcept ?Source.
?Source dc:identifier ?ID;
skos:notation ?CODE.
}
`
}
export function queryBuilder(callerId, family, uri, year, conceptId) {
if (callerId === "versions") {
const res = queryForConceptId(family, uri, year);
// console.log(res);
return res;
} else if (callerId === "families") {
const res = correspondenceQuery(family);
// console.log(res);
return res;
} else if (callerId === "pastConcepts") {
const res = backwardQuery(uri, conceptId);
// console.log(res);
// console.trace();
return res;
} else if (callerId === "futureConcepts") {
const res = forwardQuery(uri);
// console.log(res);
return res;
}
}