Skip to content

Commit 196d369

Browse files
Purging more class cleaning
1 parent 1a5ef96 commit 196d369

File tree

3 files changed

+14
-135
lines changed

3 files changed

+14
-135
lines changed

lib/query/woqlCore.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,15 @@ WOQLQuery.prototype.findLastSubject = function(json) {
561561
* @param {object} json
562562
*/
563563
WOQLQuery.prototype.findLastProperty = function(json) {
564-
if (json && json['query_list']) {
565-
for (var i = json['query_list'].length - 1; i >= 0; i--) {
566-
let lqs = this.findLastProperty(json['query_list'][i])
564+
if (json && json['and']) {
565+
for (var i = json['and'].length - 1; i >= 0; i--) {
566+
let lqs = this.findLastProperty(json['and'][i])
567+
if (lqs) return lqs
568+
}
569+
}
570+
if (json && json['or']) {
571+
for (var i = json['or'].length - 1; i >= 0; i--) {
572+
let lqs = this.findLastProperty(json['or'][i])
567573
if (lqs) return lqs
568574
}
569575
}

lib/query/woqlQuery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ WOQLQuery.prototype.wrapCursorWithAnd = function() {
1919
if (this.cursor && this.cursor['@type'] == 'And') {
2020
let newby = this.cursor['and'].length
2121
this.and({})
22-
this.cursor = this.cursor['and'][newby]['query']
22+
this.cursor = this.cursor['and'][newby]
2323
return
2424
} else {
2525
let nj = new WOQLQuery().json(this.cursor)
2626
for (var k in this.cursor) delete this.cursor[k]
2727
//create an empty json for the new query
2828
this.and(nj, {})
29-
this.cursor = this.cursor['and'][1]['query']
29+
this.cursor = this.cursor['and'][1]
3030
}
3131
}
3232

lib/query/woqlSchema.js

Lines changed: 3 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ WOQLQuery.prototype._sg = function(g) {
4141
WOQLQuery.prototype.add_class = function(c, graph) {
4242
graph = this._sg(graph)
4343
if (c) {
44-
c = this.cleanClass(c, true)
4544
this.add_quad(c, 'rdf:type', 'sys:Class', graph)
4645
this._set_adding_class(c)
4746
}
@@ -57,7 +56,7 @@ WOQLQuery.prototype.add_class = function(c, graph) {
5756
WOQLQuery.prototype.insert_class_data = function(data, graph) {
5857
graph = this._sg(graph)
5958
if (data.id) {
60-
const classId = this.cleanClass(data.id, true)
59+
const classId = data.id
6160
this.add_class(classId, graph)
6261
if (data.label) {
6362
this.label(data.label)
@@ -100,7 +99,7 @@ WOQLQuery.prototype.insert_doctype_data = function(data, refGraph) {
10099
*/
101100
WOQLQuery.prototype.add_property = function(p, t, graph) {
102101
graph = this._sg(graph)
103-
t = t ? this.cleanType(t, true) : 'xsd:string'
102+
t = t ? t : 'xsd:string'
104103
graph = graph || this.graph
105104
if (p) {
106105
p = this.cleanPathPredicate(p)
@@ -131,7 +130,7 @@ WOQLQuery.prototype.insert_property_data = function(data, graph) {
131130
graph = this._sg(graph)
132131
if (data.id) {
133132
p = this.cleanPathPredicate(data.id)
134-
t = data.range ? this.cleanType(data.range, true) : 'xsd:string'
133+
t = data.range ? data.range : 'xsd:string'
135134
this.add_property(p, t, graph)
136135
if (data.label) {
137136
this.label(data.label)
@@ -160,7 +159,6 @@ WOQLQuery.prototype.insert_property_data = function(data, graph) {
160159
* @returns WOQLQuery object
161160
*/
162161
WOQLQuery.prototype.delete_class = function(c, graph, cvar = 'v:Class') {
163-
c = this.cleanClass(c, true)
164162
return this.and(new WOQLQuery().eq(c, cvar), new WOQLQuery()._nuke_schema_element(cvar, graph))
165163
}
166164

@@ -174,7 +172,6 @@ WOQLQuery.prototype.delete_class = function(c, graph, cvar = 'v:Class') {
174172
*/
175173
WOQLQuery.prototype.delete_property = function(p, graph, propvar) {
176174
propvar = propvar || 'v:Property'
177-
p = this.cleanClass(p, true)
178175
return this.and(
179176
new WOQLQuery().eq(p, propvar),
180177
new WOQLQuery()._nuke_schema_element(propvar, graph),
@@ -256,130 +253,6 @@ WOQLQuery.prototype.makeEnum = function(client, prop, cls, clslabel, clsdesc, gr
256253
return new WOQLQuery().quad('v:Choice', 'type', cls, graph)
257254
}
258255

259-
//makeEnum(client(), "", "scm:DealType", "Deal Type", "The stage of the deal")
260-
261-
/**
262-
* Generates a class representing a choice list - an enumerated list of specific options
263-
* @param {string} cls - the id of the choice list class
264-
* @param {string} clslabel - the name of the class
265-
* @param {string} [clsdesc] - description of the class
266-
* @param {Array} choices - an array of choices, with each entry being an array ["choiceid", "choice label", "choice description"]
267-
* @param {string} graph - the id of the graph that the choice list will be written to
268-
* @param {string} parent - the id of a class that this class inherits from (e.g. scm:Enumerated)
269-
*/
270-
WOQLQuery.prototype.generateChoiceList = function(cls, clslabel, clsdesc, choices, graph, parent) {
271-
graph = this._sg(graph)
272-
var clist = []
273-
var listid = '_:' + (cls.indexOf(':') == -1 ? cls : cls.split(':')[1])
274-
const className = this.cleanClass(cls, true)
275-
var lastid = listid
276-
let wq = new WOQLQuery().add_class(className, graph).label(clslabel)
277-
if (clsdesc) wq.description(clsdesc)
278-
if (parent) wq.parent(parent)
279-
var confs = [wq]
280-
for (var i = 0; i < choices.length; i++) {
281-
if (!choices[i]) continue
282-
if (Array.isArray(choices[i])) {
283-
var chid = choices[i][0]
284-
var clab = choices[i][1]
285-
var desc = choices[i][2] || false
286-
} else {
287-
var chid = choices[i]
288-
var clab = UTILS.labelFromURL(chid)
289-
var desc = false
290-
}
291-
let cq = new WOQLQuery().insert(chid, className, graph).label(clab)
292-
if (desc) cq.description(desc)
293-
confs.push(cq)
294-
var nextid = i < choices.length - 1 ? listid + '_' + i : 'rdf:nil'
295-
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:first', new WOQLQuery().iri(chid), graph))
296-
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:rest', new WOQLQuery().iri(nextid), graph))
297-
lastid = nextid
298-
}
299-
//do the owl oneof
300-
let oneof = new WOQLQuery().and(
301-
new WOQLQuery().add_quad(className, 'owl:oneOf', new WOQLQuery().iri(listid), graph),
302-
...clist,
303-
)
304-
return this.and(...confs, oneof)
305-
}
306-
307-
WOQLQuery.prototype._oneOfList = function(cls, ids, graph) {
308-
var listid = '_:' + (cls.indexOf(':') == -1 ? cls : cls.split(':')[1])
309-
var lastid = listid
310-
graph = this._sg(graph)
311-
let clist = []
312-
for (var i = 0; i < ids.length; i++) {
313-
var nextid = i < ids.length - 1 ? listid + '_' + i : 'rdf:nil'
314-
clist.push(
315-
new WOQLQuery().add_quad(lastid, 'rdf:first', new WOQLQuery().iri(ids[i]), graph),
316-
)
317-
clist.push(new WOQLQuery().add_quad(lastid, 'rdf:rest', new WOQLQuery().iri(nextid), graph))
318-
lastid = nextid
319-
}
320-
return this.and(
321-
new WOQLQuery().add_quad(cls, 'owl:oneOf', new WOQLQuery().iri(listid), graph),
322-
...clist,
323-
)
324-
}
325-
326-
/**
327-
* @description delete the enum list for a specific enumeration class, but not the class
328-
* @param {string} classId - the enum class id
329-
* @param {string} [graph] - the resource identifier of a schema graph. The Default value id schema/main
330-
* @returns {WOQLQuery} - A WOQLQuery which contains the Delete Choice List Statement
331-
*/
332-
WOQLQuery.prototype.deleteChoiceList = function(classId, graph) {
333-
graph = this._sg(graph)
334-
//if I have to remove multi enum together
335-
const sufVar = Date.now()
336-
const vRest = `v:Rest${sufVar}`
337-
const vClist = `v:Clist${sufVar}`
338-
const vEntry = `v:Entry${sufVar}`
339-
const vPath = `v:Path${sufVar}`
340-
return new WOQLQuery().and(
341-
new WOQLQuery().from(graph).and(
342-
new WOQLQuery()
343-
.select(vRest)
344-
.distinct(vRest)
345-
.triple(classId, 'owl:oneOf', vClist)
346-
.path(vClist, 'rdf:rest+', vEntry, vPath)
347-
.or(
348-
new WOQLQuery().triple(vEntry, 'rdf:first', vRest),
349-
new WOQLQuery()
350-
.triple(vClist, 'rdf:first', `v:First${sufVar}`)
351-
.eq(`v:First${sufVar}`, vRest),
352-
),
353-
new WOQLQuery()
354-
.triple(vRest, `v:valprop${sufVar}`, `v:valval${sufVar}`)
355-
.triple(`v:X${sufVar}`, 'rdf:first', vRest)
356-
.triple(`v:Y${sufVar}`, 'rdf:rest', `v:valRest${sufVar}`)
357-
.triple(classId, `v:classProp${sufVar}`, `v:classPropVal${sufVar}`),
358-
),
359-
new WOQLQuery()
360-
.delete_quad(vRest, `v:valprop${sufVar}`, `v:valval${sufVar}`, graph)
361-
.delete_quad(`v:X${sufVar}`, 'rdf:first', vRest, graph)
362-
.delete_quad(`v:Y${sufVar}`, 'rdf:rest', `v:valRest${sufVar}`, graph)
363-
.delete_quad(classId, `v:classProp${sufVar}`, `v:classPropVal${sufVar}`, graph),
364-
)
365-
}
366-
367-
/**
368-
* @description update or create an enumeration class. You have to add at least one permitted values in the list
369-
* @param {string} classId - the enum class id
370-
* @param {string} classLabel - the enum class label
371-
* @param {string} [classDesc] - the enum class description
372-
* @param {array} choices - an list of permitted values [[id,label,comment],[id,label,comment]]
373-
* @param {string} [graph] - the resource identifier of a schema graph. The Default value id schema/main
374-
* @returns {WOQLQuery} - A WOQLQuery which contains the Update Enum/Choice Class Statement
375-
*/
376-
WOQLQuery.prototype.updateChoiceList = function(classId, classLabel, classDesc, choices, graph) {
377-
return new WOQLQuery().and(
378-
new WOQLQuery().opt(new WOQLQuery().deleteChoiceList(classId, graph)),
379-
new WOQLQuery().generateChoiceList(classId, classLabel, classDesc, choices, graph),
380-
)
381-
}
382-
383256
/**
384257
* Adds the xdd datataypes to the graph
385258
*/

0 commit comments

Comments
 (0)