Skip to content

Commit adfe0e5

Browse files
committed
add fix capability issue
1 parent 089148d commit adfe0e5

12 files changed

+407
-284
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ module.exports = {
33
* @type {typeof import('./lib/woqlClient')}
44
*/
55
WOQLClient: require('./lib/woqlClient'),
6+
/**
7+
* @type {typeof import('./lib/woqlClientTools')}
8+
*/
9+
WOQLClientTools: require('./lib/woqlClientTools'),
610
/**
711
* @type {typeof import('./lib/utils')}
812
*/

lib/connectionCapabilities.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ConnectionCapabilities.prototype.setCapabilities = function(capabilities) {
3636
if (capabilities['@context']) this._load_connection_context(capabilities['@context'])
3737
this.user = this._extract_user_info(capabilities)
3838
this._extract_database_organizations() //find the organization which owns the db
39+
console.log("___AFTER_SET_CAPABILITIES",this.databases[1])
3940
return this.user
4041
}
4142

lib/query/woqlBuilder.js

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ WOQLQuery.prototype.nuke = function(g) {
124124
*/
125125

126126
WOQLQuery.prototype.property = function(proId, type_or_value) {
127+
//get the name of the last class it used only here!!!
128+
//the value is setted in add_class (woqlSchema)
127129
if (this._adding_class()) {
128130
let part = this.findLastSubject(this.cursor)
129131
let g = false
@@ -140,7 +142,6 @@ WOQLQuery.prototype.property = function(proId, type_or_value) {
140142
return this
141143
}
142144

143-
144145
WOQLQuery.prototype.node = function(node, type) {
145146
type = type || false
146147
if (type == 'add_quad') type = 'AddQuad'
@@ -185,7 +186,7 @@ WOQLQuery.prototype.insert_data = function(data, refGraph) {
185186
}
186187

187188
/**
188-
* @description Creates a pattern matching rule for a quad [Subject, Predicate, Object, Graph] or for a triple [Subject, Predicate, Object]
189+
* @description Creates a pattern matching rule for a quad [Subject, Predicate, Object, Graph] or for a triple [Subject, Predicate, Object]
189190
* add extra information about the type of the value object
190191
* @param {string} subject - The IRI of a triple’s subject or a variable
191192
* @param {string} predicate - The IRI of a property or a variable
@@ -226,13 +227,16 @@ WOQLQuery.prototype.domain = function(d) {
226227
d = this.cleanClass(d)
227228
return this._add_partial(false, 'rdfs:domain', d)
228229
}
230+
/**
231+
* @param {string} labelVar - the label variable name or string "v:Label" or "My Label"
232+
* @param {string} [lang] - the label language
233+
*/
229234

230-
WOQLQuery.prototype.label = function(l, lang) {
231-
lang = lang ? lang : 'en'
232-
if (l.substring(0, 2) == 'v:') {
233-
var d = l
235+
WOQLQuery.prototype.label = function(labelVar, lang = 'en') {
236+
if (labelVar.substring(0, 2) == 'v:') {
237+
var d = labelVar
234238
} else {
235-
var d = {'@value': l, '@type': 'xsd:string', '@language': lang}
239+
var d = {'@value': labelVar, '@type': 'xsd:string', '@language': lang}
236240
}
237241
return this._add_partial(false, 'rdfs:label', d)
238242
}
@@ -283,6 +287,15 @@ WOQLQuery.prototype._add_partial = function(s, p, o, g) {
283287
s = s || ctxt.subject
284288
g = g || ctxt.graph
285289
let lastsubj = this.findLastSubject(this.cursor)
290+
//if the last subject is a cardinality restriction quad
291+
//I'm looking for the last property
292+
if (
293+
lastsubj['woql:predicate'] &&
294+
lastsubj['woql:predicate']['woql:node'] &&
295+
lastsubj['woql:predicate']['woql:node'].indexOf('Cardinality') > -1
296+
) {
297+
lastsubj = this.findLastProperty(this.cursor)
298+
}
286299
if (lastsubj && !s) s = lastsubj['woql:subject']
287300
let t = ctxt.action || lastsubj['@type']
288301
if (!g) {
@@ -379,70 +392,53 @@ WOQLQuery.prototype._string_matches_object = function(str, node) {
379392
}
380393

381394
/**
382-
*
383-
* @param {string} n
395+
*
396+
* @param {number} cardValue
384397
* @param {string} which
385-
* @returns {WOQLQuery}
398+
* @returns {WOQLQuery}
386399
*/
387400

388-
WOQLQuery.prototype._card = function(n, which) {
401+
WOQLQuery.prototype._card = function(cardValue, which) {
389402
//need to generate a new id for the cardinality restriction object
390403
//and point it at the property in question via the onProperty function
391404
let ctxt = this.triple_builder_context || {}
392-
let s = ctxt.subject
393-
let g = ctxt.graph
405+
let subject = ctxt.subject
406+
let graph = ctxt.graph
394407
let lastsubj = this.findLastProperty(this.cursor)
395-
if (lastsubj && !s) s = lastsubj['woql:subject']
396-
if (typeof s == 'object') {
397-
if (s['woql:node']) s = s['woql:node']
398-
else return
408+
if (lastsubj && !subject) subject = lastsubj['woql:subject']
409+
if (typeof subject === 'object') {
410+
if (subject['woql:node']) subject = subject['woql:node']
411+
else return this
399412
}
400-
if (lastsubj && !g) {
413+
414+
if (lastsubj && !graph) {
401415
const gobj = lastsubj['woql:graph_filter'] || lastsubj['woql:graph']
402-
g = gobj ? gobj['@value'] : false
416+
graph = gobj ? gobj['@value'] : false
417+
}
418+
let cardId = subject + '_' + which + '_' + cardValue
419+
420+
//important!! this add_quad have to stay in this position
421+
//then make the domain of the property into a subclass of the restriction
422+
let classDomain = this._get_object(subject, 'rdfs:domain')
423+
if (classDomain) {
424+
this.and(new WOQLQuery().add_quad(classDomain, 'subClassOf', cardId, graph))
403425
}
404-
let newid = s + '_' + which + '_' + n
405426
this.and(
406427
new WOQLQuery()
407-
.add_quad(newid, 'type', 'owl:Restriction', g)
408-
.add_quad(newid, 'owl:onProperty', s, g),
428+
.add_quad(cardId, 'type', 'owl:Restriction', graph)
429+
.add_quad(cardId, 'owl:onProperty', subject, graph),
430+
)
431+
const cardObj = {min: 'owl:minCardinality', max: 'owl:maxCardinality'}
432+
let cardType = cardObj[which] ? cardObj[which] : 'owl:Cardinality'
433+
434+
this.and(
435+
new WOQLQuery().add_quad(
436+
cardId,
437+
cardType,
438+
{'@value': cardValue, '@type': 'xsd:nonNegativeInteger'},
439+
graph,
440+
),
409441
)
410-
switch (which) {
411-
case 'max':
412-
this.and(
413-
new WOQLQuery().add_quad(
414-
newid,
415-
'owl:maxCardinality',
416-
{'@value': n, '@type': 'xsd:nonNegativeInteger'},
417-
g,
418-
),
419-
)
420-
break
421-
case 'min':
422-
this.and(
423-
new WOQLQuery().add_quad(
424-
newid,
425-
'owl:minCardinality',
426-
{'@value': n, '@type': 'xsd:nonNegativeInteger'},
427-
g,
428-
),
429-
)
430-
break
431-
default:
432-
this.and(
433-
new WOQLQuery().add_quad(
434-
newid,
435-
'owl:cardinality',
436-
{'@value': n, '@type': 'xsd:nonNegativeInteger'},
437-
g,
438-
),
439-
)
440-
}
441-
//then make the domain of the property into a subclass of the restriction
442-
let od = this._get_object(s, 'rdfs:domain')
443-
if (od) {
444-
this.and(new WOQLQuery().add_quad(od, 'subClassOf', newid, g))
445-
}
446442
return this
447443
}
448444

lib/query/woqlCore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ WOQLQuery.prototype.findLastSubject = function(json) {
495495
let ls = this.findLastSubject(json['woql:query'])
496496
if (ls) return ls
497497
}
498+
//check for cardinality here
498499
if (json && json['woql:subject']) {
499500
return json
500501
}

lib/query/woqlLibrary.js

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ WOQLLibrary.prototype.add_multiple = function(client, parts, varlist, clause, ex
11651165
})
11661166
p.and(clause(item, nvarlist, extra))
11671167
})
1168-
console.log("___GET_DB_INFO____",p.prettyPrint())
1168+
//console.log("___GET_DB_INFO____",p.prettyPrint())
11691169
return client.query(p, commit).then(results => {
11701170
let res = []
11711171
if (results && results.bindings && results.bindings.length) {
@@ -1184,7 +1184,7 @@ WOQLLibrary.prototype.add_multiple = function(client, parts, varlist, clause, ex
11841184
})
11851185
}
11861186

1187-
WOQLLibrary.prototype.asset_overview = function(using, v, with_size) {
1187+
WOQLLibrary.prototype.asset_overview = function(using, vars, with_size) {
11881188
let q = new WOQLQuery()
11891189
let commits = using + '/local/_commits'
11901190
let meta = using + '/_meta'
@@ -1209,7 +1209,7 @@ WOQLLibrary.prototype.asset_overview = function(using, v, with_size) {
12091209
NoParent,
12101210
created,
12111211
dbsize,
1212-
] = v
1212+
] = vars
12131213
let cs = []
12141214
cs.push(
12151215
new WOQLQuery()
@@ -1292,7 +1292,8 @@ WOQLLibrary.prototype.assets_overview = function(dbs, client, with_size) {
12921292
dbmeta.organization = dbmeta.organization.substring(1)
12931293
let rec = res[i]
12941294
if (rec) {
1295-
if (rec['branches'] && rec['branches'] != 'system:unknown') {
1295+
formatDBInfo(dbmeta, rec)
1296+
/*if (rec['branches'] && rec['branches'] != 'system:unknown') {
12961297
mbranches = unWindBranches(rec['branches'])
12971298
for (var k in mbranches) {
12981299
dbmeta[k] = mbranches[k]
@@ -1305,14 +1306,65 @@ WOQLLibrary.prototype.assets_overview = function(dbs, client, with_size) {
13051306
if (rec['schema'] && rec['schema'] != 'system:unknown') dbmeta.schema = true
13061307
if (rec['size'] && rec['size']['@value']) dbmeta.size = rec['size']['@value']
13071308
if (rec['prefixes'] && rec['prefixes'] != 'system:unknown')
1308-
dbmeta.prefixes = unWindPrefixes(rec['prefixes'])
1309+
dbmeta.prefixes = unWindPrefixes(rec['prefixes'])*/
13091310
}
13101311
dbmetas.push(dbmeta)
13111312
}
13121313

13131314
return dbmetas
13141315
})
13151316
}
1317+
WOQLLibrary.prototype.assets_overview_result = function(using, dbInfo, client, with_size) {
1318+
const vars = [
1319+
'v:RemoteIRI',
1320+
'v:remote_url',
1321+
'v:AnyCommit',
1322+
'v:schema',
1323+
'v:prefix',
1324+
'v:prefix_URI',
1325+
'v:PrefixPairIRI',
1326+
'v:prefixes',
1327+
'v:BranchIRI',
1328+
'v:branch',
1329+
'v:BranchHeadIRI',
1330+
'v:branch_head',
1331+
'v:branch_time',
1332+
'v:author',
1333+
'v:message',
1334+
'v:branches',
1335+
'v:FirstCommitIRI',
1336+
'v:NoParent',
1337+
'v:created',
1338+
'v:size',
1339+
]
1340+
const wquery = this.asset_overview(using, vars, with_size)
1341+
1342+
return client.query(wquery).then(result => {
1343+
//format the result data
1344+
if (result.bindings && result.bindings.length) {
1345+
return formatDBInfo(dbInfo, result.bindings[0])
1346+
}
1347+
})
1348+
}
1349+
1350+
function formatDBInfo(dbmeta, queryResult) {
1351+
if (queryResult['branches'] && queryResult['branches'] != 'system:unknown') {
1352+
const mbranches = unWindBranches(queryResult['branches'])
1353+
for (var k in mbranches) {
1354+
dbmeta[k] = mbranches[k]
1355+
}
1356+
}
1357+
if (queryResult['created'] && queryResult['created']['@value'])
1358+
dbmeta.created = queryResult['created']['@value']
1359+
if (queryResult['remote_url'] && queryResult['remote_url']['@value'])
1360+
dbmeta.remote_url = queryResult['remote_url']['@value']
1361+
if (queryResult['schema'] && queryResult['schema'] != 'system:unknown') dbmeta.schema = true
1362+
if (queryResult['size'] && queryResult['size']['@value'])
1363+
dbmeta.size = queryResult['size']['@value']
1364+
if (queryResult['prefixes'] && queryResult['prefixes'] != 'system:unknown')
1365+
dbmeta.prefixes = unWindPrefixes(queryResult['prefixes'])
1366+
return dbmeta
1367+
}
13161368

13171369
function unWindPrefixes(prefixes) {
13181370
let prefs = []

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Utils.compareIDs = function(ida, idb) {
138138
*/
139139
Utils.shorten = function(url, prefixes) {
140140
if (!url) return undefined
141-
if(typeof url == "function") return undefined
141+
if (typeof url === 'function') return undefined
142142
prefixes = prefixes || Utils.standard_urls
143143
for (const pref in prefixes) {
144144
if (prefixes[pref] == url.substring(0, prefixes[pref].length)) {

lib/viewer/chartConfig.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ WOQLChartConfig.prototype.prettyPrint = function() {
2727
if (typeof this.layout() != 'undefined') {
2828
str += "view.layout('" + this.layout() + "')\n"
2929
}
30+
if (typeof this.align() != 'undefined') {
31+
str += "view.align('" + this.align() + "')\n"
32+
}
3033

3134
str += this.getBasicPrettyPrint()
3235
return str
@@ -49,6 +52,9 @@ WOQLChartConfig.prototype.json = function() {
4952
if (typeof this.layout() != 'undefined') {
5053
conf['layout'] = this.layout()
5154
}
55+
if (typeof this.align() != 'undefined') {
56+
conf['align'] = this.align()
57+
}
5258

5359
let mj = {chart: conf, rules: this.getRulesJSON()}
5460
return mj
@@ -75,6 +81,9 @@ WOQLChartConfig.prototype.loadJSON = function(config, rules) {
7581
if (typeof config.layout != 'undefined') {
7682
this.layout(config.layout)
7783
}
84+
if (typeof config.align != 'undefined') {
85+
this.align(config.align)
86+
}
7887
}
7988

8089
WOQLChartConfig.prototype.title = function(title) {
@@ -93,14 +102,22 @@ WOQLChartConfig.prototype.description = function(description) {
93102
return this._description
94103
}
95104

96-
//layout "vertical" | "horizontal"
105+
//legend layout "vertical" | "horizontal"
97106
WOQLChartConfig.prototype.layout = function(layout) {
98107
if (layout) {
99108
this._layout = layout
100109
return this
101110
}
102111
return this._layout
103112
}
113+
//legend align'left', 'center', 'right'
114+
WOQLChartConfig.prototype.align = function(align) {
115+
if (align) {
116+
this._align = align
117+
return this
118+
}
119+
return this._align
120+
}
104121
//default is { top: 10, right: 30, left: 0, bottom: 80 }
105122
WOQLChartConfig.prototype.margin = function(marginObj) {
106123
if (marginObj) {
@@ -366,7 +383,8 @@ WOQLChartRule.prototype.customColors = function(colorsObj) {
366383
}
367384

368385
/*
369-
* @param {array} payload array of the object for descrive the legend [{value:"legend label",color:"#ff0000",type:"rect"}]
386+
* @param {array} payload array of the object for descrive the legend
387+
[{value:"legend label",color:"#ff0000",type:"rect","id":'element id'}]
370388
*/
371389

372390
WOQLChartRule.prototype.payload = function(payloadArr) {

0 commit comments

Comments
 (0)