-
Notifications
You must be signed in to change notification settings - Fork 5
/
TripleUtils.js
50 lines (40 loc) · 1.09 KB
/
TripleUtils.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
var uniq = require('lodash.uniq');
var NodeUtils = require('./NodeUtils');
var TripleUtils = {
uniqTriples: function(triples) {
var result = uniq(triples, false, function(x) {
return x.toString();
});
return result;
},
matches: function(tripleMatch, triple) {
var ps = tripleMatch.toArray();
var cs = triple.toArray();
var result = true;
for(var i = 0; i < 3; ++i) {
var p = ps[i];
var c = cs[i];
var t = NodeUtils.matches(p, c);
if(!t) {
result = false;
break;
}
}
return result;
},
getNodeAt: function(triple, index) {
if(triple == null) {
index = null;
}
var result;
switch(index) {
case 0: result = triple.getSubject(); break;
case 1: result = triple.getPredicate(); break;
case 2: result = triple.getObject(); break;
default:
result = null;
}
return result;
},
};
module.exports = TripleUtils;