Skip to content

Commit 298316e

Browse files
committed
Merge branch 'dev' of https://github.com/terminusdb/terminus-client into dev
2 parents a13b212 + bdfbb11 commit 298316e

File tree

4 files changed

+88
-25
lines changed

4 files changed

+88
-25
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
}

lib/woqlClient.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,7 @@ WOQLClient.prototype.updateCSV = function(csv_path, commit_msg, gtype, gid) {
464464
WOQLClient.prototype.getCSV = function(csv_name, download, gtype, gid) {
465465
let options = {}, filePath
466466
options.name=csv_name;
467-
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options).then(results => {
468-
if (download) {
469-
const url=window.URL.createObjectURL(new Blob([results]));
470-
const link=document.createElement('a');
471-
link.href = url;
472-
link.setAttribute('download', csv_name);
473-
document.body.appendChild(link);
474-
link.click();
475-
}
476-
return results;
477-
})
467+
return this.dispatch(CONST.GET_CSV, this.connectionConfig.csvURL(gtype, gid), options)
478468
}
479469

480470
/**
@@ -524,12 +514,14 @@ WOQLClient.prototype.info = function() {
524514
* @param {WOQLQuery} woql is a "woql query object"
525515
* @param {string} commit_msg - if the query contains any updates, it should include a textual message describing the reason for the update
526516
*/
527-
WOQLClient.prototype.query = function(woql, commit_msg) {
517+
WOQLClient.prototype.query = function(woql, commit_msg, all_witnesses) {
518+
all_witnesses = all_witnesses || false
528519
commit_msg = commit_msg || 'Commit generated with javascript client without message'
529520
if (woql && woql.json && (!woql.containsUpdate() || commit_msg)) {
530521
woql.context(this.connection.getContextForOutboundQuery(woql, this.db(), this.organization()))
531522
let doql = woql.containsUpdate() ? this.generateCommitInfo(commit_msg) : {}
532523
doql.query = woql.json()
524+
if(all_witnesses) doql.all_witnesses = true
533525
return this.dispatch(CONST.WOQL_QUERY, this.connectionConfig.queryURL(), doql)
534526
}
535527
let errmsg = `WOQL query parameter error`

0 commit comments

Comments
 (0)