@@ -22,19 +22,41 @@ WOQL.sub = function(a, b){ return new WOQLQuery().sub(a, b); }
22
22
WOQL . isa = function ( a , b ) { return new WOQLQuery ( ) . isa ( a , b ) ; }
23
23
WOQL . trim = function ( a , b ) { return new WOQLQuery ( ) . trim ( a , b ) ; }
24
24
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 ) ; }
29
29
WOQL . eval = function ( arith , v ) { return new WOQLQuery ( ) . eval ( arith , v ) ; }
30
30
WOQL . plus = function ( ...args ) { return new WOQLQuery ( ) . plus ( ...args ) ; }
31
31
WOQL . minus = function ( ...args ) { return new WOQLQuery ( ) . minus ( ...args ) ; }
32
32
WOQL . times = function ( ...args ) { return new WOQLQuery ( ) . times ( ...args ) ; }
33
33
WOQL . divide = function ( ...args ) { return new WOQLQuery ( ) . divide ( ...args ) ; }
34
34
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
+
35
48
WOQL . json = function ( json ) { return new WOQLQuery ( ) . json ( json ) ; }
36
49
WOQL . rule = function ( ) { return new FramePattern . FrameRule ( ) }
37
50
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
+
38
60
function WOQLQuery ( query , results ) {
39
61
this . query = ( query ? query : { } ) ;
40
62
this . cursor = this . query ;
@@ -490,23 +512,23 @@ WOQLQuery.prototype.delete = function(JSON_or_IRI){
490
512
return this . lastUpdate ( ) ;
491
513
}
492
514
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 ] ;
495
517
return this . lastUpdate ( ) ;
496
518
}
497
519
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 ] ;
500
522
return this . lastUpdate ( ) ;
501
523
}
502
524
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 ] ;
505
527
return this . lastUpdate ( ) ;
506
528
}
507
529
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 ] ;
510
532
return this . lastUpdate ( ) ;
511
533
}
512
534
@@ -636,4 +658,109 @@ WOQLQuery.prototype.simpleGraphQuery = function(){
636
658
) ;
637
659
}
638
660
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 ;
0 commit comments