-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathElementUtils.js
58 lines (39 loc) · 1.58 KB
/
ElementUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var FacetUtils = require('./FacetUtils');
var ElementGroup = require('../sparql/element/ElementGroup');
var ElementOptional = require('../sparql/element/ElementOptional');
var Path = require('./Path');
var ElementUtils = {
/**
* Creates an element based on the given paths,
* where each path can be considered as mapped to a column in a table
*
*/
createElementTable: function(facetConfig, paths) {
//var facetConceptGenerator = facete.FaceteUtils.createFacetConceptGenerator(this.facetConfig);
//var concept = facetConceptGenerator.createConceptResources(new facete.Path());
var concept = FacetUtils.createConceptResources(facetConfig, new Path(), false);
var rootFacetNode = facetConfig.getRootFacetNode();
var pathElements = paths.map(function(path) {
var facetNode = rootFacetNode.forPath(path);
//console.log('facetNode: ', facetNode);
var e = facetNode.getElements(true);
// TODO On certain constraints affecting the path, we can skip the Optional
var g = new ElementGroup(e);
var r;
if(e.length !== 0) {
r = new ElementOptional(g);
}
else {
r = g;
}
return r;
});
var elements = [];
elements.push.apply(elements, concept.getElements());
elements.push.apply(elements, pathElements);
var tmp = new ElementGroup(elements);
var result = tmp.flatten();
return result;
}
};
module.exports = ElementUtils;