Skip to content

Commit ed996cc

Browse files
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents 8afc691 + 57cf45e commit ed996cc

File tree

2 files changed

+742
-61
lines changed

2 files changed

+742
-61
lines changed

test/woql.spec.js

Lines changed: 113 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,21 @@ describe('woql queries', function () {
8080
const Update=WOQL.addClass("id");
8181
const Condition=WOQL.or(WOQL.triple("a", "b", "c"),WOQL.triple("1", "2", "3"));
8282

83-
const woqlObject=WOQL.when(Condition, Update);
83+
const woqlObject=WOQL.when(true, WOQL.addClass("id"));
84+
85+
const woqlObjectChain=WOQL.when(true).addClass("id")
8486

85-
const woqlObjectChain=WOQL.when(Condition).addClass("id")
86-
//console.log(woqlObject.json()['when'][0][]);
87-
console.log(woqlObjectChain.json());
88-
/*
8987
const jsonObj={
9088
when: [
91-
WOQLQuery {
92-
query: [Object],
93-
cursor: [Object],
94-
chain_ended: false,
95-
contains_update: false,
96-
paging_transitive_properties: [Array],
97-
vocab: [Object]
89+
{
90+
"true":[]
9891
},
99-
{}
92+
{ add_quad: [ 'scm:id', 'rdf:type', 'owl:Class', 'db:schema' ] }
10093
]
10194
};
102-
*/
95+
10396
//expect(woqlObject.json()).to.eql(jsonObj);
104-
//expect(woqlObjectChain.json()).to.eql(jsonObj);
97+
expect(woqlObjectChain.json()).to.eql(jsonObj);
10598

10699
})
107100

@@ -231,9 +224,9 @@ describe('woql queries', function () {
231224

232225
it('check the get method',function(){
233226

234-
const woqlObject=WOQL.as("Map", "Target");
227+
const woqlObject=WOQL.get("Map", "Target");
235228

236-
const jsonObj={ as: [ { '@value': 'Map' }, 'v:Target' ] };
229+
const jsonObj={ get: [[], {}] };
237230

238231
expect(woqlObject.json()).to.eql(jsonObj);
239232

@@ -242,28 +235,32 @@ describe('woql queries', function () {
242235
it('check the as method',function(){
243236

244237
const woqlObject=WOQL.as("Source", "Target");
238+
const woqlObject2=WOQL.as("Source", "Target").as("Source2", "Target2");
245239

246-
const jsonObj={ as: [ { '@value': 'Source' }, 'v:Target' ] };
240+
const jsonObj=[{ as: [ { '@value': 'Source' }, 'v:Target' ] }];
241+
const jsonObj2 =[{ as: [ { '@value': 'Source' }, 'v:Target' ] },
242+
{ as: [ { '@value': 'Source2' }, 'v:Target2' ] }]
247243

248244
expect(woqlObject.json()).to.eql(jsonObj);
245+
expect(woqlObject2.json()).to.eql(jsonObj2);
249246

250247
})
251248

252249
it('check the remote method',function(){
253250

254251
const woqlObject=WOQL.remote({url: "http://url"});
255-
console.log(woqlObject.json());
256-
//const jsonObj={ as: [ { '@value': 'Prefix' }, 'v:V1,V2' ] };
257252

258-
//expect(woqlObject.json()).to.eql(jsonObj);
253+
const jsonObj={ remote: [ { url: 'http://url' } ] };
254+
255+
expect(woqlObject.json()).to.eql(jsonObj);
259256

260257
})
261258

262259
it('check the unique method',function(){
263260

264-
const woqlObject=WOQL.as("Prefix", ["V1","V2"]);
261+
const woqlObject=WOQL.unique("doc:Station_",["v:Start_ID"],"v:Start_IRI");
265262

266-
const jsonObj={ as: [ { '@value': 'Prefix' }, 'v:V1,V2' ] };
263+
const jsonObj={ unique: [ 'doc:Station_', { list: ["v:Start_ID"] }, 'v:Start_IRI' ] }
267264

268265
expect(woqlObject.json()).to.eql(jsonObj);
269266

@@ -272,10 +269,10 @@ describe('woql queries', function () {
272269
it('check the list method',function(){
273270

274271
const woqlObject=WOQL.list(["V1","V2"]);
275-
console.log(woqlObject.json());
276-
//const jsonObj={ as: [ { '@value': 'Prefix' }, 'v:V1,V2' ] };
277272

278-
//expect(woqlObject.json()).to.eql(jsonObj);
273+
const jsonObj={ list: [ [ 'V1', 'V2' ] ] };
274+
275+
expect(woqlObject.json()).to.eql(jsonObj);
279276

280277
})
281278

@@ -317,7 +314,10 @@ describe('triple builder', function () {
317314

318315
const woqlObject=WOQL.deleteClass("id");
319316

320-
const jsonObj= { and: [ { delete_quad: [ 'scm:id', 'v:All', 'v:Al2', 'db:schema' ] }, { opt: [{delete_quad: [ 'v:Al3', 'v:Al4', 'scm:id', 'db:schema' ] }]} ] };
317+
const jsonObj= { and: [
318+
{ delete_quad: [ 'scm:id', 'v:All', 'v:Al2', 'db:schema' ] },
319+
{ "opt": [ { delete_quad: [ 'v:Al3', 'v:Al4', 'scm:id', 'db:schema' ] } ] }
320+
] };
321321

322322
expect(woqlObject.json()).to.eql(jsonObj);
323323

@@ -446,17 +446,33 @@ describe('triple builder chanier', function () {
446446

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

449-
const jsonObj={ add_quad: ["doc:x", 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:schema'] };
449+
const jsonObj={ add_quad: ['doc:x', 'rdfs:label', { '@value': 'my label', '@language': 'en' }, 'db:schema'] };
450+
451+
expect(woqlObject.json()).to.eql(jsonObj);
452+
453+
})
454+
455+
it('check the description method',function(){
456+
457+
const woqlObject=WOQL.addClass("New class").description("A new class object.").entity();
458+
459+
const jsonObj={ "add_quad": ['doc:x', 'rdfs:comment', { '@value': 'my comment', '@language': 'en' }, 'db:schema'] };
450460

451461
expect(woqlObject.json()).to.eql(jsonObj);
452462

453463
})
454464

455465
it('check the comment method',function(){
456466

457-
const woqlObject=WOQL.comment("Comments Out the Following").add_triple("doc:x", "type", "scm:Yoke");
467+
const woqlObject=WOQL.node("doc:x", "add_quad").comment("my comment");
458468

459-
const jsonObj={ comment: [{ "@value": 'Comments Out the Following', "@language": 'en' }, {"add_triple": ["doc:x", "rdf:type", "scm:Yoke"]}] };
469+
const jsonObj={ "comment": [
470+
{
471+
"@language": "en",
472+
"@value": "my comment"
473+
},
474+
{}
475+
] };
460476

461477
expect(woqlObject.json()).to.eql(jsonObj);
462478

@@ -476,23 +492,19 @@ describe('triple builder chanier', function () {
476492

477493
const woqlObject=WOQL.node("doc:x", "add_quad").entity();
478494

479-
console.log(woqlObject.json());
480-
481-
//const jsonObj={ add_quad: ['doc:x', 'rdfs:myprop', { '@value': 'my value', '@language': 'en' }, 'db:schema'] }
495+
const jsonObj={ add_quad: [ 'doc:x', 'rdfs:subClassOf', 'tcs:Entity', 'db:schema' ] };
482496

483-
//expect(woqlObject.json()).to.eql(jsonObj);
497+
expect(woqlObject.json()).to.eql(jsonObj);
484498

485499
})
486500

487501
it('check the parent method',function(){
488502

489503
const woqlObject=WOQL.node("doc:x", "add_quad").parent("Z");
490504

491-
console.log(woqlObject.json());
492-
493-
//const jsonObj={ add_quad: ['doc:x', 'rdfs:myprop', { '@value': 'my value', '@language': 'en' }, 'db:schema'] }
505+
const jsonObj={ add_quad: [ 'doc:x', 'rdfs:subClassOf', 'scm:Z', 'db:schema' ] };
494506

495-
//expect(woqlObject.json()).to.eql(jsonObj);
507+
expect(woqlObject.json()).to.eql(jsonObj);
496508

497509
})
498510

@@ -510,8 +522,6 @@ describe('triple builder chanier', function () {
510522

511523
const woqlObject=WOQL.node("doc:x", "add_quad").relationship();
512524

513-
console.log(woqlObject.json());
514-
515525
const jsonObj={ add_quad: [ 'doc:x', 'rdfs:subClassOf', 'tcs:Entity', 'db:schema' ] };
516526

517527
expect(woqlObject.json()).to.eql(jsonObj);
@@ -522,35 +532,86 @@ describe('triple builder chanier', function () {
522532

523533
const woqlObject=WOQL.addProperty("P", "string").max(4);
524534

525-
console.log(woqlObject.json());
526-
527-
//const jsonObj={ add_quad: [ 'doc:x', 'tcs:tag', 'tcs:relationship', 'db:schema' ] };
535+
const jsonObj={ "and": [ { "add_quad": ["scm:P",
536+
"rdf:type",
537+
"owl:DatatypeProperty",
538+
"db:schema"] },
539+
{ "add_quad": ["scm:P",
540+
"rdfs:range",
541+
"xsd:string",
542+
"db:schema"] },
543+
{ "add_quad": ["scm:P_max",
544+
"rdf:type",
545+
"owl:Restriction",
546+
"db:schema"] },
547+
{ "add_quad": [ "scm:P_max",
548+
"owl:onProperty",
549+
"scm:P",
550+
"db:schema"] },
551+
{ "add_quad": [ "scm:P_max",
552+
"owl:maxCardinality",
553+
{ "@value": "4", "@type": "xsd:nonNegativeInteger" },
554+
"db:schema"] } ] };
528555

529-
//expect(woqlObject.json()).to.eql(jsonObj);
556+
expect(woqlObject.json()).to.eql(jsonObj);
530557

531558
})
532559

533560
it('check the min method',function(){
534561

535562
const woqlObject=WOQL.addProperty("P", "string").min(2);
536563

537-
console.log(woqlObject.json());
564+
const jsonObj={ "and": [ { "add_quad": ["scm:P",
565+
"rdf:type",
566+
"owl:DatatypeProperty",
567+
"db:schema"] },
568+
{ "add_quad": ["scm:P",
569+
"rdfs:range",
570+
"xsd:string",
571+
"db:schema"] },
572+
{ "add_quad": ["scm:P_min",
573+
"rdf:type",
574+
"owl:Restriction",
575+
"db:schema"] },
576+
{ "add_quad": [ "scm:P_min",
577+
"owl:onProperty",
578+
"scm:P",
579+
"db:schema"] },
580+
{ "add_quad": [ "scm:P_min",
581+
"owl:minCardinality",
582+
{ "@value": "2", "@type": "xsd:nonNegativeInteger" },
583+
"db:schema"] } ] };
538584

539-
//const jsonObj={ add_quad: [ 'doc:x', 'tcs:tag', 'tcs:relationship', 'db:schema' ] };
540-
541-
//expect(woqlObject.json()).to.eql(jsonObj);
585+
expect(woqlObject.json()).to.eql(jsonObj);
542586

543587
})
544588

545589
it('check the cardinality method',function(){
546590

547591
const woqlObject=WOQL.addProperty("P", "string").cardinality(3);
548592

549-
console.log(woqlObject.json());
550-
551-
//const jsonObj={ add_quad: [ 'doc:x', 'tcs:tag', 'tcs:relationship', 'db:schema' ] };
593+
const jsonObj={ "and": [ { "add_quad": ["scm:P",
594+
"rdf:type",
595+
"owl:DatatypeProperty",
596+
"db:schema"] },
597+
{ "add_quad": ["scm:P",
598+
"rdfs:range",
599+
"xsd:string",
600+
"db:schema"] },
601+
{ "add_quad": ["scm:P_cardinality",
602+
"rdf:type",
603+
"owl:Restriction",
604+
"db:schema"] },
605+
{ "add_quad": [ "scm:P_cardinality",
606+
"owl:onProperty",
607+
"scm:P",
608+
"db:schema"] },
609+
{ "add_quad": [ "scm:P_cardinality",
610+
"owl:cardinality",
611+
{ "@value": "3", "@type": "xsd:nonNegativeInteger" },
612+
"db:schema"] } ] };
552613

553-
//expect(woqlObject.json()).to.eql(jsonObj);
614+
expect(woqlObject.json()).to.eql(jsonObj);
554615

555616
})
556617

0 commit comments

Comments
 (0)