1-
21const UTILS = require ( './utils' ) ;
32const WOQLRule = require ( './woqlRule' ) ;
43const FrameRule = require ( './frameRule' ) ;
@@ -505,6 +504,7 @@ WOQL.boxClasses = function(prefix, classes, except, graph){ return new WOQLQuery
505504
506505WOQL . libs = function ( ...libs ) { return new WOQLQuery ( ) . libs ( ...libs ) }
507506
507+ WOQL . generateChoiceList = function ( cls , clslabel , clsdesc , choices , graph , parent ) { return new WOQLQuery ( ) . generateChoiceList ( cls , clslabel , clsdesc , choices , graph , parent ) }
508508
509509/**
510510 * Deletes the Class with the passed ID form the schema (and all references to it)
@@ -1274,20 +1274,18 @@ WOQLQuery.prototype.delete_property = function(p, graph){
12741274WOQLQuery . prototype . boxClasses = function ( prefix , classes , except , graph ) {
12751275 graph = ( graph ? this . cleanGraph ( graph ) : "db:schema" ) ;
12761276 prefix = prefix || "scm:" ;
1277- var subs = [
1278- WOQL . quad ( "v:Cid" , "rdf:type" , "owl:Class" , graph ) ,
1279- WOQL . not ( ) . abstract ( "v:Cid" , graph ) ,
1280- ] ;
1277+ var subs = [ ] ;
12811278 for ( var i = 0 ; i < classes . length ; i ++ ) {
12821279 subs . push ( WOQL . sub ( "v:Cid" , this . cleanClass ( classes [ i ] ) ) ) ;
12831280 }
1281+ var nsubs = [ ] ;
12841282 for ( var i = 0 ; i < except . length ; i ++ ) {
1285- subs . push ( WOQL . not ( ) . sub ( "v:Cid" , this . cleanClass ( except [ i ] ) ) ) ;
1283+ nsubs . push ( WOQL . not ( ) . sub ( "v:Cid" , this . cleanClass ( except [ i ] ) ) ) ;
12861284 }
12871285 //property punning
12881286 //generate a property id that is the same as the classname but starting with a lowercase letter
12891287 let idgens = [
1290- WOQL . re ( ".* #(.)(.*)" , "v:Cid" , [ "v:AllB" , "v:FirstB" , "v:RestB" ] ) ,
1288+ WOQL . re ( "#(.)(.*)" , "v:Cid" , [ "v:AllB" , "v:FirstB" , "v:RestB" ] ) ,
12911289 WOQL . lower ( "v:FirstB" , "v:Lower" ) ,
12921290 WOQL . concat ( [ "v:Lower" , "v:RestB" ] , "v:Propname" ) ,
12931291 WOQL . concat ( [ "Scoped" , "v:FirstB" , "v:RestB" ] , "v:Cname" ) ,
@@ -1296,7 +1294,10 @@ WOQLQuery.prototype.boxClasses = function(prefix, classes, except, graph){
12961294 ] ;
12971295
12981296 const filter = WOQL . and (
1297+ WOQL . quad ( "v:Cid" , "rdf:type" , "owl:Class" , graph ) ,
1298+ WOQL . not ( ) . abstract ( "v:Cid" , graph ) ,
12991299 WOQL . or ( ...subs ) ,
1300+ WOQL . and ( ...nsubs ) ,
13001301 WOQL . and ( ...idgens ) ,
13011302 WOQL . quad ( "v:Cid" , "rdfs:label" , "v:Label" , graph ) ,
13021303 WOQL . quad ( "v:Cid" , "rdfs:comment" , "v:Desc" , graph )
@@ -1312,12 +1313,50 @@ WOQLQuery.prototype.boxClasses = function(prefix, classes, except, graph){
13121313 ) ) ;
13131314}
13141315
1316+ WOQLQuery . prototype . generateChoiceList = function ( cls , clslabel , clsdesc , choices , graph , parent ) {
1317+ parent = parent || "scm:Enumerated" ;
1318+ graph = graph || "db:schema" ;
1319+ var confs = [
1320+ WOQL . add_class ( cls , graph )
1321+ . label ( clslabel )
1322+ . description ( clsdesc )
1323+ . parent ( parent )
1324+ ] ;
1325+ for ( var i = 0 ; i < choices . length ; i ++ ) {
1326+ if ( ! choices [ i ] ) continue ;
1327+ confs . push ( WOQL . insert ( choices [ i ] [ 0 ] , cls , graph )
1328+ . label ( choices [ i ] [ 1 ] )
1329+ . description ( choices [ i ] [ 2 ] )
1330+ )
1331+ }
1332+ //generate one of list
1333+ var clist = [ ] ;
1334+ var listid = "_:" + cls . split ( ":" ) [ 1 ] ;
1335+ var lastid = listid ;
1336+ for ( var i = 0 ; i <= choices . length ; i ++ ) {
1337+ if ( ! choices [ i ] ) continue ;
1338+ var nextid = ( i < ( choices . length - 1 ) ? listid + "_" + i : "rdf:nil" ) ;
1339+ clist . push ( WOQL . add_quad ( lastid , "rdf:first" , choices [ i ] [ 0 ] , graph ) )
1340+ clist . push ( WOQL . add_quad ( lastid , "rdf:rest" , nextid , graph ) ) ;
1341+ lastid = nextid ;
1342+ }
1343+ //do the owl oneof
1344+ let oneof = WOQL . and (
1345+ WOQL . add_quad ( cls , "owl:oneOf" , listid , graph ) ,
1346+ ...clist
1347+ )
1348+ return WOQL . and ( ...confs , oneof ) ;
1349+ }
1350+
1351+
13151352WOQLQuery . prototype . libs = function ( ...libs ) {
13161353 var bits = [ ] ;
13171354 if ( libs . indexOf ( "xdd" ) != - 1 ) {
13181355 bits . push ( this . loadXDD ( ) ) ;
1319- if ( libs . indexOf ( "box" ) != - 1 ) bits . push ( this . loadXDDBoxes ( ) ) ;
1320-
1356+ if ( libs . indexOf ( "box" ) != - 1 ) {
1357+ bits . push ( this . loadXDDBoxes ( ) ) ;
1358+ bits . push ( this . loadXSDBoxes ( ) ) ;
1359+ }
13211360 }
13221361 else if ( libs . indexOf ( "box" ) != - 1 ) {
13231362 bits . push ( this . loadXSDBoxes ( ) ) ;
@@ -1402,9 +1441,9 @@ WOQLQuery.prototype.loadXSDBoxes = function(){
14021441 this . boxDatatype ( "xsd:ID" , "ID" , "An xsd:ID value." ) ,
14031442 this . boxDatatype ( "xsd:IDREF" , "IDREF" , "An xsd:IDREF value." ) ,
14041443 this . boxDatatype ( "xsd:ENTITY" , "ENTITY" , "An xsd:ENTITY value." ) ,
1405- this . boxDatatype ( "xsd :XMLLiteral" , "XML Literal" , "An rdf:XMLLiteral value." ) ,
1406- this . boxDatatype ( "xsd :PlainLiteral" , "Plain Literal" , "An rdf:PlainLiteral value." ) ,
1407- this . boxDatatype ( "rdfs:Literal" , "Literal" , "An rdfs:Literal value." )
1444+ // this.boxDatatype("rdf :XMLLiteral", "XML Literal", "An rdf:XMLLiteral value."),
1445+ // this.boxDatatype("rdf :PlainLiteral", "Plain Literal", "An rdf:PlainLiteral value."),
1446+ // this.boxDatatype("rdfs:Literal", "Literal", "An rdfs:Literal value.")
14081447 )
14091448}
14101449
@@ -1439,9 +1478,9 @@ WOQLQuery.prototype.boxDatatype = function(datatype, label, descr, graph, prefix
14391478 let ext = datatype . split ( ":" ) [ 1 ] ;
14401479 let box_class_id = prefix + ext . charAt ( 0 ) . toUpperCase ( ) + ext . slice ( 1 ) ;
14411480 let box_prop_id = prefix + ext . charAt ( 0 ) . toLowerCase ( ) + ext . slice ( 1 ) ;
1442- var box_class = WOQL . insert ( box_class_id , "owl:Class" , graph ) . label ( label ) . parent ( "scm:Box" ) ;
1481+ var box_class = WOQL . add_class ( box_class_id ) . label ( label ) . parent ( "scm:Box" ) ;
14431482 if ( descr ) box_class . description ( descr ) ;
1444- var box_prop = WOQL . insert ( box_prop_id , datatype , graph ) . label ( label ) ;
1483+ var box_prop = WOQL . add_property ( box_prop_id , datatype ) . label ( label ) . domain ( box_class_id )
14451484 if ( descr ) box_prop . description ( descr ) ;
14461485 return WOQL . and ( box_class , box_prop ) ;
14471486}
@@ -1876,12 +1915,12 @@ WOQLQuery.prototype.execute = function(client){
18761915 if ( typeof this . query [ '@context' ] [ pref ] == "undefined" )
18771916 this . query [ '@context' ] [ pref ] = UTILS . standard_urls [ pref ] ;
18781917 }
1918+ this . query [ "@context" ] [ "_" ] = "_:" ;
18791919 var json = this . json ( ) ;
18801920 }
18811921 else {
18821922 var json = this . json ( ) ;
18831923 }
1884- this . query [ "@context" ] [ "_" ] = "_:" ;
18851924 if ( this . contains_update ) {
18861925 return client . select ( false , json ) ;
18871926 //return client.update(false, json);
0 commit comments