Skip to content

Commit 5ec95b7

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents d45fdfc + 4d8bef6 commit 5ec95b7

File tree

5 files changed

+156
-64
lines changed

5 files changed

+156
-64
lines changed

dist/terminus-client.min.js

Lines changed: 4 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ module.exports = {
77
ErrorMessage:require('./lib/errorMessage'),
88
FrameHelper:require('./lib/frameHelper'),
99
ObjectFrame:require('./lib/objectFrame'),
10+
WOQLResult:require('./lib/woqlResult'),
1011
WOQL:require('./lib/woql')};

lib/woql.js

Lines changed: 148 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const FramePattern = require('./framePattern');
77
const FrameHelper = require('./frameHelper');
88

99
const WOQL = {};
10+
1011
WOQL.when = function(Query, Update){ return new WOQLQuery().when(Query, Update);}
1112
WOQL.opt = function(query){ return new WOQLQuery().opt(query); }
1213
WOQL.from = function(dburl, query){ return new WOQLQuery().from(dburl, query); }
@@ -22,19 +23,40 @@ WOQL.sub = function(a, b){ return new WOQLQuery().sub(a, b); }
2223
WOQL.isa = function(a, b){ return new WOQLQuery().isa(a, b); }
2324
WOQL.trim = function(a, b){ return new WOQLQuery().trim(a, b); }
2425
WOQL.delete = function(JSON_or_IRI){ return new WOQLQuery().delete(JSON_or_IRI); }
25-
WOQL.minus_triple = function( S, P, O ){ return new WOQLQuery().minus_triple (S, P, O); }
26-
WOQL.plus_triple = function( S, P, O ){ return new WOQLQuery().plus_triple (S, P, O); }
27-
WOQL.minus_quad = function( S, P, O, G ){ return new WOQLQuery().minus_triple (S, P, O, G); }
28-
WOQL.plus_quad = function( S, P, O, G ){ return new WOQLQuery().plus_triple (S, P, O, G);}
26+
WOQL.delete_triple = function( S, P, O ){ return new WOQLQuery().delete_triple (S, P, O); }
27+
WOQL.add_triple = function( S, P, O ){ return new WOQLQuery().add_triple (S, P, O); }
28+
WOQL.delete_quad = function( S, P, O, G ){ return new WOQLQuery().delete_triple (S, P, O, G); }
29+
WOQL.add_quad = function( S, P, O, G ){ return new WOQLQuery().add_triple (S, P, O, G);}
2930
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
3031
WOQL.plus = function(...args){ return new WOQLQuery().plus(...args);}
3132
WOQL.minus = function(...args){ return new WOQLQuery().minus(...args); }
3233
WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
3334
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
3435
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
36+
37+
WOQL.schema = function(){ return new WOQLSchema(); }
38+
39+
WOQL.query = function(){ return new WOQLQuery(); }
40+
41+
WOQL.get = function(map, target){ return new WOQLQuery().get(map, target); }
42+
WOQL.as = function(map, vari){ return new WOQLQuery().as(map, vari); }
43+
WOQL.remote = function(url){ return new WOQLQuery().remote(url); }
44+
WOQL.unique = function(prefix, vari){ return new WOQLQuery().unique(prefix, vari); }
45+
WOQL.list = function(vars){ return new WOQLQuery().list(vars); }
46+
//WOQL.value = function(vars){ return new WOQLQuery().list(vars); }
47+
48+
3549
WOQL.json = function(json){ return new WOQLQuery().json(json); }
3650
WOQL.rule = function(){ return new FramePattern.FrameRule() }
37-
WOQL.getAllDocuments= function(){return new WOQLQuery().getAllDocuments()}
51+
52+
WOQL.isLiteralType = function(t){
53+
if(t){
54+
var pref = t.split(":");
55+
if(pref[0] == "xdd" || pref[0] == "xsd") return true;
56+
}
57+
return false;
58+
}
59+
3860

3961
function WOQLQuery(query, results){
4062
this.query = (query ? query : {});
@@ -405,7 +427,7 @@ WOQLQuery.prototype.and = function(...queries){
405427
return this;
406428
}
407429

408-
WOQLQuery.prototype.or = function(queries){
430+
WOQLQuery.prototype.or = function(...queries){
409431
this.cursor["or"] = [];
410432
for(var i = 0; i<queries.length; i++){
411433
if(queries[i].contains_update) this.contains_update = true;
@@ -491,23 +513,23 @@ WOQLQuery.prototype.delete = function(JSON_or_IRI){
491513
return this.lastUpdate();
492514
}
493515

494-
WOQLQuery.prototype.minus_triple = function( Subject, Predicate, Object_or_Literal ){
495-
this.cursor['minus_triple'] = [ Subject, Predicate, Object_or_Literal ];
516+
WOQLQuery.prototype.delete_triple = function( Subject, Predicate, Object_or_Literal ){
517+
this.cursor['delete_triple'] = [ Subject, Predicate, Object_or_Literal ];
496518
return this.lastUpdate();
497519
}
498520

499-
WOQLQuery.prototype.plus_triple = function( Subject, Predicate, Object_or_Literal ){
500-
this.cursor['plus_triple'] = [ Subject, Predicate, Object_or_Literal ];
521+
WOQLQuery.prototype.add_triple = function( Subject, Predicate, Object_or_Literal ){
522+
this.cursor['add_triple'] = [ Subject, Predicate, Object_or_Literal ];
501523
return this.lastUpdate();
502524
}
503525

504-
WOQLQuery.prototype.minus_quad = function( Subject, Predicate, Object_or_Literal, Graph ){
505-
this.cursor['minus_quad'] = [ Subject, Predicate, Object_or_Literal, Graph ];
526+
WOQLQuery.prototype.delete_quad = function( Subject, Predicate, Object_or_Literal, Graph ){
527+
this.cursor['delete_quad'] = [ Subject, Predicate, Object_or_Literal, Graph ];
506528
return this.lastUpdate();
507529
}
508530

509-
WOQLQuery.prototype.plus_quad = function( Subject, Predicate, Object_or_Literal, Graph){
510-
this.cursor['plus_quad'] = [ Subject, Predicate, Object_or_Literal, Graph ];
531+
WOQLQuery.prototype.add_quad = function( Subject, Predicate, Object_or_Literal, Graph){
532+
this.cursor['add_quad'] = [ Subject, Predicate, Object_or_Literal, Graph ];
511533
return this.lastUpdate();
512534
}
513535

@@ -552,6 +574,9 @@ WOQLQuery.prototype.documentMetadata = function(){
552574
);
553575
}
554576

577+
578+
579+
555580
WOQLQuery.prototype.propertyMetadata = function(){
556581
return this.and(
557582
WOQL.or(
@@ -602,9 +627,9 @@ WOQLQuery.prototype.getDataOfProperty = function(chosen){
602627

603628
WOQLQuery.prototype.documentProperties = function(id){
604629
return this.and(
605-
WOQL.triple(id, "v:Property", "v:Property_Value"),
606-
WOQL.opt().quad("v:Property", "rdfs:label", "v:Property_Label", "db:schema"),
607-
WOQL.opt().quad("v:Property", "rdf:type", "v:Property_Type", "db:schema")
630+
'WOQL.triple(id, "v:Property", "v:Property_Value")',
631+
'WOQL.opt().quad("v:Property", "rdfs:label", "v:Property_Label", "db:schema")',
632+
'WOQL.opt().quad("v:Property", "rdf:type", "v:Property_Type", "db:schema")'
608633
);
609634
}
610635

@@ -637,4 +662,109 @@ WOQLQuery.prototype.simpleGraphQuery = function(){
637662
);
638663
}
639664

640-
module.exports = WOQL ;
665+
function WOQLSchema(){
666+
this.triples = [];
667+
this.subject = false;
668+
}
669+
670+
WOQLSchema.prototype.execute = function(client){
671+
var subs = [];
672+
for(var i = 0; i<this.triples.length; i++){
673+
subs.push(WOQL.add_quad(...this.triples[i], "db:schema"));
674+
}
675+
return WOQL.and(subs).execute(client);
676+
}
677+
678+
WOQLSchema.prototype.getO = function(s, p){
679+
for(var i = 0; i<this.triples.length; i++){
680+
if(this.triples[i][0] == s && this.triples[i][1] == p ) return this.triples[i][2];
681+
}
682+
return false;
683+
}
684+
685+
686+
WOQLSchema.prototype.addPO = function(p, o){
687+
this.triples.push([this.subject, p, o]);
688+
return this;
689+
}
690+
691+
WOQLSchema.prototype.addClass = function(c){
692+
this.subject = c;
693+
return this.addPO("rdf:type", "owl:Class");
694+
}
695+
696+
WOQLSchema.prototype.addProperty = function(p, t){
697+
this.subject = p;
698+
this.addPO("rdfs:range", t);
699+
if(WOQL.isLiteralType(t)){
700+
return this.addPO("rdf:type", "owl:DatatypeProperty");
701+
}
702+
else {
703+
return this.addPO("rdf:type", "owl:ObjectProperty");
704+
}
705+
}
706+
707+
WOQLSchema.prototype.label = function(l, lang){
708+
lang = (lang ? lang : "en");
709+
return this.addPO('rdfs:label', {"@value": l, "@language": "en"});
710+
}
711+
712+
WOQLSchema.prototype.comment = function(c, lang){
713+
lang = (lang ? lang : "en");
714+
return this.addPO('rdfs:comment', {"@value": c, "@language": "en"});
715+
}
716+
717+
WOQLSchema.prototype.parent = function(...p){
718+
return this.addPO('rdfs:subClassOf', p);
719+
}
720+
721+
WOQLSchema.prototype.abstract = function(){
722+
return this.addPO('tcs:tag', "tcs:abstract");
723+
}
724+
725+
WOQLSchema.prototype.entity = function(){
726+
return this.parent("tcs:Entity");
727+
}
728+
729+
WOQLSchema.prototype.relationship = function(){
730+
return this.parent("tcs:Relationship");
731+
}
732+
733+
WOQLSchema.prototype.card = function(n, which){
734+
let os = this.subject;
735+
this.subject += "_" + which;
736+
this.addPO('rdf:type', "owl:Restriction");
737+
this.addPO("owl:onProperty", os);
738+
switch(which){
739+
case "max": this.addPO("owl:maxCardinality", n);
740+
break;
741+
case "min": this.addPO("owl:minCardinality", n);
742+
break;
743+
default: this.addPO("owl:cardinality", n);
744+
}
745+
let od = this.getO(os, "rdfs:domain");
746+
if(od){
747+
this.triples.push([od, "rdfs:subClassOf", this.subject]);
748+
}
749+
this.subject = os;
750+
return this;
751+
}
752+
753+
WOQLSchema.prototype.max = function(m){
754+
return this.card(m, "max");
755+
}
756+
757+
WOQLSchema.prototype.min = function(m){
758+
return this.card(m, "min");
759+
}
760+
761+
WOQLSchema.prototype.cardinality = function(m){
762+
return this.card(m, "cardinality");
763+
}
764+
765+
WOQLSchema.prototype.domain = function(d){
766+
return this.addPO('rdfs:domain', d);
767+
}
768+
769+
770+
module.exports = WOQL;

lib/woqlResult.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ WOQLResult.prototype.last = function(){
3636
}
3737

3838
WOQLResult.prototype.next = function(){
39+
var res = this.bindings[this.cursor];
3940
this.cursor++;
40-
return this.bindings[this.cursor];
41+
return res;
4142
}
4243

4344
WOQLResult.prototype.prev = function(){

0 commit comments

Comments
 (0)