Skip to content

Commit d237494

Browse files
committed
Add filter to knowledge system
1 parent e1dc6b8 commit d237494

File tree

11 files changed

+7110
-34
lines changed

11 files changed

+7110
-34
lines changed

app.js

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ conn.once('open', function() {
6363
app.get('/plugins', pluginsRoute.getJSON);
6464

6565
app.get('/knowledge', knowledgeRoute.index);
66+
app.get('/knowledge/graph', knowledgeRoute.graph);
6667
app.get('/knowledge/user', knowledgeRoute.user);
6768
app.get('/knowledge/bot', knowledgeRoute.bot);
6869
app.get('/knowledge/world', knowledgeRoute.world);

controllers/knowledge.js

+47-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@ module.exports = function(models, bot) {
99
});
1010
},
1111

12+
graph: function(req, res) {
13+
bot.factSystem.db.get({limit: 2000, offset: 0}, function(err, items){
14+
var data1 = items.map(function(el, index){
15+
return el.subject;
16+
});
17+
18+
var data2 = items.map(function(el, index){
19+
return el.object;
20+
});
21+
22+
var data = _.unique(data1.concat(data2));
23+
24+
// Gen IDs
25+
var data3 = [];
26+
data3 = data.map(function(item, index){
27+
return {id:'xx_'+index, name:item};
28+
});
29+
30+
// nodes
31+
var nodes = data3.map(function(item, index){
32+
return {data: item};
33+
});
34+
35+
// Edges
36+
var edges = items.map(function(item, index){
37+
var sourceID, targetID;
38+
for(var i = 0; i < data3.length; i++) {
39+
if (data3[i].name === item.subject) {
40+
sourceID = data3[i].id;
41+
}
42+
}
43+
44+
for(var i = 0; i < data3.length; i++) {
45+
if (data3[i].name === item.object) {
46+
targetID = data3[i].id;
47+
}
48+
}
49+
50+
return { data: { source: sourceID, target: targetID } };
51+
});
52+
53+
res.render('knowledge/graph', {nodes: nodes, edges: edges});
54+
});
55+
},
56+
1257
filter: function(req, res) {
1358
params = {};
1459
for (var x in req.query) {
@@ -18,7 +63,7 @@ module.exports = function(models, bot) {
1863
}
1964

2065
bot.factSystem.db.get(params, function(err, items) {
21-
res.render('knowledge/world', {concepts:items});
66+
res.render('knowledge/world', {concepts:items, params:params});
2267
});
2368
},
2469

@@ -93,7 +138,7 @@ module.exports = function(models, bot) {
93138

94139
world: function(req, res) {
95140
bot.factSystem.db.get({limit: 100, offset: 0}, function(err, items) {
96-
res.render('knowledge/world', {concepts:items});
141+
res.render('knowledge/world', {concepts:items, params: {}});
97142
});
98143
},
99144

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"cookie-parser": "^1.3.3",
2424
"cookie-session": "^1.1.0",
2525
"csurf": "^1.6.6",
26+
"cytoscape": "^2.4.1",
2627
"express": "^4.11.2",
2728
"jade": "^1.9.1",
2829
"method-override": "^2.3.1",

plugins/bot.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ exports.getFavorite = function(thing, cb) {
1515
botfacts.get({subject:'favorite', predicate: cleanThing}, function(err, list) {
1616
if (!_.isEmpty(list)) {
1717
var favThing = Utils.pickItem(list);
18-
var favThing = favThing.object.replace(/_/g, " ");
18+
favThing = favThing.object.replace(/_/g, " ");
1919
cb(null, "My favorite " + thing + " is " + favThing + ".");
2020
} else {
2121
// Quibble can handle this.
2222
cb(null, "");
2323
}
2424
});
25-
}
25+
};

public/css/app.css

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
svg {
2+
width: 100%;
3+
height: 100%;
4+
}
5+
16
.bg-warning, .bg-success {
27
padding:15px;
38
}

0 commit comments

Comments
 (0)