-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (51 loc) · 1.4 KB
/
index.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
58
59
60
61
62
var Core = require('factis-core');
var Group = require('factis-store-group');
var Hexastore = require('factis-store-hexastore');
var Identity = require('factis-store-identity');
var _ = require('lodash');
function Factis() {
this.hexastore = new Hexastore();
this.store = new Group([
this.hexastore,
new Identity()
]);
}
Factis.prototype.add = function(element) {
if (_.isArray(element)) {
var hexastore = this.hexastore;
_.forEach(element, function(x) {
hexastore.add(x.a);
});
} else {
if (element.x == "fact") {
this.hexastore.add(element.a);
} else {
throw new Error('Hexastore can only add facts or arrays of facts');
}
}
};
Factis.prototype.remove = function(element) {
if (_.isArray(element)) {
var hexastore = this.hexastore;
_.forEach(element, function(x) {
hexastore.remove(x.a);
});
} else {
if (element.x == "fact") {
this.hexastore.remove(element.a);
} else {
throw new Error('Hexastore can only remove facts or arrays of facts');
}
}
};
Factis.prototype.query = function(query) {
return Core.query(query, this.store);
};
Factis.prototype.fact = Core.fact;
Factis.prototype.the = Core.the;
Factis.prototype.and = Core.and;
Factis.prototype.or = Core.or;
Factis.prototype.not = Core.not;
Factis.prototype.implies = Core.implies;
Factis.prototype.equivalent = Core.equivalent;
module.exports = Factis;