Skip to content

Commit 579f8cf

Browse files
fixed bug with missing choices comments in classesAndChoices
1 parent b87c5de commit 579f8cf

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

lib/query/woqlLibrary.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,28 @@ WOQLLibrary.prototype.classesAndChoices = function(values, variables, schema_res
117117

118118

119119
let qpattern = new WOQLQuery().and(
120-
this.classes(values, variables, schema_resource),
121-
new WOQLQuery().opt().select("v:Choices").from("schema/main")
122-
.group_by("v:Class ID", ["v:choice id", "v:choice label", "v:choice description"], "v:Choices")
123-
.and(
124-
new WOQLQuery().select("v:choice id").distinct("v:choice id")
125-
.triple("v:Class ID", "owl:oneOf", "v:Choice")
126-
.path("v:Choice", "rdf:rest+", "v:Entry", "v:Path")
127-
.or(
120+
this.classes(values, variables, schema_resource),
121+
new WOQLQuery().opt().select("v:Choices").from("schema/main")
122+
.group_by("v:Class ID", ["v:choice id", "v:choice label", "v:choice description"], "v:Choices")
123+
.and(
124+
new WOQLQuery().select("v:choice id").distinct("v:choice id")
125+
.triple("v:Class ID", "owl:oneOf", "v:Choice")
126+
.path("v:Choice", "rdf:rest+", "v:Entry", "v:Path")
127+
.or(
128128
new WOQLQuery().triple("v:Choice", "rdf:first", "v:choice id"),
129129
new WOQLQuery().triple("v:Entry", "rdf:first", "v:choice id")
130-
),
131-
new WOQLQuery().triple("v:choice id", "label", "v:choice label")
132-
.triple("v:choice id", "comment", "v:choice description")
133-
)
134-
)
130+
),
131+
new WOQLQuery().triple("v:choice id", "label", "v:choice label"),
132+
new WOQLQuery().or(
133+
new WOQLQuery().and(
134+
new WOQLQuery().not().triple("v:choice id", "comment", "v:any_choice"),
135+
new WOQLQuery().eq("v:choice description", "v:choice label")
136+
),
137+
new WOQLQuery().triple("v:choice id", "comment", "v:choice description"),
138+
139+
)
140+
)
141+
)
135142

136143
return this._add_constraints(qpattern, values)
137144
}

lib/query/woqlSchema.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,47 @@ WOQLQuery.prototype._nuke_schema_element = function(elvar, graph) {
188188
/**
189189
* Experimental / Unstable API
190190
*/
191+
WOQLQuery.prototype.genEnum = function(prop, cls, clslabel, clsdesc, graph) {
192+
clslabel = clslabel || cls
193+
graph = this._sg(graph)
194+
195+
let add_class = new WOQLQuery()
196+
.add_quad(cls, "type", "owl:Class", graph)
197+
.add_quad(cls, "label", clslabel, graph)
198+
if(clsdesc){
199+
add_class.add_quad(cls, "comment", clsdesc, graph)
200+
}
201+
202+
this.and(
203+
new WOQLQuery().select("v:PV").distinct("v:PV").triple("v:A", prop, "v:PV"),
204+
new WOQLQuery().idgen(cls, ["v:PV"], "v:ChoiceID"),
205+
add_class,
206+
new WOQLQuery().add_quad("v:ChoiceID", "type", cls, graph)
207+
.add_quad("v:ChoiceID", "label", "v:PV", graph)
208+
)
209+
return this
210+
}
211+
212+
WOQLQuery.prototype.finishEnum = function(client, cls, graph) {
213+
graph = this._sg(graph)
214+
let q = new WOQLQuery().quad("v:ChoiceID", "type", cls, graph)
215+
return client.query(q).then((results) => {
216+
let ids = []
217+
for(var i = 0; i< results.bindings.length; i++){
218+
ids.push(results.bindings[i]["ChoiceID"])
219+
}
220+
return client.query(this._oneOfList(cls, ids, graph))
221+
})
222+
}
223+
224+
WOQLQuery.prototype.makeEnum = function(client, prop, cls, clslabel, clsdesc, graph) {
225+
client.query(new WOQLQuery().genEnum( prop, cls, clslabel, clsdesc, graph))
226+
.then(() => new WOQLQuery().finishEnum(client, cls, graph))
227+
graph = this._sg(graph)
228+
return new WOQLQuery().quad("v:Choice", "type", cls, graph)
229+
}
230+
231+
//makeEnum(client(), "", "scm:DealType", "Deal Type", "The stage of the deal")
191232

192233
/**
193234
* Generates a class representing a choice list - an enumerated list of specific options
@@ -235,6 +276,24 @@ WOQLQuery.prototype.generateChoiceList = function(cls, clslabel, clsdesc, choice
235276
return this.and(...confs, oneof)
236277
}
237278

279+
WOQLQuery.prototype._oneOfList = function(cls, ids, graph) {
280+
var listid = '_:' + (cls.indexOf(':') == -1 ? cls : cls.split(':')[1])
281+
var lastid = listid
282+
graph = this._sg(graph)
283+
let clist = []
284+
for (var i = 0; i < ids.length; i++) {
285+
var nextid = i < ids.length - 1 ? listid + '_' + i : 'rdf:nil'
286+
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:first', new WOQLQuery().iri(ids[i]), graph))
287+
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:rest', new WOQLQuery().iri(nextid), graph))
288+
lastid = nextid
289+
}
290+
return this.and(
291+
new WOQLQuery().add_quad(cls, 'owl:oneOf', new WOQLQuery().iri(listid), graph),
292+
...clist,
293+
)
294+
}
295+
296+
238297
WOQLQuery.prototype.deleteChoiceList = function(classId, graph) {
239298
graph = this._sg(graph)
240299
return new WOQLQuery().and(

lib/woql.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,10 +1011,15 @@ WOQL.link = function(a, b, c, g){
10111011
}
10121012

10131013

1014+
WOQL.makeEnum = function(client, prop, cls, clslabel, clsdesc, graph){
1015+
return new WOQLQuery().makeEnum(client, prop, cls, clslabel, clsdesc, graph)
1016+
}
1017+
10141018
WOQL.generateChoiceList = function(cls, clslabel, clsdesc, choices, graph, parent){
10151019
return new WOQLQuery().generateChoiceList(cls, clslabel, clsdesc, choices, graph, parent)
10161020
}
10171021

1022+
10181023
WOQL.updateChoiceList = function(cls, clslabel, clsdesc, choices, graph){
10191024
return new WOQLQuery().updateChoiceList(cls, clslabel, clsdesc, choices, graph)
10201025
}

0 commit comments

Comments
 (0)