terminusdb 12.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Contributing.md +36 -0
- package/LICENSE +201 -0
- package/README.md +175 -0
- package/RELEASE_NOTES.md +462 -0
- package/dist/index.html +22 -0
- package/dist/terminusdb-client.min.js +3 -0
- package/dist/terminusdb-client.min.js.LICENSE.txt +188 -0
- package/dist/terminusdb-client.min.js.map +1 -0
- package/dist/typescript/index.d.ts +14 -0
- package/dist/typescript/lib/accessControl.d.ts +554 -0
- package/dist/typescript/lib/axiosInstance.d.ts +2 -0
- package/dist/typescript/lib/connectionConfig.d.ts +381 -0
- package/dist/typescript/lib/const.d.ts +54 -0
- package/dist/typescript/lib/dispatchRequest.d.ts +17 -0
- package/dist/typescript/lib/errorMessage.d.ts +25 -0
- package/dist/typescript/lib/query/woqlBuilder.d.ts +75 -0
- package/dist/typescript/lib/query/woqlCore.d.ts +341 -0
- package/dist/typescript/lib/query/woqlDoc.d.ts +63 -0
- package/dist/typescript/lib/query/woqlLibrary.d.ts +718 -0
- package/dist/typescript/lib/query/woqlPrinter.d.ts +71 -0
- package/dist/typescript/lib/query/woqlQuery.d.ts +833 -0
- package/dist/typescript/lib/typedef.d.ts +624 -0
- package/dist/typescript/lib/utils.d.ts +199 -0
- package/dist/typescript/lib/valueHash.d.ts +146 -0
- package/dist/typescript/lib/viewer/chartConfig.d.ts +62 -0
- package/dist/typescript/lib/viewer/chooserConfig.d.ts +38 -0
- package/dist/typescript/lib/viewer/documentFrame.d.ts +44 -0
- package/dist/typescript/lib/viewer/frameConfig.d.ts +74 -0
- package/dist/typescript/lib/viewer/frameRule.d.ts +145 -0
- package/dist/typescript/lib/viewer/graphConfig.d.ts +73 -0
- package/dist/typescript/lib/viewer/objectFrame.d.ts +212 -0
- package/dist/typescript/lib/viewer/streamConfig.d.ts +23 -0
- package/dist/typescript/lib/viewer/tableConfig.d.ts +66 -0
- package/dist/typescript/lib/viewer/terminusRule.d.ts +75 -0
- package/dist/typescript/lib/viewer/viewConfig.d.ts +47 -0
- package/dist/typescript/lib/viewer/woqlChart.d.ts +1 -0
- package/dist/typescript/lib/viewer/woqlChooser.d.ts +56 -0
- package/dist/typescript/lib/viewer/woqlGraph.d.ts +26 -0
- package/dist/typescript/lib/viewer/woqlPaging.d.ts +1 -0
- package/dist/typescript/lib/viewer/woqlResult.d.ts +128 -0
- package/dist/typescript/lib/viewer/woqlRule.d.ts +96 -0
- package/dist/typescript/lib/viewer/woqlStream.d.ts +31 -0
- package/dist/typescript/lib/viewer/woqlTable.d.ts +102 -0
- package/dist/typescript/lib/viewer/woqlView.d.ts +49 -0
- package/dist/typescript/lib/woql.d.ts +1267 -0
- package/dist/typescript/lib/woqlClient.d.ts +1216 -0
- package/index.js +28 -0
- package/lib/.eslintrc +1 -0
- package/lib/accessControl.js +988 -0
- package/lib/axiosInstance.js +5 -0
- package/lib/connectionConfig.js +765 -0
- package/lib/const.js +59 -0
- package/lib/dispatchRequest.js +236 -0
- package/lib/errorMessage.js +110 -0
- package/lib/query/woqlBuilder.js +234 -0
- package/lib/query/woqlCore.js +934 -0
- package/lib/query/woqlDoc.js +177 -0
- package/lib/query/woqlLibrary.js +1015 -0
- package/lib/query/woqlPrinter.js +476 -0
- package/lib/query/woqlQuery.js +1865 -0
- package/lib/typedef.js +248 -0
- package/lib/utils.js +817 -0
- package/lib/valueHash.js_old +581 -0
- package/lib/viewer/chartConfig.js +411 -0
- package/lib/viewer/chooserConfig.js +234 -0
- package/lib/viewer/documentFrame.js +206 -0
- package/lib/viewer/frameConfig.js +469 -0
- package/lib/viewer/frameRule.js +519 -0
- package/lib/viewer/graphConfig.js +345 -0
- package/lib/viewer/objectFrame.js +1550 -0
- package/lib/viewer/streamConfig.js +82 -0
- package/lib/viewer/tableConfig.js +310 -0
- package/lib/viewer/terminusRule.js +196 -0
- package/lib/viewer/viewConfig.js +219 -0
- package/lib/viewer/woqlChart.js +17 -0
- package/lib/viewer/woqlChooser.js +171 -0
- package/lib/viewer/woqlGraph.js +295 -0
- package/lib/viewer/woqlPaging.js +148 -0
- package/lib/viewer/woqlResult.js +258 -0
- package/lib/viewer/woqlRule.js +312 -0
- package/lib/viewer/woqlStream.js +27 -0
- package/lib/viewer/woqlTable.js +332 -0
- package/lib/viewer/woqlView.js +107 -0
- package/lib/woql.js +1693 -0
- package/lib/woqlClient.js +2091 -0
- package/package.json +110 -0
package/lib/woql.js
ADDED
|
@@ -0,0 +1,1693 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
/* eslint-disable no-underscore-dangle */
|
|
3
|
+
/* eslint no-trailing-spaces: ["error", { "ignoreComments": true }] */
|
|
4
|
+
/// /@ts-check
|
|
5
|
+
// I HAVE TO REVIEW THE Inheritance and the prototype chain
|
|
6
|
+
const WOQLQuery = require('./query/woqlBuilder');
|
|
7
|
+
const WOQLLibrary = require('./query/woqlLibrary');
|
|
8
|
+
const {
|
|
9
|
+
Vars, Var, Doc,
|
|
10
|
+
VarsUnique,
|
|
11
|
+
VarUnique,
|
|
12
|
+
SetVarsUniqueCounter,
|
|
13
|
+
} = require('./query/woqlDoc');
|
|
14
|
+
// eslint-disable-next-line no-unused-vars
|
|
15
|
+
const typedef = require('./typedef');
|
|
16
|
+
// eslint-disable-next-line no-unused-vars
|
|
17
|
+
const WOQLClient = require('./woqlClient');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @license Apache Version 2
|
|
21
|
+
* @module WOQL
|
|
22
|
+
* @constructor WOQL
|
|
23
|
+
* @description The WOQL object is a wrapper around the WOQLQuery object
|
|
24
|
+
* Syntactic sugar to allow writing WOQL.triple()... instead of new WOQLQuery().triple()
|
|
25
|
+
* Every function matches one of the public api functions of the woql query object
|
|
26
|
+
*/
|
|
27
|
+
const WOQL = {};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* WOQL primitives are WOQL.js functions which directly map onto words in
|
|
31
|
+
* the underlying JSON-LD language. All other WOQL.js functions are compound functions
|
|
32
|
+
* which translate into multiple WOQL primitives, or are helper functions which reduce
|
|
33
|
+
* the need to write verbose JSON-LD directly.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* WOQL Literals, Prefixes & IRI Constant
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* We expose all the real woql predicates via the WOQL object,
|
|
42
|
+
* for ease of typing all return a WOQL query object
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Query running against any specific commit Id
|
|
47
|
+
* @param {string} refPath - path to specific reference Id or commit Id
|
|
48
|
+
* @param {WOQLQuery} [subquery] - subquery for the specific commit point
|
|
49
|
+
* @returns {WOQLQuery}
|
|
50
|
+
* @example
|
|
51
|
+
* let [a, b, c] = vars("a", "b", "c")
|
|
52
|
+
* WOQL.using("userName/dbName/local/commit|branch/commitID").triple(a, b, c)
|
|
53
|
+
*/
|
|
54
|
+
WOQL.using = function (refPath, subquery) {
|
|
55
|
+
return new WOQLQuery().using(refPath, subquery);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Adds a text comment to a query - can also be used to wrap any part of a query to turn it off
|
|
60
|
+
* @param {string} comment - text comment
|
|
61
|
+
* @param {WOQLQuery} [subquery] - query that is "commented out"
|
|
62
|
+
* @returns {WOQLQuery}
|
|
63
|
+
*/
|
|
64
|
+
WOQL.comment = function (comment, subquery) {
|
|
65
|
+
return new WOQLQuery().comment(comment, subquery);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @example
|
|
70
|
+
* let [a, b, c] = vars("a", "b", "c")
|
|
71
|
+
* WOQL.select(a, triple(a, b, c))
|
|
72
|
+
* Filters the query so that only the variables included in [V1...Vn] are returned in the bindings
|
|
73
|
+
* @param {...string|...Var} varNames - only these variables are returned
|
|
74
|
+
* @returns {WOQLQuery}
|
|
75
|
+
*/
|
|
76
|
+
WOQL.select = function (...varNames) {
|
|
77
|
+
return new WOQLQuery().select(...varNames);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Filter the query to return only results that are distinct in the given variables
|
|
82
|
+
* @param {...string|...Var} varNames - these variables are guaranteed to be unique as a tuple
|
|
83
|
+
* @returns {WOQLQuery}
|
|
84
|
+
*/
|
|
85
|
+
WOQL.distinct = function (...varNames) {
|
|
86
|
+
return new WOQLQuery().distinct(...varNames);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Create a localized scope for variables to prevent leaking into outer scope
|
|
91
|
+
* @param {Object} paramSpec - Object mapping parameter names to values or null
|
|
92
|
+
* @returns {Array} - Returns [localized, v] with wrapper function and unique
|
|
93
|
+
* variable names
|
|
94
|
+
* @example
|
|
95
|
+
* const [localized, v] = WOQL.localize({
|
|
96
|
+
* consSubject: 'v:list',
|
|
97
|
+
* valueVar: 'v:value',
|
|
98
|
+
* last_cell: null // null creates a local-only variable
|
|
99
|
+
* });
|
|
100
|
+
* return localized(
|
|
101
|
+
* WOQL.and(
|
|
102
|
+
* WOQL.triple(v.consSubject, 'rdf:type', 'rdf:List'),
|
|
103
|
+
* WOQL.triple(v.last_cell, 'rdf:rest', 'rdf:nil')
|
|
104
|
+
* )
|
|
105
|
+
* );
|
|
106
|
+
*/
|
|
107
|
+
WOQL.localize = function (paramSpec) {
|
|
108
|
+
return new WOQLQuery().localize(paramSpec);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Logical conjunction of the contained queries - all queries must match or the entire clause fails
|
|
113
|
+
* @param {...WOQLQuery} subqueries - A list of one or more woql queries to execute as a conjunction
|
|
114
|
+
* @returns {WOQLQuery} - A WOQLQuery object containing the conjunction of queries
|
|
115
|
+
* @example
|
|
116
|
+
* //find triples that are of type scm:Journey, and have
|
|
117
|
+
* //a start_station Start, and that start_station is labeled Start_Label
|
|
118
|
+
* let [Journey, Start, Start_Label] = vars("Journey", "Start", "Start_Label")
|
|
119
|
+
* WOQL.and(
|
|
120
|
+
* WOQL.triple(Journey, "rdf:type", "@schema:Journey"),
|
|
121
|
+
* WOQL.triple(Journey, "start_station", Start),
|
|
122
|
+
* WOQL.triple(Start, "label", Start_Label))
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
WOQL.and = function (...subqueries) {
|
|
127
|
+
return new WOQLQuery().and(...subqueries);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Use {@link #read_document|read_document} instead.
|
|
132
|
+
* @deprecated
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
WOQL.read_object = function (IRI, output, formatObj) {
|
|
136
|
+
return new WOQLQuery().read_document(IRI, output, formatObj);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Read a node identified by an IRI as a JSON-LD document
|
|
141
|
+
* @param {string} IRI - The document id or a variable to read
|
|
142
|
+
* @param {string} output - Variable which will be bound to the document.
|
|
143
|
+
* @return {WOQLQuery} WOQLQuery
|
|
144
|
+
* @example
|
|
145
|
+
* let [person] = vars("Person")
|
|
146
|
+
* const query = WOQL.read_document(
|
|
147
|
+
* "Person/0b4feda109d9d13c9da809090b342ad9e4d8185545ce05f7cd20b97fe458f547",
|
|
148
|
+
* person
|
|
149
|
+
* );
|
|
150
|
+
* const res = await client.query(query);
|
|
151
|
+
*/
|
|
152
|
+
|
|
153
|
+
WOQL.read_document = function (IRI, output) {
|
|
154
|
+
return new WOQLQuery().read_document(IRI, output);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Insert a document in the graph.
|
|
159
|
+
* @param {object} docjson - The document to insert. Must either have an '@id' or
|
|
160
|
+
* have a class specified key.
|
|
161
|
+
* @param {string} [IRI] - An optional identifier specifying the document location.
|
|
162
|
+
* @return {WOQLQuery} WOQLQuery
|
|
163
|
+
* @example
|
|
164
|
+
* const res = await client.query(
|
|
165
|
+
* WOQL.insert_document(WOQL.doc({ "@type" : "Person", "label": "John" }))
|
|
166
|
+
* )
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
WOQL.insert_document = function (docjson, IRI) {
|
|
170
|
+
return new WOQLQuery().insert_document(docjson, IRI);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Update a document identified by an IRI
|
|
175
|
+
* @param {object} docjson - The document to update. Must either have an '@id' or
|
|
176
|
+
* have a class specified key.
|
|
177
|
+
* @param {string} [IRI] - An optional identifier specifying the document location.
|
|
178
|
+
* @return {object} WOQLQuery
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
WOQL.update_document = function (docjson, IRI) {
|
|
182
|
+
return new WOQLQuery().update_document(docjson, IRI);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Delete a document from the graph.
|
|
187
|
+
* @param {string} IRI - The document id or a variable
|
|
188
|
+
* @return {WOQLQuery} WOQLQuery
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
WOQL.delete_document = function (IRI) {
|
|
192
|
+
return new WOQLQuery().delete_document(IRI);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Creates a logical OR of the arguments
|
|
197
|
+
* @param {...WOQLQuery} subqueries - A list of one or more woql queries
|
|
198
|
+
* to execute as alternatives
|
|
199
|
+
* @returns {WOQLQuery} - A WOQLQuery object containing the logical Or of the subqueries
|
|
200
|
+
* @example
|
|
201
|
+
* let [Subject] = vars("Subject")
|
|
202
|
+
* or(
|
|
203
|
+
* triple(Subject, 'label', "A"),
|
|
204
|
+
* triple(Subject, "label", "a")
|
|
205
|
+
* )
|
|
206
|
+
*/
|
|
207
|
+
WOQL.or = function (...subqueries) {
|
|
208
|
+
return new WOQLQuery().or(...subqueries);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Specifies the database URL that will be the default database for the enclosed query
|
|
213
|
+
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
|
|
214
|
+
* @param {WOQLQuery} [query] - The query
|
|
215
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the from expression
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
WOQL.from = function (graphRef, query) {
|
|
219
|
+
return new WOQLQuery().from(graphRef, query);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Specifies the graph resource to write the contained query into
|
|
224
|
+
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
|
|
225
|
+
* @param {WOQLQuery} [subquery] - The query which will be written into the graph
|
|
226
|
+
* @returns {WOQLQuery} A WOQLQuery which will be written into the graph in question
|
|
227
|
+
* @example
|
|
228
|
+
* //Subq is an argument or a chained query
|
|
229
|
+
* using("admin/minecraft").into("instance/main").add_triple("a", "rdf:type", "@schema:X")
|
|
230
|
+
* //writes a single tripe (doc:a, rdf:type, scm:X) into the main instance graph
|
|
231
|
+
*
|
|
232
|
+
*/
|
|
233
|
+
WOQL.into = function (graphRef, subquery) {
|
|
234
|
+
return new WOQLQuery().into(graphRef, subquery);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate, Object)
|
|
239
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
240
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
241
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
242
|
+
* @returns {WOQLQuery}
|
|
243
|
+
*/
|
|
244
|
+
WOQL.triple = function (subject, predicate, object) {
|
|
245
|
+
return new WOQLQuery().triple(subject, predicate, object);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate,
|
|
250
|
+
* Object) added in the current layer
|
|
251
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
252
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
253
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
254
|
+
* @returns {WOQLQuery}
|
|
255
|
+
*/
|
|
256
|
+
WOQL.added_triple = function (subject, predicate, object) {
|
|
257
|
+
return new WOQLQuery().added_triple(subject, predicate, object);
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Creates a triple pattern matching rule for the triple [S, P, O] (Subject, Predicate,
|
|
262
|
+
* Object) added in the current commit
|
|
263
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
264
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
265
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
266
|
+
* @returns {WOQLQuery}
|
|
267
|
+
*/
|
|
268
|
+
WOQL.removed_triple = function (subject, predicate, object) {
|
|
269
|
+
return new WOQLQuery().removed_triple(subject, predicate, object);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
|
|
274
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
275
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
276
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
277
|
+
* @param {typedef.GraphRef} graphRef - A valid graph resource identifier string
|
|
278
|
+
* @returns {WOQLQuery}
|
|
279
|
+
*/
|
|
280
|
+
WOQL.quad = function (subject, predicate, object, graphRef) {
|
|
281
|
+
return new WOQLQuery().quad(subject, predicate, object, graphRef);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate,
|
|
286
|
+
* Object, Graph) removed from the current commit
|
|
287
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
288
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
289
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
290
|
+
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
|
|
291
|
+
* @returns {WOQLQuery}
|
|
292
|
+
*/
|
|
293
|
+
WOQL.added_quad = function (subject, predicate, object, graphRef) {
|
|
294
|
+
return new WOQLQuery().added_quad(subject, predicate, object, graphRef);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Creates a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate,
|
|
299
|
+
* Object, Graph) removed from the current commit
|
|
300
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
301
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
302
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
303
|
+
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
|
|
304
|
+
* @returns {WOQLQuery}
|
|
305
|
+
*/
|
|
306
|
+
WOQL.removed_quad = function (subject, predicate, object, graphRef) {
|
|
307
|
+
return new WOQLQuery().removed_quad(subject, predicate, object, graphRef);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Returns true if ClassA subsumes ClassB, according to the current DB schema
|
|
312
|
+
* @param {string} classA - ClassA
|
|
313
|
+
* @param {string} classB - ClassB
|
|
314
|
+
* @returns {WOQLQuery} WOQLQuery
|
|
315
|
+
*/
|
|
316
|
+
WOQL.sub = function (classA, classB) {
|
|
317
|
+
return new WOQLQuery().sub(classA, classB);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
WOQL.subsumption = function (classA, classB) {
|
|
321
|
+
return new WOQLQuery().sub(classA, classB);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Matches if a is equal to b
|
|
326
|
+
* @param {string|number|boolean|array|Var} varName - literal, variable, array, or id
|
|
327
|
+
* @param {string|number|boolean|array|Var} varValue - literal, variable, array, or id
|
|
328
|
+
* @returns {WOQLQuery}
|
|
329
|
+
*
|
|
330
|
+
*
|
|
331
|
+
*/
|
|
332
|
+
WOQL.eq = function (varName, varValue) {
|
|
333
|
+
return new WOQLQuery().eq(varName, varValue);
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
WOQL.equals = function (varName, varValue) {
|
|
337
|
+
return new WOQLQuery().eq(varName, varValue);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Substring of string
|
|
342
|
+
* @param {string|Var} string - String or variable
|
|
343
|
+
* @param {number|Var} before - integer or variable (characters from start to begin)
|
|
344
|
+
* @param {number|Var} [length] - integer or variable (length of substring)
|
|
345
|
+
* @param {number|Var} [after] - integer or variable (number of characters after substring)
|
|
346
|
+
* @param {string|Var} [substring] - String or variable
|
|
347
|
+
* @returns {WOQLQuery}
|
|
348
|
+
* @example
|
|
349
|
+
* let [after, result] = vars("after", "result")
|
|
350
|
+
* substr("joe", 1, 2, after, result)
|
|
351
|
+
* //result is "oe", after is 2
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
WOQL.substr = function (string, before, length, after, substring) {
|
|
355
|
+
return new WOQLQuery().substr(string, before, length, after, substring);
|
|
356
|
+
};
|
|
357
|
+
WOQL.substring = function (string, before, length, after, substring) {
|
|
358
|
+
return new WOQLQuery().substr(string, before, length, after, substring);
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Use the document interface to import documents
|
|
363
|
+
* @deprecated
|
|
364
|
+
* Retrieves the exernal resource defined by QueryResource and copies values
|
|
365
|
+
* from it into variables defined in AsVars
|
|
366
|
+
* @param {Vars | array<Var>} asvars - an array of AsVar variable mappings (see as for format below)
|
|
367
|
+
* @param {WOQLQuery} queryResource - an external resource (remote, file, post) to query
|
|
368
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the get expression
|
|
369
|
+
* @example
|
|
370
|
+
* let [a, b] = vars("a", "b")
|
|
371
|
+
* get(as("a", a).as("b", b)).remote("http://my.url.com/x.csv")
|
|
372
|
+
* //copies the values from column headed "a" into a variable a and from column
|
|
373
|
+
* //"b" into a variable b from remote CSV
|
|
374
|
+
*/
|
|
375
|
+
WOQL.get = function (asvars, queryResource) {
|
|
376
|
+
return new WOQLQuery().get(asvars, queryResource);
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Use the document interface to import documents
|
|
381
|
+
* @deprecated
|
|
382
|
+
* @put Outputs the results of a query to a file
|
|
383
|
+
* @param {Vars | array<Var>} varsToExp - an array of AsVar variable
|
|
384
|
+
* mappings (see as for format below)
|
|
385
|
+
* @param {WOQLQuery} query - The query which will be executed to produce the results
|
|
386
|
+
* @param {string} fileResource - an file resource local to the server
|
|
387
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the put expression
|
|
388
|
+
*/
|
|
389
|
+
WOQL.put = function (varsToExp, query, fileResource) {
|
|
390
|
+
return new WOQLQuery().put(varsToExp, query, fileResource);
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Imports the value identified by Source to a Target variable
|
|
395
|
+
* @param {string | number | Var} source - Source
|
|
396
|
+
* @param {string | Var} target - Target
|
|
397
|
+
* @param {string} [type] - type to cast value to string|number etc...
|
|
398
|
+
* @returns {WOQLQuery}
|
|
399
|
+
* @example
|
|
400
|
+
* let [First_Var, Second_Var] = vars('First_Var', 'Second_Var')
|
|
401
|
+
* WOQL.as("first var", First_Var, "xsd:string").as("second var", Second_Var)
|
|
402
|
+
* WOQL.as(["first var", First_Var, "xsd:string"], ["second var", Second_Var])
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
WOQL.as = function (source, target, type) {
|
|
406
|
+
return new WOQLQuery().as(source, target, type);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Identifies a remote resource by URL and specifies the format of the resource through the options
|
|
411
|
+
* @param {object} remoteObj - The URL at which the remote resource can be accessed
|
|
412
|
+
* @param {typedef.DataFormatObj} [formatObj] - The format of the resource data {}
|
|
413
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the remote resource identifier
|
|
414
|
+
* @example
|
|
415
|
+
* remote({url:"http://url.of.resource"}, {type: "csv"})
|
|
416
|
+
*/
|
|
417
|
+
//
|
|
418
|
+
WOQL.remote = function (remoteObj, formatObj) {
|
|
419
|
+
return new WOQLQuery().remote(remoteObj, formatObj);
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Identifies a resource as a local path on the client, to be sent to the server through a
|
|
424
|
+
* HTTP POST request, with the format defined through the options
|
|
425
|
+
* @param {string} url - The Path on the server at which the file resource can be accessed
|
|
426
|
+
* @param {typedef.DataFormatObj} [formatObj] - imput options, optional
|
|
427
|
+
* @param {string} [source] - It defines the source of the file, it can be 'url','post'
|
|
428
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Post resource identifier
|
|
429
|
+
* @example
|
|
430
|
+
* post("/.../.../", {type:'csv'})
|
|
431
|
+
*/
|
|
432
|
+
WOQL.post = function (url, formatObj, source) {
|
|
433
|
+
return new WOQLQuery().post(url, formatObj, source);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Deletes a single triple from the default graph of the database
|
|
438
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
439
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
440
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
441
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the Triple Deletion statement
|
|
442
|
+
* @example
|
|
443
|
+
* delete_triple("john", "age", 42)
|
|
444
|
+
*/
|
|
445
|
+
WOQL.delete_triple = function (subject, predicate, object) {
|
|
446
|
+
return new WOQLQuery().delete_triple(subject, predicate, object);
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Deletes a single triple from the graph [Subject, Predicate, Object, Graph]
|
|
451
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
452
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
453
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
454
|
+
* @param {typedef.GraphRef} graphRef - A valid graph resource identifier string
|
|
455
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the Delete Quad Statement
|
|
456
|
+
* @example remove the class Person from the schema graph
|
|
457
|
+
* WOQL.delete_quad("Person", "rdf:type", "sys:Class", "schema")
|
|
458
|
+
*/
|
|
459
|
+
WOQL.delete_quad = function (subject, predicate, object, graphRef) {
|
|
460
|
+
return new WOQLQuery().delete_quad(subject, predicate, object, graphRef);
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Adds triples according to the the pattern [subject,predicate,object]
|
|
465
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
466
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
467
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
468
|
+
* @returns {WOQLQuery}
|
|
469
|
+
*/
|
|
470
|
+
WOQL.add_triple = function (subject, predicate, object) {
|
|
471
|
+
return new WOQLQuery().add_triple(subject, predicate, object);
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Adds quads according to the pattern [S,P,O,G]
|
|
476
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
477
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
478
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
479
|
+
* @param {typedef.GraphRef} graphRef- A valid graph resource identifier string
|
|
480
|
+
* @returns {WOQLQuery}
|
|
481
|
+
*/
|
|
482
|
+
WOQL.add_quad = function (subject, predicate, object, graphRef) {
|
|
483
|
+
return new WOQLQuery().add_quad(subject, predicate, object, graphRef);
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
*
|
|
488
|
+
* When the subquery is met, the update query is executed
|
|
489
|
+
* @param {WOQLQuery} subquery - the condition query
|
|
490
|
+
* @param {WOQLQuery} [updateQuery]
|
|
491
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the when expression
|
|
492
|
+
* @example
|
|
493
|
+
* when(true()).triple("a", "b", "c")
|
|
494
|
+
*/
|
|
495
|
+
|
|
496
|
+
// Functions which take a query as an argument advance the cursor to make the chaining
|
|
497
|
+
// of queries fall into the corrent place in the encompassing json.
|
|
498
|
+
/* WOQL.when = function(subquery, updateQuery) {
|
|
499
|
+
return new WOQLQuery().when(subquery, updateQuery)
|
|
500
|
+
} */
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
*
|
|
504
|
+
* Remove whitespace from both sides of a string:
|
|
505
|
+
* @param {string|Var} inputStr - A string or variable containing
|
|
506
|
+
* the untrimmed version of the string
|
|
507
|
+
* @param {string|Var} resultVarName - A string or variable
|
|
508
|
+
* containing the trimmed version of the string
|
|
509
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Trim pattern matching expression
|
|
510
|
+
* @example
|
|
511
|
+
* let [trimmed] = vars("trimmed")
|
|
512
|
+
* trim("hello ", trimmed)
|
|
513
|
+
* //trimmed contains "hello"
|
|
514
|
+
*/
|
|
515
|
+
WOQL.trim = function (inputStr, resultVarName) {
|
|
516
|
+
return new WOQLQuery().trim(inputStr, resultVarName);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
*
|
|
521
|
+
* Evaluates the passed arithmetic expression and generates or matches the result value
|
|
522
|
+
* @param {object| WOQLQuery | string} arithExp - A WOQL query containing a valid WOQL Arithmetic
|
|
523
|
+
* Expression, which is evaluated by the function
|
|
524
|
+
* @param {string|number|Var} resultVarName - Either a variable, in which the result of the
|
|
525
|
+
* expression will be stored, or a numeric literal which will be used as a test of result of
|
|
526
|
+
* the evaluated expression
|
|
527
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Arithmetic function
|
|
528
|
+
* @example
|
|
529
|
+
* let [result] = vars("result")
|
|
530
|
+
* evaluate(plus(2, minus(3, 1)), result)
|
|
531
|
+
*/
|
|
532
|
+
WOQL.evaluate = function (arithExp, resultVarName) {
|
|
533
|
+
return new WOQLQuery().eval(arithExp, resultVarName);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
*
|
|
538
|
+
* Evaluates the passed arithmetic expression and generates or matches the result value
|
|
539
|
+
* @param {object| WOQLQuery | string} arithExp - A WOQL query containing a valid WOQL Arithmetic
|
|
540
|
+
* Expression, which is evaluated by the function
|
|
541
|
+
* @param {string|number|Var} resultVarName - Either a variable, in which the result of the
|
|
542
|
+
* expression will be stored, or a numeric literal which will be used as a test of result of
|
|
543
|
+
* the evaluated expression
|
|
544
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Arithmetic function
|
|
545
|
+
* @example
|
|
546
|
+
* let [result] = vars("result")
|
|
547
|
+
* eval(plus(2, minus(3, 1)), result)
|
|
548
|
+
* @deprecated Use {@link evaluate} instead. The name 'eval' conflicts with JavaScript's
|
|
549
|
+
* built-in eval in strict mode.
|
|
550
|
+
* @internal
|
|
551
|
+
*/
|
|
552
|
+
WOQL.eval = function (arithExp, resultVarName) {
|
|
553
|
+
return new WOQLQuery().eval(arithExp, resultVarName);
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
*
|
|
558
|
+
* Adds the numbers together
|
|
559
|
+
* @param {...(string|number|Var)} args - a variable or numeric containing the values to add
|
|
560
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the addition expression
|
|
561
|
+
* @example
|
|
562
|
+
* let [result] = vars("result")
|
|
563
|
+
* evaluate(plus(2, plus(3, 1)), result)
|
|
564
|
+
*/
|
|
565
|
+
WOQL.plus = function (...args) {
|
|
566
|
+
return new WOQLQuery().plus(...args);
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
*
|
|
571
|
+
* Subtracts Numbers N1..Nn
|
|
572
|
+
* @param {...(string|number|Var)} args - variable or numeric containing the value that will be
|
|
573
|
+
* subtracted from
|
|
574
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the subtraction expression
|
|
575
|
+
* @example
|
|
576
|
+
* let [result] = vars("result")
|
|
577
|
+
* evaluate(minus(2.1, plus(0.2, 1)), result)
|
|
578
|
+
*/
|
|
579
|
+
WOQL.minus = function (...args) {
|
|
580
|
+
return new WOQLQuery().minus(...args);
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
*
|
|
585
|
+
* Multiplies numbers N1...Nn together
|
|
586
|
+
* @param {...(string|number|Var)} args - a variable or numeric containing the value
|
|
587
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the multiplication expression
|
|
588
|
+
* @example
|
|
589
|
+
* let [result] = vars("result")
|
|
590
|
+
* evaluate(times(10, minus(2.1, plus(0.2, 1))), result)
|
|
591
|
+
* //result contains 9.000000000000002y
|
|
592
|
+
*/
|
|
593
|
+
WOQL.times = function (...args) {
|
|
594
|
+
return new WOQLQuery().times(...args);
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
*
|
|
599
|
+
* Divides numbers N1...Nn by each other left, to right precedence
|
|
600
|
+
* @param {...(string|number|Var )} args - numbers to tbe divided
|
|
601
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the division expression
|
|
602
|
+
* let [result] = vars("result")
|
|
603
|
+
* evaluate(divide(times(10, minus(2.1, plus(0.2, 1))), 10), result)
|
|
604
|
+
* //result contains 0.9000000000000001
|
|
605
|
+
*/
|
|
606
|
+
WOQL.divide = function (...args) {
|
|
607
|
+
return new WOQLQuery().divide(...args);
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
*
|
|
612
|
+
* Division - integer division - args are divided left to right
|
|
613
|
+
* @param {...(string|number|Var)} args - numbers for division
|
|
614
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the division expression
|
|
615
|
+
* @example
|
|
616
|
+
* let [result] = vars("result")
|
|
617
|
+
* evaluate(div(10, 3), result)
|
|
618
|
+
* //result contains 3
|
|
619
|
+
*/
|
|
620
|
+
WOQL.div = function (...args) {
|
|
621
|
+
return new WOQLQuery().div(...args);
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
/*
|
|
625
|
+
* @param {integer or double} a - base number
|
|
626
|
+
* @param {integer or double} b - power of
|
|
627
|
+
* @returns {object} WOQLQuery */
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
*
|
|
631
|
+
* Exponent - raises varNum01 to the power of varNum02
|
|
632
|
+
* @param {string|number|Var} varNum - a variable or numeric containing the number to be
|
|
633
|
+
* raised to the power of the second number
|
|
634
|
+
* @param {number} expNum - a variable or numeric containing the exponent
|
|
635
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the exponent expression
|
|
636
|
+
* @example
|
|
637
|
+
* let [result] = vars("result")
|
|
638
|
+
* evaluate(exp(3, 2), result)
|
|
639
|
+
* //result contains 9
|
|
640
|
+
*/
|
|
641
|
+
WOQL.exp = function (varNum, expNum) {
|
|
642
|
+
return new WOQLQuery().exp(varNum, expNum);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
*
|
|
647
|
+
* Generates the nearest lower integer to the passed number
|
|
648
|
+
* @param {string|number|Var} varNum - Variable or numeric containing the number to be floored
|
|
649
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the floor expression
|
|
650
|
+
* @example
|
|
651
|
+
* let [result] = vars("result")
|
|
652
|
+
* evaluate(divide(floor(times(10, minus(2.1, plus(0.2, 1)))), 10), result)
|
|
653
|
+
* //result contains 0.9 - floating point error removed
|
|
654
|
+
*/
|
|
655
|
+
WOQL.floor = function (varNum) {
|
|
656
|
+
return new WOQLQuery().floor(varNum);
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
*
|
|
661
|
+
* Tests whether a given instance IRI has type Class, according to the current state of the DB
|
|
662
|
+
* @param {string|Var} instanceIRI - A string IRI or a variable that identify the class instance
|
|
663
|
+
* @param {string|Var} classId - A Class IRI or a variable
|
|
664
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the type test
|
|
665
|
+
* @example
|
|
666
|
+
* let [subject] = vars("subject")
|
|
667
|
+
* isa(subject, "Person")
|
|
668
|
+
*/
|
|
669
|
+
WOQL.isa = function (instanceIRI, classId) {
|
|
670
|
+
return new WOQLQuery().isa(instanceIRI, classId);
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
*
|
|
675
|
+
* Generates a string Leverstein distance measure between stringA and stringB
|
|
676
|
+
* @param {string|Var} stringA - string literal or variable representing a string to be compared
|
|
677
|
+
* @param {string|Var } stringB - string literal or variable
|
|
678
|
+
* representing the other string to be compared
|
|
679
|
+
* @param {number|string|Var} distance - variable representing the distance between the variables
|
|
680
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Like pattern matching expression
|
|
681
|
+
* @example
|
|
682
|
+
* let [dist] = vars('dist')
|
|
683
|
+
* like("hello", "hallo", dist)
|
|
684
|
+
* //dist contains 0.7265420560747664
|
|
685
|
+
*/
|
|
686
|
+
WOQL.like = function (stringA, stringB, distance) {
|
|
687
|
+
return new WOQLQuery().like(stringA, stringB, distance);
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
*
|
|
692
|
+
* Compares the value of v1 against v2 and returns true if v1 is less than v2
|
|
693
|
+
* @param {string|number|Var} varNum01 - a variable or numeric containing
|
|
694
|
+
* the number to be compared
|
|
695
|
+
* @param {string|number|Var} varNum02 - a variable or numeric containing the second comporator
|
|
696
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the comparison expression
|
|
697
|
+
* @example
|
|
698
|
+
* let [result] = vars("result")
|
|
699
|
+
* less(1, 1.1).eq(result, literal(true, "boolean"))
|
|
700
|
+
* //result contains true
|
|
701
|
+
*/
|
|
702
|
+
WOQL.less = function (varNum01, varNum02) {
|
|
703
|
+
return new WOQLQuery().less(varNum01, varNum02);
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
*
|
|
708
|
+
* Compares the value of v1 against v2 and returns true if v1 is greater than v2
|
|
709
|
+
* @param {string|number|Var} varNum01 - a variable or numeric containing the number to be compared
|
|
710
|
+
* @param {string|number|Var} varNum02 - a variable or numeric containing the second comporator
|
|
711
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the comparison expression
|
|
712
|
+
* @example
|
|
713
|
+
* let [result] = vars("result")
|
|
714
|
+
* greater(1.2, 1.1).eq(result, literal(true, "boolean"))
|
|
715
|
+
* //result contains true
|
|
716
|
+
*/
|
|
717
|
+
WOQL.greater = function (varNum01, varNum02) {
|
|
718
|
+
return new WOQLQuery().greater(varNum01, varNum02);
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
*
|
|
723
|
+
* Specifies that the Subquery is optional - if it does not match the query will not fail
|
|
724
|
+
* @param {WOQLQuery} [subquery] - A subquery which will be optionally matched
|
|
725
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the optional sub Query
|
|
726
|
+
* @example
|
|
727
|
+
* let [subject] = vars("subject")
|
|
728
|
+
* opt(triple(subject, 'label', "A"))
|
|
729
|
+
* //Subq is an argument or a chained query
|
|
730
|
+
* opt().triple(subject, 'label', "A")
|
|
731
|
+
*/
|
|
732
|
+
WOQL.opt = function (subquery) {
|
|
733
|
+
return new WOQLQuery().opt(subquery);
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
WOQL.optional = function (subquery) {
|
|
737
|
+
return new WOQLQuery().opt(subquery);
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
*
|
|
742
|
+
* Generate a new IRI from the prefix and a hash of the variables which will be unique for any
|
|
743
|
+
* given combination of variables
|
|
744
|
+
* @param {string} prefix - A prefix for the IRI - typically formed of the doc prefix and the
|
|
745
|
+
* classtype of the entity (“doc:Person”)
|
|
746
|
+
* @param {array|string|Var} inputVarList - An array of variables and / or strings from which the
|
|
747
|
+
* unique hash will be generated
|
|
748
|
+
* @param {string|Var} resultVarName - Variable in which the unique ID is stored
|
|
749
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the unique ID generating function
|
|
750
|
+
* @example
|
|
751
|
+
* let [newid] = vars("newid")
|
|
752
|
+
* unique("doc:Person", ["John", "Smith"], newid)
|
|
753
|
+
*/
|
|
754
|
+
WOQL.unique = function (prefix, inputVarList, resultVarName) {
|
|
755
|
+
return new WOQLQuery().unique(prefix, inputVarList, resultVarName);
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
*
|
|
760
|
+
* Generate a new IRI from the prefix and concatention of the variables
|
|
761
|
+
* @param {string} prefix - A prefix for the IRI - typically formed of the doc prefix and the
|
|
762
|
+
* classtype of the entity (“doc:Person”)
|
|
763
|
+
* @param {array|string|Var} inputVarList - An array of variables and / or strings from which the
|
|
764
|
+
* unique hash will be generated
|
|
765
|
+
* @param {string|Var} resultVarName - Variable in which the unique ID is stored
|
|
766
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the ID generating function
|
|
767
|
+
* @example
|
|
768
|
+
* let [newid] = vars("newid")
|
|
769
|
+
* idgen("doc:Person", ["John", "Smith"], newid)
|
|
770
|
+
*/
|
|
771
|
+
WOQL.idgen = function (prefix, inputVarList, resultVarName) {
|
|
772
|
+
return new WOQLQuery().idgen(prefix, inputVarList, resultVarName);
|
|
773
|
+
};
|
|
774
|
+
WOQL.idgenerator = function (prefix, inputVarList, resultVarName) {
|
|
775
|
+
return new WOQLQuery().idgen(prefix, inputVarList, resultVarName);
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Generates a random ID with a specified prefix
|
|
780
|
+
* @param {string} prefix - prefix for the generated ID
|
|
781
|
+
* @param {string} resultVarName - variable that stores the generated ID
|
|
782
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the random ID generation function
|
|
783
|
+
* @example
|
|
784
|
+
* let [newid] = vars("newid")
|
|
785
|
+
* idgen_random("Person/", newid)
|
|
786
|
+
*/
|
|
787
|
+
WOQL.idgen_random = function (prefix, resultVarName) {
|
|
788
|
+
return new WOQLQuery().idgen_random(prefix, resultVarName);
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Backward-compatible alias for idgen_random
|
|
793
|
+
* @deprecated Use idgen_random instead
|
|
794
|
+
* @param {string} prefix - prefix for the generated ID
|
|
795
|
+
* @param {string} resultVarName - variable that stores the generated ID
|
|
796
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the random ID generation function
|
|
797
|
+
*/
|
|
798
|
+
WOQL.random_idgen = function (prefix, resultVarName) {
|
|
799
|
+
return new WOQLQuery().idgen_random(prefix, resultVarName);
|
|
800
|
+
};
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
*
|
|
804
|
+
* Changes a string to upper-case
|
|
805
|
+
* @param {string|Var} inputVarName - string or variable representing the uncapitalized string
|
|
806
|
+
* @param {string|Var} resultVarName - variable that stores the capitalized string output
|
|
807
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Upper case pattern matching expression
|
|
808
|
+
* @example
|
|
809
|
+
* let [allcaps] = vars("allcaps")
|
|
810
|
+
* upper("aBCe", allcaps)
|
|
811
|
+
* //upper contains "ABCE"
|
|
812
|
+
*/
|
|
813
|
+
WOQL.upper = function (inputVarName, resultVarName) {
|
|
814
|
+
return new WOQLQuery().upper(inputVarName, resultVarName);
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
*
|
|
819
|
+
* Changes a string to lower-case
|
|
820
|
+
* @param {string|Var} inputVarName - string or variable representing the non-lowercased string
|
|
821
|
+
* @param {string|Var} resultVarName - variable that stores the lowercased string output
|
|
822
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Lower case pattern matching expression
|
|
823
|
+
* @example
|
|
824
|
+
* let [lower] = var("l")
|
|
825
|
+
* lower("aBCe", lower)
|
|
826
|
+
* //lower contains "abce"
|
|
827
|
+
*/
|
|
828
|
+
WOQL.lower = function (inputVarName, resultVarName) {
|
|
829
|
+
return new WOQLQuery().lower(inputVarName, resultVarName);
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
*
|
|
834
|
+
* Pads out the string input to be exactly len long by appending the pad character pad to
|
|
835
|
+
* form output
|
|
836
|
+
* @param {string|Var} inputVarName - The input string or variable in unpadded state
|
|
837
|
+
* @param {string|Var} pad - The characters to use to pad the string or a variable representing them
|
|
838
|
+
* @param {number | string | Var} len - The variable or integer value representing the length of
|
|
839
|
+
* the output string
|
|
840
|
+
* @param {string|Var} resultVarName - stores output
|
|
841
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Pad pattern matching expression
|
|
842
|
+
* @example
|
|
843
|
+
* let [fixed] = vars("fixed length")
|
|
844
|
+
* pad("joe", " ", 8, fixed)
|
|
845
|
+
* //fixed contains "joe "
|
|
846
|
+
*/
|
|
847
|
+
WOQL.pad = function (inputVarName, pad, len, resultVarName) {
|
|
848
|
+
return new WOQLQuery().pad(inputVarName, pad, len, resultVarName);
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Splits a string (Input) into a list strings (Output) by removing separator
|
|
853
|
+
* @param {string|Var} inputVarName - A string or variable representing the unsplit string
|
|
854
|
+
* @param {string|Var} separator - A string or variable containing a sequence of charatcters
|
|
855
|
+
* to use as a separator
|
|
856
|
+
* @param {string|Var} resultVarName - variable that stores output list
|
|
857
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Split pattern matching expression
|
|
858
|
+
* @example
|
|
859
|
+
* let [words] = vars("words")
|
|
860
|
+
* split("joe has a hat", " ", words)
|
|
861
|
+
*/
|
|
862
|
+
WOQL.split = function (inputVarName, separator, resultVarName) {
|
|
863
|
+
return new WOQLQuery().split(inputVarName, separator, resultVarName);
|
|
864
|
+
};
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Matches if List includes Element
|
|
868
|
+
* @param {string|object|Var} element - Either a variable, IRI or any simple datatype
|
|
869
|
+
* @param {string|array|Var} list - List ([string, literal] or string*) Either a variable
|
|
870
|
+
* representing a list or a list of variables or literals
|
|
871
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the List inclusion pattern matching expression
|
|
872
|
+
* @example
|
|
873
|
+
* let [name] = vars("name")
|
|
874
|
+
* member(name, ["john", "joe", "frank"])
|
|
875
|
+
*/
|
|
876
|
+
WOQL.member = function (element, list) {
|
|
877
|
+
return new WOQLQuery().member(element, list);
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
/**
|
|
881
|
+
*
|
|
882
|
+
* takes a variable number of string arguments and concatenates them into a single string
|
|
883
|
+
* @param {array|string|Var} varList - a variable representing a list or a list of variables or
|
|
884
|
+
* strings - variables can be embedded in the string if they do not contain spaces
|
|
885
|
+
* @param {string|Var} resultVarName - A variable or string containing the output string
|
|
886
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Concatenation pattern matching expression
|
|
887
|
+
* @example
|
|
888
|
+
* let [first_name, last_name, full_name] = vars("first_name", "last_name", "full_name")
|
|
889
|
+
* concat([first_name, " ", last_name], full_name)
|
|
890
|
+
*/
|
|
891
|
+
WOQL.concat = function (varList, resultVarName) {
|
|
892
|
+
return new WOQLQuery().concat(varList, resultVarName);
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
*
|
|
897
|
+
* Joins a list variable together (Input) into a string variable (Output) by glueing the strings
|
|
898
|
+
* together with Glue
|
|
899
|
+
* @param {string|array|Var} varList - a variable representing a list or a list of strings
|
|
900
|
+
* and / or variables
|
|
901
|
+
* @param {string|Var} glue - A variable (v:glue) or (glue) string representing the characters
|
|
902
|
+
* to put in between the joined strings in input
|
|
903
|
+
* @param {string|Var} resultVarName - A variable or string containing the output string
|
|
904
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Join pattern matching expression
|
|
905
|
+
* @example
|
|
906
|
+
* let [sentence] = vars("sentence")
|
|
907
|
+
* join(["joe", "has", "a", "hat", " ", sentence)
|
|
908
|
+
*/
|
|
909
|
+
WOQL.join = function (varList, glue, resultVarName) {
|
|
910
|
+
return new WOQLQuery().join(varList, glue, resultVarName);
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* computes the sum of the List of values passed. In contrast to other arithmetic functions,
|
|
915
|
+
* sum self-evaluates - it does not have to be passed to evaluate()
|
|
916
|
+
* @param {WOQLQuery} subquery - a subquery or ([string or numeric]) - a list variable, or a
|
|
917
|
+
* list of variables or numeric literals
|
|
918
|
+
* @param {string|Var} total - the variable name with the sum result of the values in List
|
|
919
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the Sum expression
|
|
920
|
+
* @example
|
|
921
|
+
* let [total] = vars("total")
|
|
922
|
+
* sum([2, 3, 4, 5], total)
|
|
923
|
+
*/
|
|
924
|
+
WOQL.sum = function (subquery, total) {
|
|
925
|
+
return new WOQLQuery().sum(subquery, total);
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Extracts a contiguous subsequence from a list, following JavaScript's slice() semantics
|
|
930
|
+
* @param {string|array|Var} inputList - Either a variable representing a list or a list of
|
|
931
|
+
* variables or literals
|
|
932
|
+
* @param {string|Var} resultVarName - A variable in which the sliced list is stored
|
|
933
|
+
* @param {number|string|Var} start - The start index (0-based, supports negative indices)
|
|
934
|
+
* @param {number|string|Var} [end] - The end index (exclusive, optional - defaults to list length)
|
|
935
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Slice pattern matching expression
|
|
936
|
+
* @example
|
|
937
|
+
* let [result] = vars("result")
|
|
938
|
+
* slice(["a", "b", "c", "d"], result, 1, 3) // result = ["b", "c"]
|
|
939
|
+
* slice(["a", "b", "c", "d"], result, -2) // result = ["c", "d"]
|
|
940
|
+
*/
|
|
941
|
+
WOQL.slice = function (inputList, resultVarName, start, end) {
|
|
942
|
+
return new WOQLQuery().slice(inputList, resultVarName, start, end);
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
*
|
|
947
|
+
* Specifies an offset position in the results to start listing results from
|
|
948
|
+
* @param {number|string|Var} start - A variable that refers to an interger or an integer literal
|
|
949
|
+
* @param {WOQLQuery} [subquery] - WOQL Query object, you can pass a subquery as an argument
|
|
950
|
+
* or a chained query
|
|
951
|
+
* @returns {WOQLQuery} A WOQLQuery whose results will be returned starting from
|
|
952
|
+
* the specified offset
|
|
953
|
+
* @example
|
|
954
|
+
* let [a, b, c] = vars("a", "b", "c")
|
|
955
|
+
* start(100).triple(a, b, c)
|
|
956
|
+
*/
|
|
957
|
+
WOQL.start = function (start, subquery) {
|
|
958
|
+
return new WOQLQuery().start(start, subquery);
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
*
|
|
963
|
+
* Specifies a maximum number of results that will be returned from the subquery
|
|
964
|
+
* @param {number|string} limit - A variable that refers to an non-negative integer or a
|
|
965
|
+
* non-negative integer
|
|
966
|
+
* @param {WOQLQuery} [subquery] - A subquery whose results will be limited
|
|
967
|
+
* @returns {WOQLQuery} A WOQLQuery whose results will be returned starting from
|
|
968
|
+
* the specified offset
|
|
969
|
+
* @example
|
|
970
|
+
* let [a, b, c] = vars("a", "b", "c")
|
|
971
|
+
* limit(100).triple(a, b, c)
|
|
972
|
+
* //subquery is an argument or a chained query
|
|
973
|
+
* limit(100,triple(a, b, c))
|
|
974
|
+
*/
|
|
975
|
+
WOQL.limit = function (limit, subquery) {
|
|
976
|
+
return new WOQLQuery().limit(limit, subquery);
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
/**
|
|
980
|
+
*
|
|
981
|
+
* Matches the regular expression defined in Patern against the Test string, to produce
|
|
982
|
+
* the matched patterns in Matches
|
|
983
|
+
* @param {string} pattern - string or variable using normal PCRE regular expression syntax with
|
|
984
|
+
* the exception that special characters have to be escaped twice (to enable transport in JSONLD)
|
|
985
|
+
* @param {string|Var} inputVarName - string or variable containing the string to be tested for
|
|
986
|
+
* patterns with the regex
|
|
987
|
+
* @param {string|array|object|Var} resultVarList - variable representing the list of matches
|
|
988
|
+
* or a list of strings or variables
|
|
989
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Regular Expression pattern
|
|
990
|
+
* matching expression
|
|
991
|
+
* @example
|
|
992
|
+
* let [All, Sub] = vars("All", "Sub")
|
|
993
|
+
* WOQL.re("h(.).*", "hello", [All, Sub])
|
|
994
|
+
* //e contains 'e', llo contains 'llo'
|
|
995
|
+
* //p is a regex pattern (.*) using normal regular expression syntax, the only unusual
|
|
996
|
+
* thing is that special characters have to be escaped twice, s is the string to be matched
|
|
997
|
+
* and m is a list of matches:
|
|
998
|
+
*/
|
|
999
|
+
WOQL.re = function (pattern, inputVarName, resultVarList) {
|
|
1000
|
+
return new WOQLQuery().re(pattern, inputVarName, resultVarList);
|
|
1001
|
+
};
|
|
1002
|
+
WOQL.regexp = function (pattern, inputVarName, resultVarList) {
|
|
1003
|
+
return new WOQLQuery().re(pattern, inputVarName, resultVarList);
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
/**
|
|
1007
|
+
*
|
|
1008
|
+
* Calculates the length of the list in va and stores it in vb
|
|
1009
|
+
* @param {string|array} inputVarList - Either a variable representing a list or a list of
|
|
1010
|
+
* variables or literals
|
|
1011
|
+
* @param {string|Var} resultVarName - A variable in which the length of the list is stored or
|
|
1012
|
+
* the length of the list as a non-negative integer
|
|
1013
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the Length pattern matching expression
|
|
1014
|
+
* @example
|
|
1015
|
+
* let [count] = vars("count")
|
|
1016
|
+
* length(["john", "joe", "frank"], count)
|
|
1017
|
+
*/
|
|
1018
|
+
WOQL.length = function (inputVarList, resultVarName) {
|
|
1019
|
+
return new WOQLQuery().length(inputVarList, resultVarName);
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
*
|
|
1024
|
+
* Logical negation of the contained subquery - if the subquery matches, the query
|
|
1025
|
+
* will fail to match
|
|
1026
|
+
* @param {string | WOQLQuery} [subquery] - A subquery which will be negated
|
|
1027
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the negated sub Query
|
|
1028
|
+
* @example
|
|
1029
|
+
* let [subject, label] = vars("subject", "label")
|
|
1030
|
+
* not().triple(subject, 'label', label)
|
|
1031
|
+
*/
|
|
1032
|
+
WOQL.not = function (subquery) {
|
|
1033
|
+
return new WOQLQuery().not(subquery);
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* Results in one solution of the subqueries
|
|
1038
|
+
* @param {string| WOQLQuery } [subquery] - WOQL Query objects
|
|
1039
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the once sub Query
|
|
1040
|
+
*/
|
|
1041
|
+
WOQL.once = function (subquery) {
|
|
1042
|
+
return new WOQLQuery().once(subquery);
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Runs the query without backtracking on side-effects
|
|
1047
|
+
* @param {string| WOQLQuery } [subquery] - WOQL Query objects
|
|
1048
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the immediately sub Query
|
|
1049
|
+
*/
|
|
1050
|
+
WOQL.immediately = function (subquery) {
|
|
1051
|
+
return new WOQLQuery().immediately(subquery);
|
|
1052
|
+
};
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Creates a count of the results of the query
|
|
1056
|
+
* @param {string|number|Var} countVarName - variable or integer count
|
|
1057
|
+
* @param {WOQLQuery} [subquery]
|
|
1058
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the count sub Query
|
|
1059
|
+
* @example
|
|
1060
|
+
* let [count, Person] = vars("count", "Person")
|
|
1061
|
+
* WOQL.count(count).triple(Person, "rdf:type", "@schema:Person")
|
|
1062
|
+
*/
|
|
1063
|
+
WOQL.count = function (countVarName, subquery) {
|
|
1064
|
+
return new WOQLQuery().count(countVarName, subquery);
|
|
1065
|
+
};
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
*
|
|
1069
|
+
* Casts the value of Input to a new value of type Type and stores the result in CastVar
|
|
1070
|
+
* @param {string|number|object|Var} varName - Either a single variable or a
|
|
1071
|
+
* literal of any basic type
|
|
1072
|
+
* @param {string|Var} varType - Either a variable or a basic datatype (xsd / xdd)
|
|
1073
|
+
* @param {string|Var} resultVarName - save the return variable
|
|
1074
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the casting expression
|
|
1075
|
+
* @example
|
|
1076
|
+
* let [time] = vars("time")
|
|
1077
|
+
* cast("22/3/98", "xsd:dateTime", time)
|
|
1078
|
+
*/
|
|
1079
|
+
WOQL.typecast = function (varName, varType, resultVarName) {
|
|
1080
|
+
return new WOQLQuery().typecast(varName, varType, resultVarName);
|
|
1081
|
+
};
|
|
1082
|
+
WOQL.cast = function (varName, varType, resultVarName) {
|
|
1083
|
+
return new WOQLQuery().typecast(varName, varType, resultVarName);
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Orders the results of the contained subquery by a precedence list of variables
|
|
1088
|
+
* @param {...string|...Var|...array} varNames - A sequence of variables,
|
|
1089
|
+
* by which to order the results,
|
|
1090
|
+
* each optionally followed by either “asc” or “desc” to represent order as a list, by default
|
|
1091
|
+
* it will sort the variable in ascending order
|
|
1092
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the ordering expression
|
|
1093
|
+
* @example
|
|
1094
|
+
* let [A, B, C] = vars("A", "B", "C")
|
|
1095
|
+
* WOQL.order_by(A, [B, "asc"], [C, "desc"]).triple(A, B, C);
|
|
1096
|
+
*/
|
|
1097
|
+
WOQL.order_by = function (...varNames) {
|
|
1098
|
+
return new WOQLQuery().order_by(...varNames);
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
*
|
|
1103
|
+
* Groups the results of the contained subquery on the basis of identical values for Groupvars,
|
|
1104
|
+
* extracts the patterns defined in PatternVars and stores the results in GroupedVar.
|
|
1105
|
+
* See also {@link /docs/group-query-results/ How to Group Results in WOQL}
|
|
1106
|
+
* @param {array|string|Var} varList - Either a single variable or an array of variables
|
|
1107
|
+
* @param {array|string|Var} patternVars - Either a single variable or an array of variables
|
|
1108
|
+
* @param {string|Var} resultVarName - output variable name
|
|
1109
|
+
* @param {WOQLQuery} [subquery] - The query whose results will be grouped
|
|
1110
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the grouping expression
|
|
1111
|
+
* @example
|
|
1112
|
+
* //subquery is an argument or a chained query
|
|
1113
|
+
* let [age, last_name, first_name, age_group, person] = vars("age", "last name", "first name",
|
|
1114
|
+
* "age group", "person")
|
|
1115
|
+
* group_by(age, [last_name, first_name], age_group)
|
|
1116
|
+
* .triple(person, "first_name", first_name)
|
|
1117
|
+
* .triple(person, "last_name", last_name)
|
|
1118
|
+
* .triple(person, "age", age)
|
|
1119
|
+
* OR extract a simple list of last_name in age_group that can be
|
|
1120
|
+
* used for example with member()
|
|
1121
|
+
* group_by([], last_name, age_group)
|
|
1122
|
+
* .triple(person, "first_name", first_name)
|
|
1123
|
+
*/
|
|
1124
|
+
WOQL.group_by = function (varList, patternVars, resultVarName, subquery) {
|
|
1125
|
+
return new WOQLQuery().group_by(varList, patternVars, resultVarName, subquery);
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
*
|
|
1130
|
+
* A function that always matches, always returns true
|
|
1131
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the true value that will match any pattern
|
|
1132
|
+
* @example
|
|
1133
|
+
* when(true()).triple("a", "b", "c")
|
|
1134
|
+
*/
|
|
1135
|
+
WOQL.true = function () {
|
|
1136
|
+
return new WOQLQuery().true();
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
/**
|
|
1140
|
+
*
|
|
1141
|
+
* Performs a path regular expression match on the graph
|
|
1142
|
+
* @param {string|Var} subject - An IRI or variable that refers to an IRI representing the subject,
|
|
1143
|
+
* i.e. the starting point of the path
|
|
1144
|
+
* @param {string} pattern -(string) - A path regular expression describing a pattern through
|
|
1145
|
+
* multiple edges of the graph (see: https://terminusdb.com/docs/path-query-reference-guide)
|
|
1146
|
+
* @param {string|Var} object - An IRI or variable that refers to an IRI representing the object,
|
|
1147
|
+
* i.e. ending point of the path
|
|
1148
|
+
* @param {string|Var} [resultVarName] - A variable in which the actual paths
|
|
1149
|
+
* traversed will be stored
|
|
1150
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the path regular expression matching expression
|
|
1151
|
+
* @example
|
|
1152
|
+
* let [person, grand_uncle, lineage] = vars("person", "grand uncle", "lineage")
|
|
1153
|
+
* path(person, "((father|mother) {2,2}), brother)", grand_uncle, lineage)
|
|
1154
|
+
*/
|
|
1155
|
+
WOQL.path = function (subject, pattern, object, resultVarName) {
|
|
1156
|
+
return new WOQLQuery().path(subject, pattern, object, resultVarName);
|
|
1157
|
+
};
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
*
|
|
1161
|
+
* Calculates the size in bytes of the contents of the resource identified in ResourceID
|
|
1162
|
+
* @param {string|Var} resourceId - A valid resource identifier string (can refer to any graph /
|
|
1163
|
+
* branch / commit / db)
|
|
1164
|
+
* @param {string|Var} resultVarName - The variable name
|
|
1165
|
+
* @example
|
|
1166
|
+
* let [varSize] = vars("varSize")
|
|
1167
|
+
* size("admin/minecraft/local/branch/main/instance/main", varSize)
|
|
1168
|
+
* //returns the number of bytes in the main instance graph on the main branch
|
|
1169
|
+
*/
|
|
1170
|
+
WOQL.size = function (resourceId, resultVarName) {
|
|
1171
|
+
return new WOQLQuery().size(resourceId, resultVarName);
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
/**
|
|
1175
|
+
*
|
|
1176
|
+
* Calculates the number of triples of the contents of the resource identified in ResourceID
|
|
1177
|
+
* @param {string|Var} resourceId - A valid resource identifier string (can refer to any graph /
|
|
1178
|
+
* branch / commit / db)
|
|
1179
|
+
* @param {string|number|Var} tripleCount - An integer literal with the size in bytes or a
|
|
1180
|
+
* variable containing that integer
|
|
1181
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the size expression
|
|
1182
|
+
* @example
|
|
1183
|
+
* let [count] = vars("count")
|
|
1184
|
+
* triple_count("admin/minecraft/local/_commits", count)
|
|
1185
|
+
* //returns the number of bytes in the local commit graph
|
|
1186
|
+
*/
|
|
1187
|
+
WOQL.triple_count = function (resourceId, tripleCount) {
|
|
1188
|
+
return new WOQLQuery().triple_count(resourceId, tripleCount);
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
*
|
|
1193
|
+
* Returns true if 'elementId' is of type 'elementType', according to the current DB schema
|
|
1194
|
+
* @param {string|Var} elementId - the id of a schema graph element
|
|
1195
|
+
* @param {string|Var} elementType - the element type
|
|
1196
|
+
* @returns {WOQLQuery} A WOQLQuery object containing the type_of pattern matching rule
|
|
1197
|
+
*
|
|
1198
|
+
*/
|
|
1199
|
+
WOQL.type_of = function (elementId, elementType) {
|
|
1200
|
+
return new WOQLQuery().type_of(elementId, elementType);
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
*
|
|
1205
|
+
* Generates a query that by default matches all triples in a graph identified by "graph"
|
|
1206
|
+
* or in all the current terminusDB's graph
|
|
1207
|
+
* @param {string | boolean} [graph] - false or the resource identifier of a graph possible
|
|
1208
|
+
* value are schema/{main - myschema - *} | instance/{main - myschema - *} |
|
|
1209
|
+
* inference/{main - myschema - *}
|
|
1210
|
+
* @param {string|Var} [subject] - The IRI of a triple’s subject or a variable,
|
|
1211
|
+
* default value "v:Subject"
|
|
1212
|
+
* @param {string|Var} [predicate] - The IRI of a property or a variable,
|
|
1213
|
+
* default value "v:Predicate"
|
|
1214
|
+
* @param {string|Var} [object] - The IRI of a node or a variable, or a literal,
|
|
1215
|
+
* default value "v:Object"
|
|
1216
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the pattern matching expression
|
|
1217
|
+
* @example
|
|
1218
|
+
* star("schema/main")
|
|
1219
|
+
* //will return every triple in schema/main graph
|
|
1220
|
+
*/
|
|
1221
|
+
WOQL.star = function (graph, subject, predicate, object) {
|
|
1222
|
+
return new WOQLQuery().star(graph, subject, predicate, object);
|
|
1223
|
+
};
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
*
|
|
1227
|
+
* Generates a query that by default matches all triples in a graph - identical to
|
|
1228
|
+
* star() except for order of arguments
|
|
1229
|
+
* @param {string|Var} [subject] - The IRI of a triple’s subject or a variable
|
|
1230
|
+
* @param {string|Var} [predicate] - The IRI of a property or a variable
|
|
1231
|
+
* @param {string|Var} [object] - The IRI of a node or a variable, or a literal
|
|
1232
|
+
* @param {typedef.GraphRef} [graphRef] - the resource identifier of a graph possible
|
|
1233
|
+
* value are schema/{main - myschema - *} | instance/{main - myschema - *} |
|
|
1234
|
+
* inference/{main - myschema - *}
|
|
1235
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the pattern matching expression
|
|
1236
|
+
* all("mydoc")
|
|
1237
|
+
* //will return every triple in the instance/main graph that has "doc:mydoc" as its subject
|
|
1238
|
+
*/
|
|
1239
|
+
WOQL.all = function (subject, predicate, object, graphRef) {
|
|
1240
|
+
return new WOQLQuery().all(subject, predicate, object, graphRef);
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
*
|
|
1245
|
+
* Specifies the identity of a node that can then be used in subsequent builder functions.
|
|
1246
|
+
* Note that node() requires subsequent chained functions to complete the triples / quads
|
|
1247
|
+
* that it produces - by itself it only generates the subject.
|
|
1248
|
+
* @param {string|Var} nodeid - The IRI of a node or a variable containing an IRI which will
|
|
1249
|
+
* be the subject of the builder functions
|
|
1250
|
+
* @param {typedef.FuntionType} [chainType] - Optional type of builder function to build
|
|
1251
|
+
* (default is triple)
|
|
1252
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the partial Node pattern matching expression
|
|
1253
|
+
* @example
|
|
1254
|
+
* node("mydoc").label("my label")
|
|
1255
|
+
* //equivalent to triple("mydoc", "label", "my label")
|
|
1256
|
+
*/
|
|
1257
|
+
WOQL.node = function (nodeid, chainType) {
|
|
1258
|
+
return new WOQLQuery().node(nodeid, chainType);
|
|
1259
|
+
};
|
|
1260
|
+
// These ones are special ones for dealing with the schema only...
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Inserts a single triple into the database declaring the Node to have type Type,
|
|
1264
|
+
* optionally into the specified graph
|
|
1265
|
+
* @param {string|Var} classId - IRI string or variable containing
|
|
1266
|
+
* the IRI of the node to be inserted
|
|
1267
|
+
* @param {string|Var} classType - IRI string or variable containing the IRI of the
|
|
1268
|
+
* type of the node (class/document name)
|
|
1269
|
+
* @param {typedef.GraphRef} [graphRef] - Optional Graph resource identifier
|
|
1270
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the insert expression
|
|
1271
|
+
* @example
|
|
1272
|
+
* insert("mydoc", "MyType")
|
|
1273
|
+
* //equivalent to add_triple("mydoc", "rdf:type", "@schema:MyType")
|
|
1274
|
+
*/
|
|
1275
|
+
WOQL.insert = function (classId, classType, graphRef) {
|
|
1276
|
+
return new WOQLQuery().insert(classId, classType, graphRef);
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* Sets the graph resource ID that will be used for subsequent chained function calls
|
|
1281
|
+
* @param {typedef.GraphRef} [graphRef] Resource String identifying the graph which will
|
|
1282
|
+
* be used for subsequent chained schema calls
|
|
1283
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the partial Graph pattern matching expression
|
|
1284
|
+
* @example
|
|
1285
|
+
* WOQL.graph("schema")
|
|
1286
|
+
* //equivalent to add_quad("MyClass", "label", "My Class Label", "schema/main")
|
|
1287
|
+
*/
|
|
1288
|
+
|
|
1289
|
+
WOQL.graph = function (graphRef) {
|
|
1290
|
+
return new WOQLQuery().graph(graphRef);
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
// to be review
|
|
1294
|
+
/**
|
|
1295
|
+
* Deletes all triples in the passed graph (defaults to instance/main)
|
|
1296
|
+
* @param {typedef.GraphRef} [graphRef] - Resource String identifying the graph from
|
|
1297
|
+
* which all triples will be removed
|
|
1298
|
+
* @returns {WOQLQuery} - A WOQLQuery which contains the deletion expression
|
|
1299
|
+
* @example
|
|
1300
|
+
* nuke("schema/main")
|
|
1301
|
+
* //will delete everything from the schema/main graph
|
|
1302
|
+
*/
|
|
1303
|
+
WOQL.nuke = function (graphRef) {
|
|
1304
|
+
return new WOQLQuery().nuke(graphRef);
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* Generates an empty WOQLQuery object
|
|
1309
|
+
* @returns {WOQLQuery}
|
|
1310
|
+
* @example
|
|
1311
|
+
* let q = query()
|
|
1312
|
+
* //then q.triple(1, 1) ...
|
|
1313
|
+
*/
|
|
1314
|
+
WOQL.query = function () {
|
|
1315
|
+
return new WOQLQuery();
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1318
|
+
/**
|
|
1319
|
+
* Generates a WOQLQuery object from the passed WOQL JSON - if an argument is passed,
|
|
1320
|
+
* the query object is created from it, if none is passed, the current state is
|
|
1321
|
+
* returned as a JSON-LD
|
|
1322
|
+
* @param {object} [JSON_LD] - JSON-LD woql document encoding a query
|
|
1323
|
+
* @returns {WOQLQuery | object} either a JSON-LD or a WOQLQuery object
|
|
1324
|
+
*
|
|
1325
|
+
* json version of query for passing to api
|
|
1326
|
+
*/
|
|
1327
|
+
WOQL.json = function (JSON_LD) {
|
|
1328
|
+
return new WOQLQuery().json(JSON_LD);
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* get the predefined library query [WOQLLibrary](/api/woqlLibrary.js?id=WOQLLibrary)
|
|
1333
|
+
* @returns {WOQLLibrary} WOQLLibrary object
|
|
1334
|
+
* @example
|
|
1335
|
+
* //get commits older than the specified commit id
|
|
1336
|
+
* const query = WOQL.lib().previousCommits('m8vpxewh2aovfauebfkbzwmj4qwr5lb')
|
|
1337
|
+
*
|
|
1338
|
+
* //return the commits of a specific branch starting from the head
|
|
1339
|
+
* //you can add the limit (how many results to return.) and the start point
|
|
1340
|
+
* //if a timestamp is given, gets the commits before the specified timestamp
|
|
1341
|
+
* //WOQL.lib().commits(branch='main',limit=0,start=0,timestamp=0)
|
|
1342
|
+
*
|
|
1343
|
+
* const query = WOQL.lib().commits('main',10,2,1630683082.9278786)
|
|
1344
|
+
*
|
|
1345
|
+
* //return the branches list with the timestamp and commits id
|
|
1346
|
+
* const query = WOQL.lib().branches()
|
|
1347
|
+
*/
|
|
1348
|
+
WOQL.lib = function () {
|
|
1349
|
+
return new WOQLLibrary();
|
|
1350
|
+
};
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Generates explicitly a JSON-LD string literal from the input
|
|
1354
|
+
* @param {string | boolean | number} val - any primitive literal type
|
|
1355
|
+
* @returns {string|Var} - A JSON-LD string literal
|
|
1356
|
+
* @example
|
|
1357
|
+
* string(1)
|
|
1358
|
+
* //returns { "@type": "xsd:string", "@value": "1" }
|
|
1359
|
+
*/
|
|
1360
|
+
WOQL.string = function (val) {
|
|
1361
|
+
return new WOQLQuery().string(val);
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* Generates explicitly a JSON-LD string literal from the input
|
|
1366
|
+
* @param {string} val - any literal type
|
|
1367
|
+
* @param {string} type - an xsd or xdd type
|
|
1368
|
+
* @returns {Var} - A JSON-LD literal
|
|
1369
|
+
* @example
|
|
1370
|
+
* literal(1, "nonNegativeInteger")
|
|
1371
|
+
* //returns { "@type": "xsd:nonNegativeInteger", "@value": 1 }
|
|
1372
|
+
*/
|
|
1373
|
+
WOQL.literal = function (val, type) {
|
|
1374
|
+
return new WOQLQuery().literal(val, type);
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Generates explicitly a JSON-LD literal date from the imput
|
|
1379
|
+
* @param {string} date - any date format string (YYYY-MM-DD)
|
|
1380
|
+
* @returns {Var} - A JSON-LD literal date
|
|
1381
|
+
* @example
|
|
1382
|
+
* date("2022-10-02")
|
|
1383
|
+
* //returns { "@type": "xsd:date", "@value": "2022-10-02" }
|
|
1384
|
+
*/
|
|
1385
|
+
WOQL.date = function (date) {
|
|
1386
|
+
return new WOQLQuery().literal(date, 'xsd:date');
|
|
1387
|
+
};
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Generates explicitly a JSON-LD literal datetime from the imput
|
|
1391
|
+
* @param {string} datetime - any datetime format string (YYYY-MM-DDThh-mm-ssZ)
|
|
1392
|
+
* @returns {Var} - A JSON-LD literal datetime
|
|
1393
|
+
* @example
|
|
1394
|
+
* datetime("2022-10-19T14:17:12Z")
|
|
1395
|
+
* //returns { "@type": "xsd:dateTime", "@value": "2022-10-19T14:17:12Z" }
|
|
1396
|
+
*/
|
|
1397
|
+
WOQL.datetime = function (datetime) {
|
|
1398
|
+
return new WOQLQuery().literal(datetime, 'xsd:dateTime');
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Generates explicitly a JSON-LD literal boolean from the input
|
|
1403
|
+
* @param {boolean} bool - true | false
|
|
1404
|
+
* @returns {Var} - A JSON-LD literal boolean
|
|
1405
|
+
* @example
|
|
1406
|
+
* boolean(true)
|
|
1407
|
+
* //returns { "@type": "xsd:boolean", "@value": true }
|
|
1408
|
+
*/
|
|
1409
|
+
WOQL.boolean = function (bool) {
|
|
1410
|
+
return new WOQLQuery().boolean(bool);
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* Explicitly sets a value to be an IRI - avoiding automatic type marshalling
|
|
1415
|
+
* @param {string} val string which will be treated as an IRI
|
|
1416
|
+
* @returns {Var} - A JSON-LD IRI value
|
|
1417
|
+
*/
|
|
1418
|
+
WOQL.iri = function (val) {
|
|
1419
|
+
return new WOQLQuery().iri(val);
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Generates javascript variables for use as WOQL variables within a query
|
|
1424
|
+
* @param {...string} varNames
|
|
1425
|
+
* @returns {Array<Var>} an array of javascript variables which can be dereferenced using the
|
|
1426
|
+
* array destructuring operation
|
|
1427
|
+
* @example
|
|
1428
|
+
* const [a, b, c] = WOQL.vars("a", "b", "c")
|
|
1429
|
+
* //a, b, c are javascript variables which can be used as WOQL variables in subsequent queries
|
|
1430
|
+
*/
|
|
1431
|
+
|
|
1432
|
+
WOQL.vars = function (...varNames) {
|
|
1433
|
+
return varNames.map((item) => new Var(item));
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Generates unique javascript variables for use as WOQL variables within a query
|
|
1438
|
+
* @param {...string} varNames
|
|
1439
|
+
* @returns {Array<Var>} an array of javascript variables which can be dereferenced using the
|
|
1440
|
+
* array destructuring operation
|
|
1441
|
+
* @example
|
|
1442
|
+
* const [a, b, c] = WOQL.vars("a", "b", "c")
|
|
1443
|
+
* //a, b, c are javascript variables that are unique WOQL variables
|
|
1444
|
+
*/
|
|
1445
|
+
|
|
1446
|
+
WOQL.vars_unique = function (...varNames) {
|
|
1447
|
+
return varNames.map((item) => new VarUnique(item));
|
|
1448
|
+
};
|
|
1449
|
+
|
|
1450
|
+
/**
|
|
1451
|
+
* Sets the unique variable counter to a specific value
|
|
1452
|
+
* This is particularly useful together with select() for locally scoped variables
|
|
1453
|
+
* @param {number} start - starting value
|
|
1454
|
+
*/
|
|
1455
|
+
|
|
1456
|
+
WOQL.vars_unique_reset_start = function (start) {
|
|
1457
|
+
SetVarsUniqueCounter(start ?? 0);
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
/**
|
|
1461
|
+
* Produces an encoded form of a document that can be used by a WOQL operation
|
|
1462
|
+
* such as `WOQL.insert_document` or with `WOQL.dot` operators
|
|
1463
|
+
* @param {object} object - Document to encode
|
|
1464
|
+
* @returns {Var} The encoded document
|
|
1465
|
+
* @example
|
|
1466
|
+
* WOQL.insert_document(WOQL.doc({ "@type": "Person", name: "Newperson" }), "v:docId")
|
|
1467
|
+
*/
|
|
1468
|
+
|
|
1469
|
+
WOQL.doc = function (object) {
|
|
1470
|
+
return new Doc(object);
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
/**
|
|
1474
|
+
* Use instead to run your query woqlclient.query('myWOQLQuery')
|
|
1475
|
+
* @deprecated
|
|
1476
|
+
* Gets/Sets woqlClient
|
|
1477
|
+
* @param {WOQLClient}
|
|
1478
|
+
* @returns {WOQLClient}
|
|
1479
|
+
*/
|
|
1480
|
+
WOQL.client = function (client) {
|
|
1481
|
+
if (client) this._client = client;
|
|
1482
|
+
return this._client;
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
*
|
|
1487
|
+
* @param {...string} varNames
|
|
1488
|
+
* @returns {Record<string, Var>}
|
|
1489
|
+
* @example
|
|
1490
|
+
* const v = WOQL.Vars('var01', 'var02', 'var03');
|
|
1491
|
+
* triple(v.var01, v.var02, v.var03)
|
|
1492
|
+
*/
|
|
1493
|
+
WOQL.Vars = function (...varNames) {
|
|
1494
|
+
return new Vars(...varNames);
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
/**
|
|
1498
|
+
*
|
|
1499
|
+
* Produces variables with unique names by appending an incrementing counter to each variable name.
|
|
1500
|
+
* This is particularly useful together with select() for locally scoped variables
|
|
1501
|
+
*
|
|
1502
|
+
* @param {...string} varNames
|
|
1503
|
+
* @returns {Record<string, Var>}
|
|
1504
|
+
* @example
|
|
1505
|
+
* // Creates variables like "a_4", "b_5" - unique even with same input names
|
|
1506
|
+
* const v = WOQL.VarsUnique('var01', 'var02', 'var03');
|
|
1507
|
+
* triple(v.var01, v.var02, v.var03) // locally scoped
|
|
1508
|
+
*/
|
|
1509
|
+
WOQL.VarsUnique = function (...varNames) {
|
|
1510
|
+
return new VarsUnique(...varNames);
|
|
1511
|
+
};
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
*
|
|
1515
|
+
* query module
|
|
1516
|
+
* allow you to use WOQL words as top level functions
|
|
1517
|
+
* @param {*} auto_eval
|
|
1518
|
+
* @returns {WOQLQuery} WOQLQuery
|
|
1519
|
+
*/
|
|
1520
|
+
WOQL.emerge = function (auto_eval) {
|
|
1521
|
+
const unemerged = ['emerge', 'true', 'eval'];
|
|
1522
|
+
function _emerge_str(k) {
|
|
1523
|
+
const str = `function ${k}(...args){
|
|
1524
|
+
return WOQL.${k}(...args)
|
|
1525
|
+
}`;
|
|
1526
|
+
return str;
|
|
1527
|
+
}
|
|
1528
|
+
const funcs = [_emerge_str('Vars')];
|
|
1529
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
1530
|
+
for (const k in this) {
|
|
1531
|
+
if (typeof this[k] === 'function') {
|
|
1532
|
+
if (unemerged.indexOf(k) === -1) {
|
|
1533
|
+
funcs.push(_emerge_str(k));
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
const str = funcs.join(';\n');
|
|
1538
|
+
// eslint-disable-next-line no-eval
|
|
1539
|
+
if (auto_eval) eval(str);
|
|
1540
|
+
return str;
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Update a pattern matching rule for the triple (Subject, Predicate, oldObjValue) with the
|
|
1545
|
+
* new one (Subject, Predicate, newObjValue). Replaces old triple with new triple
|
|
1546
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
1547
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
1548
|
+
* @param {string|Var} newObjValue - The value to update or a literal
|
|
1549
|
+
* @param {string|Var} oldObjValue - The old value of the object
|
|
1550
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the a Update Triple Statement
|
|
1551
|
+
* @example
|
|
1552
|
+
* let [newValue, oldValue] = WOQL.vars("newValue", "oldValue")
|
|
1553
|
+
* WOQL.update_triple("Project/1", "name", newValue, oldValue)
|
|
1554
|
+
*/
|
|
1555
|
+
|
|
1556
|
+
WOQL.update_triple = function (subject, predicate, newObjValue, oldObjValue) {
|
|
1557
|
+
return new WOQLQuery().update_triple(subject, predicate, newObjValue, oldObjValue);
|
|
1558
|
+
};
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Update a pattern matching rule for the quad [S, P, O, G] (Subject, Predicate, Object, Graph)
|
|
1562
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
1563
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
1564
|
+
* @param {string|Var} newObject - The value to update or a literal
|
|
1565
|
+
* @param {typedef.GraphRef} graphRef - A valid graph resource identifier string
|
|
1566
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the a Update Quad Statement
|
|
1567
|
+
* @example
|
|
1568
|
+
* let [newObj, oldObj] = WOQL.vars("newObj", "oldObj")
|
|
1569
|
+
* WOQL.update_quad("Project/1", "name", newObj, oldObj, "schema/main")
|
|
1570
|
+
*/
|
|
1571
|
+
|
|
1572
|
+
WOQL.update_quad = function (subject, predicate, newObject, graphRef) {
|
|
1573
|
+
return new WOQLQuery().update_quad(subject, predicate, newObject, graphRef);
|
|
1574
|
+
};
|
|
1575
|
+
|
|
1576
|
+
/**
|
|
1577
|
+
* Creates a pattern matching rule for a triple [Subject, Predicate, Object]
|
|
1578
|
+
* add extra information about the type of the value object
|
|
1579
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
1580
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
1581
|
+
* @param {string | number | boolean | Var} objValue - an specific value
|
|
1582
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the a quad or a triple Statement
|
|
1583
|
+
*/
|
|
1584
|
+
WOQL.value = function (subject, predicate, objValue) {
|
|
1585
|
+
return new WOQLQuery().value(subject, predicate, objValue);
|
|
1586
|
+
};
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Creates a pattern matching rule for a triple [Subject, Predicate, Object]
|
|
1590
|
+
* @param {string|Var} subject - The IRI of a triple’s subject or a variable
|
|
1591
|
+
* @param {string|Var} predicate - The IRI of a property or a variable
|
|
1592
|
+
* @param {string|Var} object - The IRI of a node or a variable, or a literal
|
|
1593
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the a quad or a triple Statement
|
|
1594
|
+
*/
|
|
1595
|
+
WOQL.link = function (subject, predicate, object) {
|
|
1596
|
+
return new WOQLQuery().link(subject, predicate, object);
|
|
1597
|
+
};
|
|
1598
|
+
|
|
1599
|
+
/**
|
|
1600
|
+
* Extract the value of a key in a bound document.
|
|
1601
|
+
* @param {string|Var} document - Document which is being accessed.
|
|
1602
|
+
* @param {string|Var} field - The field from which the document which is being accessed.
|
|
1603
|
+
* @param {string|Var} value - The value for the document and field.
|
|
1604
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the a dot Statement
|
|
1605
|
+
* @example
|
|
1606
|
+
* // Use either "v:personName" and "v:doc", OR `personName` and `doc` with variables:
|
|
1607
|
+
* // `let [personName, doc] = WOQL.vars("personName", "doc")`
|
|
1608
|
+
* and(
|
|
1609
|
+
* WOQL.eq("v:doc", WOQL.doc({ "@type": "Person", name: "Alice" })),
|
|
1610
|
+
* WOQL.dot("v:doc", "name", "v:personName")
|
|
1611
|
+
* )
|
|
1612
|
+
* // extracts the "name" field value from the document into personName variable
|
|
1613
|
+
*/
|
|
1614
|
+
WOQL.dot = function (document, field, value) {
|
|
1615
|
+
return new WOQLQuery().dot(document, field, value);
|
|
1616
|
+
};
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Computes the set difference between two lists (elements in listA but not in listB)
|
|
1620
|
+
* @param {string|Var|array} listA - First list or variable
|
|
1621
|
+
* @param {string|Var|array} listB - Second list or variable
|
|
1622
|
+
* @param {string|Var} result - Variable to store the result
|
|
1623
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the SetDifference expression
|
|
1624
|
+
* @example
|
|
1625
|
+
* let [result] = vars("result")
|
|
1626
|
+
* set_difference(["a", "b", "c"], ["b", "d"], result) // result = ["a", "c"]
|
|
1627
|
+
*/
|
|
1628
|
+
WOQL.set_difference = function (listA, listB, result) {
|
|
1629
|
+
return new WOQLQuery().set_difference(listA, listB, result);
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Computes the set intersection between two lists (elements common to both)
|
|
1634
|
+
* @param {string|Var|array} listA - First list or variable
|
|
1635
|
+
* @param {string|Var|array} listB - Second list or variable
|
|
1636
|
+
* @param {string|Var} result - Variable to store the result
|
|
1637
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the SetIntersection expression
|
|
1638
|
+
* @example
|
|
1639
|
+
* let [result] = vars("result")
|
|
1640
|
+
* set_intersection(["a", "b", "c"], ["b", "c", "d"], result) // result = ["b", "c"]
|
|
1641
|
+
*/
|
|
1642
|
+
WOQL.set_intersection = function (listA, listB, result) {
|
|
1643
|
+
return new WOQLQuery().set_intersection(listA, listB, result);
|
|
1644
|
+
};
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Computes the set union of two lists (all unique elements from both lists)
|
|
1648
|
+
* @param {string|Var|array} listA - First list or variable
|
|
1649
|
+
* @param {string|Var|array} listB - Second list or variable
|
|
1650
|
+
* @param {string|Var} result - Variable to store the result
|
|
1651
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the SetUnion expression
|
|
1652
|
+
* @example
|
|
1653
|
+
* let [result] = vars("result")
|
|
1654
|
+
* set_union(["a", "b"], ["b", "c"], result) // result = ["a", "b", "c"]
|
|
1655
|
+
*/
|
|
1656
|
+
WOQL.set_union = function (listA, listB, result) {
|
|
1657
|
+
return new WOQLQuery().set_union(listA, listB, result);
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
/**
|
|
1661
|
+
* Checks if an element is a member of a set
|
|
1662
|
+
* @param {string|number|Var} element - Element to check for membership
|
|
1663
|
+
* @param {string|Var|array} set - Set (list) to check membership in
|
|
1664
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the SetMember expression
|
|
1665
|
+
* @example
|
|
1666
|
+
* let [result] = vars("result")
|
|
1667
|
+
* set_member("b", ["a", "b", "c"], result) // true if "b" is in the set
|
|
1668
|
+
*/
|
|
1669
|
+
WOQL.set_member = function (element, set) {
|
|
1670
|
+
return new WOQLQuery().set_member(element, set);
|
|
1671
|
+
};
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* Converts a list to a set by removing duplicates and sorting
|
|
1675
|
+
* @param {string|Var|array} list - List or variable containing a list
|
|
1676
|
+
* @param {string|Var} set - Variable to store the resulting set
|
|
1677
|
+
* @returns {WOQLQuery} A WOQLQuery which contains the ListToSet expression
|
|
1678
|
+
* @example
|
|
1679
|
+
* let [result] = vars("result")
|
|
1680
|
+
* list_to_set(["a", "b", "a", "c", "b"], result) // result = ["a", "b", "c"]
|
|
1681
|
+
* @example
|
|
1682
|
+
* let [mySet, isMember] = vars("mySet", "isMember")
|
|
1683
|
+
* and(
|
|
1684
|
+
* list_to_set(["a", "b", "a", "c"], mySet),
|
|
1685
|
+
* set_member("b", mySet),
|
|
1686
|
+
* opt().eq(is_member, "b-is-member")
|
|
1687
|
+
* ) // mySet = ["a", "b", "c"], "b" is a member, and is_member is set to "b-is-member"
|
|
1688
|
+
*/
|
|
1689
|
+
WOQL.list_to_set = function (list, set) {
|
|
1690
|
+
return new WOQLQuery().list_to_set(list, set);
|
|
1691
|
+
};
|
|
1692
|
+
|
|
1693
|
+
module.exports = WOQL;
|