Skip to content

Commit 9fb7e95

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 20c284b + c1ca0e4 commit 9fb7e95

File tree

1 file changed

+83
-10
lines changed

1 file changed

+83
-10
lines changed

lib/woql.js

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,19 @@ WOQL.lower = function(u, l){ return new WOQLQuery().lower(u, l); }
4848
WOQL.pad = function(input, pad, len, output){ return new WOQLQuery().pad(input, pad, len, output); }
4949
WOQL.join = function(...list){ return new WOQLQuery().join(...list); }
5050
WOQL.unique = function(prefix, vari, type){ return new WOQLQuery().unique(prefix, vari, type); }
51+
WOQL.idgen = function(prefix, vari, type, output){ return new WOQLQuery().idgen(prefix, vari, type, output); }
52+
WOQL.typecast = function(vara, type, varb){ return new WOQLQuery().typecast(vara, type, varb); }
53+
5154

5255
/* Mathematical Processing */
53-
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
56+
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
5457
WOQL.plus = function(...args){ return new WOQLQuery().plus(...args);}
5558
WOQL.minus = function(...args){ return new WOQLQuery().minus(...args); }
5659
WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
5760
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
5861
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
62+
WOQL.div = function(...args){ return new WOQLQuery().div(...args); }
63+
WOQL.comment = function(arg){ return new WOQLQuery().comment(arg); }
5964

6065

6166
//language extensions that can be chained after 'grounded' stuff (clauses with a specific subject) sub, isa, delete_triple, add_triple, delete_quad, add_quad, node
@@ -147,6 +152,10 @@ WOQLQuery.prototype.buildAsClauses = function(vars, cols){
147152
return clauses;
148153
}
149154

155+
WOQLQuery.prototype.typecast = function(va, type, vb){
156+
this.cursor['typecast'] = [va, type, vb];
157+
return this;
158+
}
150159

151160

152161
WOQLQuery.prototype.remote = function(json){
@@ -189,6 +198,24 @@ WOQLQuery.prototype.group_by = function(gvarlist, groupedvar, groupquery, output
189198
return this;
190199
}
191200

201+
WOQLQuery.prototype.idgen = function(prefix, vari, type, mode){
202+
this.cursor['idgen'] = [prefix];
203+
if(vari.json){
204+
this.cursor['idgen'].push(vari.json());
205+
}
206+
else if(vari.list){
207+
this.cursor['idgen'].push(vari);
208+
}
209+
else {
210+
this.cursor['idgen'].push({"list": vari})
211+
}
212+
if(mode){
213+
this.cursor['idgen'].push(mode);
214+
}
215+
this.cursor['idgen'].push(type);
216+
return this;
217+
}
218+
192219

193220
WOQLQuery.prototype.unique = function(prefix, vari, type){
194221
this.cursor['unique'] = [prefix];
@@ -209,6 +236,13 @@ WOQLQuery.prototype.unique = function(prefix, vari, type){
209236
WOQLQuery.prototype.concat = function(list, v){
210237
if(typeof list == "string"){
211238
var nlist = list.split(/(v:[\w_]+)\b/);
239+
var nxlist = [];
240+
for(var i = 1; i<nlist.length; i++){
241+
if(nlist[i-1].substring(nlist[i-1].length-1) == "v" && nlist[i].substring(0, 1) == ":"){
242+
nlist[i-1] = nlist[i-1].substring(0, nlist[i-1].length-1);
243+
nlist[i] = nlist[i].substring(1);
244+
}
245+
}
212246
}
213247
else if(list.list){
214248
var nlist = list.list;
@@ -405,6 +439,19 @@ WOQLQuery.prototype.sub = function(a, b){
405439
return this.last("sub", a);
406440
}
407441

442+
WOQLQuery.prototype.comment = function(val){
443+
if(val){
444+
val = (val.json ? val.json() : val)
445+
this.cursor['comment'] = val;
446+
}
447+
else {
448+
this.cursor['comment'] = null;
449+
this.cursor = this.cursor['comment'];
450+
}
451+
return this;
452+
}
453+
454+
408455
WOQLQuery.prototype.abstract = function(varname){
409456
if(varname){
410457
return this.quad(varname, "tcs:tag", "tcs:abstract", "db:schema");
@@ -432,31 +479,54 @@ WOQLQuery.prototype.trim = function(a, b){
432479
}
433480

434481
WOQLQuery.prototype.eval = function(arith, v){
482+
arith = arith.json ? arith.json() : arith;
435483
this.cursor['eval'] = [arith, v];
436484
return this.last('eval', v);
437485
}
438486

439487
WOQLQuery.prototype.plus = function (...args) {
440-
this.cursor.plus = args;
488+
this.cursor.plus = [];
489+
for(var i = 0; i < args.length; i++){
490+
this.cursor.plus.push(args[i].json ? args[i].json() : args[i]);
491+
}
441492
return this.last();
442493
};
443494

444495
WOQLQuery.prototype.minus = function (...args) {
445-
this.cursor.minus = args;
496+
this.cursor.minus = [];
497+
for(var i = 0; i < args.length; i++){
498+
this.cursor.minus.push(args[i].json ? args[i].json() : args[i]);
499+
}
446500
return this.last();
447501
};
448502

449503
WOQLQuery.prototype.times = function (...args) {
450-
this.cursor.times = args;
504+
this.cursor.times = [];
505+
for(var i = 0; i < args.length; i++){
506+
this.cursor.times.push(args[i].json ? args[i].json() : args[i]);
507+
}
451508
return this.last();
452509
};
453510

454511
WOQLQuery.prototype.divide = function (...args) {
455-
this.cursor.divide = args;
512+
this.cursor.divide = [];
513+
for(var i = 0; i < args.length; i++){
514+
this.cursor.divide.push(args[i].json ? args[i].json() : args[i]);
515+
}
516+
return this.last();
517+
};
518+
519+
WOQLQuery.prototype.div = function (...args) {
520+
this.cursor.div = [];
521+
for(var i = 0; i < args.length; i++){
522+
this.cursor.div.push(args[i].json ? args[i].json() : args[i]);
523+
}
456524
return this.last();
457525
};
458526

459527
WOQLQuery.prototype.exp = function (a, b) {
528+
a = (a.json ? a.json() : a);
529+
b = (b.json ? b.json() : b);
460530
this.cursor.exp = [a, b];
461531
return this.last();
462532
};
@@ -613,7 +683,7 @@ WOQLQuery.prototype.label = function(l, lang){
613683
return this;
614684
}
615685

616-
WOQLQuery.prototype.comment = function(c, lang){
686+
WOQLQuery.prototype.description = function(c, lang){
617687
if(this.tripleBuilder) this.tripleBuilder.comment(c, lang);
618688
return this;
619689
}
@@ -1211,7 +1281,7 @@ WOQLQuery.prototype.uncleanArguments = function(operator, args, indent, show_con
12111281
*/
12121282
WOQLQuery.prototype.uncleanArgument = function(operator, val, index, allArgs){
12131283
//numeric values go out untouched...
1214-
const numeric_operators = ["limit", "start", "eval", "plus", "minus", "times", "divide", "exp"];
1284+
const numeric_operators = ["limit", "start", "eval", "plus", "minus", "times", "divide", "exp", "div"];
12151285
if(operator == "isa"){
12161286
val = (index == 0 ? this.unclean(val, 'subject') : this.unclean(val, 'class'));
12171287
}
@@ -1245,10 +1315,13 @@ WOQLQuery.prototype.uncleanArgument = function(operator, val, index, allArgs){
12451315
}
12461316
return oval;
12471317
}
1248-
else if(numeric_operators.indexOf(operator) !== -1){
1249-
return val;
1318+
//else if(numeric_operators.indexOf(operator) !== -1){
1319+
// return val;
1320+
//}
1321+
if(typeof val == "string"){
1322+
return '"' + val + '"';
12501323
}
1251-
return '"' + val + '"';
1324+
return val;
12521325
}
12531326

12541327

0 commit comments

Comments
 (0)