Skip to content

Commit b4ff0c5

Browse files
added more functions to woql and added a schema object
1 parent 6337c35 commit b4ff0c5

File tree

3 files changed

+143
-14
lines changed

3 files changed

+143
-14
lines changed

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: 140 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,41 @@ WOQL.sub = function(a, b){ return new WOQLQuery().sub(a, b); }
2222
WOQL.isa = function(a, b){ return new WOQLQuery().isa(a, b); }
2323
WOQL.trim = function(a, b){ return new WOQLQuery().trim(a, b); }
2424
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);}
25+
WOQL.delete_triple = function( S, P, O ){ return new WOQLQuery().delete_triple (S, P, O); }
26+
WOQL.add_triple = function( S, P, O ){ return new WOQLQuery().add_triple (S, P, O); }
27+
WOQL.delete_quad = function( S, P, O, G ){ return new WOQLQuery().delete_triple (S, P, O, G); }
28+
WOQL.add_quad = function( S, P, O, G ){ return new WOQLQuery().add_triple (S, P, O, G);}
2929
WOQL.eval = function(arith, v){ return new WOQLQuery().eval(arith, v);}
3030
WOQL.plus = function(...args){ return new WOQLQuery().plus(...args);}
3131
WOQL.minus = function(...args){ return new WOQLQuery().minus(...args); }
3232
WOQL.times = function(...args){ return new WOQLQuery().times(...args); }
3333
WOQL.divide = function(...args){ return new WOQLQuery().divide(...args); }
3434
WOQL.exp = function(a, b){ return new WOQLQuery().exp(a, b); }
35+
36+
WOQL.schema = function(){ return new WOQLSchema(); }
37+
38+
WOQL.query = function(){ return new WOQLQuery(); }
39+
40+
WOQL.get = function(map, target){ return new WOQLQuery().get(map, target); }
41+
WOQL.as = function(map, vari){ return new WOQLQuery().as(map, vari); }
42+
WOQL.remote = function(url){ return new WOQLQuery().remote(url); }
43+
WOQL.unique = function(prefix, vari){ return new WOQLQuery().unique(prefix, vari); }
44+
WOQL.list = function(vars){ return new WOQLQuery().list(vars); }
45+
//WOQL.value = function(vars){ return new WOQLQuery().list(vars); }
46+
47+
3548
WOQL.json = function(json){ return new WOQLQuery().json(json); }
3649
WOQL.rule = function(){ return new FramePattern.FrameRule() }
3750

51+
WOQL.isLiteralType = function(t){
52+
if(t){
53+
var pref = t.split(":");
54+
if(pref[0] == "xdd" || pref[0] == "xsd") return true;
55+
}
56+
return false;
57+
}
58+
59+
3860
function WOQLQuery(query, results){
3961
this.query = (query ? query : {});
4062
this.cursor = this.query;
@@ -490,23 +512,23 @@ WOQLQuery.prototype.delete = function(JSON_or_IRI){
490512
return this.lastUpdate();
491513
}
492514

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

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

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

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

@@ -636,4 +658,109 @@ WOQLQuery.prototype.simpleGraphQuery = function(){
636658
);
637659
}
638660

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