1

Can now learn keywords

This commit is contained in:
Alex Yatskov 2014-11-08 23:23:56 +09:00
parent dc67e4848c
commit 1225d605c3
3 changed files with 39 additions and 26 deletions

View File

@ -20,7 +20,7 @@
<div class="panel-heading">
<big>Visualizer</big>
<div class="pull-right">
<button class="btn btn-xs btn-default">Learn</button>
<button class="btn btn-xs btn-default" id="learn">Learn</button>
</div>
</div>
<div class="panel-body">

View File

@ -66,6 +66,27 @@
});
$('#historyIndex').on('slideStop', onSelectSnapshot);
$('#learn').click(function() {
var keyword = prompt('Input keyword to learn as');
if (name === null) {
return;
}
var query = {
keyword: keyword,
features: _ctx.query.features
};
$.getJSON('/add_keyword', query, function(results) {
if (results.success) {
}
else {
alert('Failed to learn keyword');
}
});
});
});
}

View File

@ -133,32 +133,24 @@ function loadDb(params) {
}
function addKeyword(query, callback) {
// var keyword = (query.keyword || '').toLowerCase();
// if (!/^[a-zA-Z0-9]+$/.test(keyword)) {
// callback({
// keyword: keyword,
// success: false
// });
// }
// else {
// getKeywords(function(keywords) {
// var features = combine(keywords, query.params);
// var values = [
// keyword,
// features.food || 0.0,
// features.service || 0.0,
// features.value || 0.0,
// features.atmosphere || 0.0
// ];
if (!/^[a-zA-Z0-9]+$/.test(query.keyword)) {
callback({ keyword: query.keyword, success: false });
return;
}
// pool.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
// callback({
// keyword: keyword,
// success: err === null
// });
// });
// });
// }
getKeywords(function(keywords) {
var values = [
query.keyword,
query.features.food,
query.features.service,
query.features.value,
query.features.atmosphere
];
pool.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
callback({ keyword: query.keyword, success: err === null });
});
});
}
function removeKeyword(query, callback) {