@@ -7,6 +7,7 @@ const FramePattern = require('./framePattern');
7
7
const FrameHelper = require ( './frameHelper' ) ;
8
8
9
9
const WOQL = { } ;
10
+
10
11
WOQL . when = function ( Query , Update ) { return new WOQLQuery ( ) . when ( Query , Update ) ; }
11
12
WOQL . opt = function ( query ) { return new WOQLQuery ( ) . opt ( query ) ; }
12
13
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); }
22
23
WOQL . isa = function ( a , b ) { return new WOQLQuery ( ) . isa ( a , b ) ; }
23
24
WOQL . trim = function ( a , b ) { return new WOQLQuery ( ) . trim ( a , b ) ; }
24
25
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 ) ; }
29
30
WOQL . eval = function ( arith , v ) { return new WOQLQuery ( ) . eval ( arith , v ) ; }
30
31
WOQL . plus = function ( ...args ) { return new WOQLQuery ( ) . plus ( ...args ) ; }
31
32
WOQL . minus = function ( ...args ) { return new WOQLQuery ( ) . minus ( ...args ) ; }
32
33
WOQL . times = function ( ...args ) { return new WOQLQuery ( ) . times ( ...args ) ; }
33
34
WOQL . divide = function ( ...args ) { return new WOQLQuery ( ) . divide ( ...args ) ; }
34
35
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
+
35
49
WOQL . json = function ( json ) { return new WOQLQuery ( ) . json ( json ) ; }
36
50
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
+
38
60
39
61
function WOQLQuery ( query , results ) {
40
62
this . query = ( query ? query : { } ) ;
@@ -405,7 +427,7 @@ WOQLQuery.prototype.and = function(...queries){
405
427
return this ;
406
428
}
407
429
408
- WOQLQuery . prototype . or = function ( queries ) {
430
+ WOQLQuery . prototype . or = function ( ... queries ) {
409
431
this . cursor [ "or" ] = [ ] ;
410
432
for ( var i = 0 ; i < queries . length ; i ++ ) {
411
433
if ( queries [ i ] . contains_update ) this . contains_update = true ;
@@ -491,23 +513,23 @@ WOQLQuery.prototype.delete = function(JSON_or_IRI){
491
513
return this . lastUpdate ( ) ;
492
514
}
493
515
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 ] ;
496
518
return this . lastUpdate ( ) ;
497
519
}
498
520
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 ] ;
501
523
return this . lastUpdate ( ) ;
502
524
}
503
525
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 ] ;
506
528
return this . lastUpdate ( ) ;
507
529
}
508
530
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 ] ;
511
533
return this . lastUpdate ( ) ;
512
534
}
513
535
@@ -552,6 +574,9 @@ WOQLQuery.prototype.documentMetadata = function(){
552
574
) ;
553
575
}
554
576
577
+
578
+
579
+
555
580
WOQLQuery . prototype . propertyMetadata = function ( ) {
556
581
return this . and (
557
582
WOQL . or (
@@ -602,9 +627,9 @@ WOQLQuery.prototype.getDataOfProperty = function(chosen){
602
627
603
628
WOQLQuery . prototype . documentProperties = function ( id ) {
604
629
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")'
608
633
) ;
609
634
}
610
635
@@ -637,4 +662,109 @@ WOQLQuery.prototype.simpleGraphQuery = function(){
637
662
) ;
638
663
}
639
664
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 ;
0 commit comments