Skip to content

Commit 4526068

Browse files
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 5dcfb80 + 12d548c commit 4526068

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

lib/woql.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ WOQL.greater = function(v1, v2){ return new WOQLQuery().greater(v1, v2); }
5757

5858

5959
/* Mathematical Processing */
60-
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
60+
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
6161
WOQL.plus = function(...args){ return new WOQLQuery().plus(...args);}
6262
WOQL.minus = function(...args){ return new WOQLQuery().minus(...args); }
6363
WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
6464
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
6565
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
6666
WOQL.div = function(...args){ return new WOQLQuery().div(...args); }
6767
WOQL.comment = function(arg){ return new WOQLQuery().comment(arg); }
68-
WOQL.length = function(var1, res){ return new WOQLQuery().length(var1, res);}
68+
WOQL.length = function(var1, res){ return new WOQLQuery().length(var1, res);}
6969

7070

7171
//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
@@ -124,7 +124,7 @@ WOQLQuery.prototype.get = function(arr1, arr2, target){
124124
target = arr2;
125125
}
126126
else {
127-
var map = this.buildAsClauses(arr1, arr2);
127+
var map = this.buildAsClauses(arr1, arr2);
128128
}
129129
if(target){
130130
if(target.json) target = target.json();
@@ -199,7 +199,7 @@ WOQLQuery.prototype.group_by = function(gvarlist, groupedvar, groupquery, output
199199
if(typeof groupedvar == "object" && Array.isArray(groupedvar)){
200200
ng = [];
201201
for(var i = 0; i<groupedvar.length; i++){
202-
ng.push(groupedvar[i].substring(0, 2) != "v:" ? "v:" + groupedvar[i] : groupedvar[i]);
202+
ng.push(groupedvar[i].substring(0, 2) != "v:" ? "v:" + groupedvar[i] : groupedvar[i]);
203203
}
204204
groupedvar = {"list": ng};
205205
}
@@ -208,7 +208,7 @@ WOQLQuery.prototype.group_by = function(gvarlist, groupedvar, groupquery, output
208208
}
209209
args.push(groupedvar);
210210
if(output){
211-
groupquery = groupquery.json ? groupquery.json() : groupquery;
211+
groupquery = groupquery.json ? groupquery.json() : groupquery;
212212
args.push(groupquery);
213213
}
214214
else {
@@ -527,7 +527,7 @@ WOQLQuery.prototype.eval = function(arith, v){
527527
}
528528

529529
WOQLQuery.prototype.plus = function (...args) {
530-
this.cursor.plus = [];
530+
this.cursor.plus = [];
531531
for(var i = 0; i < args.length; i++){
532532
this.cursor.plus.push(args[i].json ? args[i].json() : args[i]);
533533
}
@@ -674,7 +674,7 @@ WOQLQuery.prototype.as = function(a, b){
674674
b = (b.indexOf(":") == -1 ? "v:" + b : b);
675675
var val = (typeof a == "object" ? a : { "@value" : a});
676676
this.query.push({as: [val, b]});
677-
return this;
677+
return this;
678678
}
679679

680680
/**
@@ -1222,7 +1222,7 @@ WOQLQuery.prototype.prettyPrint = function(indent, show_context, q, fluent){
12221222
str += this.getWOQLPrelude(operator, fluent, indent - this.indent);
12231223
var val = q[operator];
12241224
if(this.chainable(operator, val[val.length-1])){
1225-
//all arguments up until the last are regular function arguments
1225+
//all arguments up until the last are regular function arguments
12261226
str += this.uncleanArguments(operator, val.slice(0, val.length-1), indent, show_context);
12271227
if(newlining_operators.indexOf(operator) !== -1){
12281228
//some fluent function calls demand a linebreak..
@@ -1253,7 +1253,7 @@ WOQLQuery.prototype.getWOQLPrelude = function(operator, fluent, inline){
12531253
if(fluent){
12541254
return "." + operator;
12551255
}
1256-
return (inline ? "\n" + nspaces(inline) : "") + "WOQL." + operator;
1256+
return (inline ? "\n" + nspaces(inline) : "") + "WOQL." + operator;
12571257
}
12581258

12591259
/**
@@ -1301,7 +1301,7 @@ WOQLQuery.prototype.uncleanArguments = function(operator, args, indent, show_con
13011301
str += ")";
13021302
str += "\n" + nspaces(indent);
13031303
}
1304-
}
1304+
}
13051305
else {
13061306
str += this.uncleanArgument(operator, args[i], i, args);
13071307
}
@@ -1319,10 +1319,10 @@ WOQLQuery.prototype.uncleanArguments = function(operator, args, indent, show_con
13191319
/**
13201320
* Passed as arguments: 1) the operator (and, triple, not, opt, etc)
13211321
* 2) the value of the argument
1322-
* 3) the index (position) of the argument.
1322+
* 3) the index (position) of the argument.
13231323
*/
13241324
WOQLQuery.prototype.uncleanArgument = function(operator, val, index, allArgs){
1325-
//numeric values go out untouched...
1325+
//numeric values go out untouched...
13261326
const numeric_operators = ["limit", "start", "eval", "plus", "minus", "times", "divide", "exp", "div"];
13271327
if(operator == "isa"){
13281328
val = (index == 0 ? this.unclean(val, 'subject') : this.unclean(val, 'class'));
@@ -1521,18 +1521,17 @@ TripleBuilder.prototype.addPO = function(p, o, g){
15211521
else var ttype = "triple";
15221522
var evstr = ttype + '("' + this.subject + '", "' + p + '", ';
15231523
if(typeof o == "string"){
1524-
evstr += "'" + o + "'";
1525-
}
1524+
evstr += "'" + o + "'";
1525+
}
15261526
else if(typeof o == "object"){
1527-
console.log(JSON.stringify(o));
15281527
evstr += JSON.stringify(o);
15291528
}
15301529
else {
15311530
evstr += o;
15321531
}
15331532
if(ttype.substring(ttype.length-4) == "quad" || this.g){
15341533
var g = (g ? g : (this.g ? this.g : "db:schema"));
1535-
evstr += ', "' + g + '"';
1534+
evstr += ', "' + g + '"';
15361535
}
15371536
evstr += ")";
15381537
try {

test/woql.spec.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ describe('woql queries', function () {
113113

114114
it('check the from method',function(){
115115

116-
const Query=WOQL.limit(10);
117-
//const woqlObject=WOQL.from("http://dburl", Query);
116+
const WOQLQuery=WOQL.limit(10);
117+
//const woqlObject=WOQL.from("http://dburl", WOQLQuery);
118118

119119
const woqlObjectChain=WOQL.from("http://dburl").limit(10);
120120

@@ -125,6 +125,20 @@ describe('woql queries', function () {
125125

126126
})
127127

128+
it('check the star method',function(){
129+
130+
const woqlObject=WOQL.limit(10).star();
131+
132+
const jsonObj={ limit: [ 10, { "triple": [
133+
"v:Subject",
134+
"v:Predicate",
135+
"v:Object"
136+
] } ] };
137+
138+
expect(woqlObject.json()).to.eql(jsonObj);
139+
140+
})
141+
128142
it('check the select method',function(){
129143

130144
const woqlObject=WOQL.select("V1", WOQL.triple("a", "b", "c"));
@@ -256,11 +270,21 @@ describe('woql queries', function () {
256270

257271
})
258272

259-
it('check the unique method',function(){
273+
it('check the idgen method',function(){
274+
275+
const woqlObject=WOQL.idgen("doc:Station",["v:Start_ID"],"v:Start_Station_URL");
276+
277+
const jsonObj={ "idgen": [ 'doc:Station', { "list": ["v:Start_ID"] }, 'v:Start_Station_URL' ] }
278+
279+
expect(woqlObject.json()).to.eql(jsonObj);
280+
281+
})
282+
283+
it('check the typecast method',function(){
260284

261-
const woqlObject=WOQL.unique("doc:Station_",["v:Start_ID"],"v:Start_IRI");
285+
const woqlObject=WOQL.typecast("v:Duration", "xsd:integer", "v:Duration_Cast");
262286

263-
const jsonObj={ unique: [ 'doc:Station_', { list: ["v:Start_ID"] }, 'v:Start_IRI' ] }
287+
const jsonObj={ "typecast": [ "v:Duration", "xsd:integer", "v:Duration_Cast" ] }
264288

265289
expect(woqlObject.json()).to.eql(jsonObj);
266290

@@ -435,7 +459,7 @@ describe('triple builder chanier', function () {
435459
const woqlObject2=WOQL.node("doc:x", "add_quad").graph("db:mySchema").label("my label", "en");
436460

437461
const jsonObj={};
438-
const jsonObj2={ add_quad: ['doc:x', 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:mySchema'] };
462+
const jsonObj2={ 'add_quad': ['doc:x', 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:mySchema'] };
439463

440464
expect(woqlObject.json()).to.eql(jsonObj);
441465
expect(woqlObject2.json()).to.eql(jsonObj2);
@@ -446,7 +470,7 @@ describe('triple builder chanier', function () {
446470

447471
const woqlObject=WOQL.node("doc:x", "add_quad").label("my label", "en");
448472

449-
const jsonObj={ add_quad: ['doc:x', 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:schema'] };
473+
const jsonObj={ 'add_quad': ['doc:x', 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:schema'] };
450474

451475
expect(woqlObject.json()).to.eql(jsonObj);
452476

@@ -485,7 +509,7 @@ describe('triple builder chanier', function () {
485509

486510
const woqlObject=WOQL.node("doc:x", "add_quad").property("myprop", "value");
487511

488-
const jsonObj={ add_quad: ['doc:x', 'scm:myprop', { '@value': 'value', '@language': 'en' }, 'db:schema'] };
512+
const jsonObj={ 'add_quad': ['doc:x', 'scm:myprop', { '@value': 'value', '@language': 'en' }, 'db:schema'] };
489513

490514
expect(woqlObject.json()).to.eql(jsonObj);
491515

0 commit comments

Comments
 (0)