Validation, keyword normalization
This commit is contained in:
parent
2bced5158a
commit
8c1279f1ec
@ -116,6 +116,11 @@
|
|||||||
|
|
||||||
$('#search').click(onSearch);
|
$('#search').click(onSearch);
|
||||||
|
|
||||||
|
$('#learnDlg').on('show.bs.modal', function() {
|
||||||
|
$('#learn').prop('disabled', true);
|
||||||
|
$('#keyword').val('');
|
||||||
|
});
|
||||||
|
|
||||||
$('#learn').click(onLearn);
|
$('#learn').click(onLearn);
|
||||||
$('#keyword').bind('input', function() {
|
$('#keyword').bind('input', function() {
|
||||||
$('#learn').prop('disabled', !$(this).val());
|
$('#learn').prop('disabled', !$(this).val());
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade options-dlg" tabindex="-1">
|
<div class="modal fade" id="optionsDlg" tabindex="-1">
|
||||||
<div class="modal-dialog modal-sm">
|
<div class="modal-dialog modal-sm">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header"><big>Visualization Options</big></div>
|
<div class="modal-header"><big>Visualization Options</big></div>
|
||||||
@ -74,15 +74,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade learn-dlg" tabindex="-1">
|
<div class="modal fade" id="learnDlg" tabindex="-1">
|
||||||
<div class="modal-dialog modal-sm">
|
<div class="modal-dialog modal-sm">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header"><big>Learn Keyword</big></div>
|
<div class="modal-header"><big>Learn Keyword</big></div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="form-horizontal">
|
<div class="form-horizontal">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="keyword" class="col-md-2 control-label">Name</label>
|
<label for="keyword" class="col-md-4 control-label">Learn as</label>
|
||||||
<div class="col-md-10">
|
<div class="col-md-8">
|
||||||
<input class="form-control" type="text" id="keyword" name="keyword">
|
<input class="form-control" type="text" id="keyword" name="keyword">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -103,8 +103,8 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<big>Semantic tweaks to <span id="query" class="text-primary"></span></big>
|
<big>Semantic tweaks to <span id="query" class="text-primary"></span></big>
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
<button class="btn btn-xs btn-success" data-toggle="modal" data-target=".learn-dlg">Learn...</button>
|
<button class="btn btn-xs btn-success" data-toggle="modal" data-target="#learnDlg">Learn...</button>
|
||||||
<button class="btn btn-xs btn-default" data-toggle="modal" data-target=".options-dlg">Options...</button>
|
<button class="btn btn-xs btn-default" data-toggle="modal" data-target="#optionsDlg">Options...</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding: 10px;" class="unselectable">
|
<div style="padding: 10px;" class="unselectable">
|
||||||
|
@ -25,18 +25,7 @@ function scale(values, factor) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalize(values) {
|
function add(values1, values2) {
|
||||||
var result = {};
|
|
||||||
|
|
||||||
for (var feature in values) {
|
|
||||||
var value = values[feature];
|
|
||||||
result[feature] = Math.max(-1.0, Math.min(1.0, value), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function combine(values1, values2) {
|
|
||||||
var result = {};
|
var result = {};
|
||||||
|
|
||||||
for (var feature in values1) {
|
for (var feature in values1) {
|
||||||
@ -157,26 +146,20 @@ function addKeyword(query, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getKeywords(function(keywords) {
|
getKeywords(function(keywords) {
|
||||||
var result = {
|
var result = {};
|
||||||
food: 0.0,
|
|
||||||
service: 0.0,
|
|
||||||
value: 0.0,
|
|
||||||
atmosphere: 0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var param in query.params) {
|
for (var param in query.params) {
|
||||||
var features = scale(keywords[param], query.params[param]);
|
var features = scale(keywords[param], query.params[param]);
|
||||||
result = combine(result, features);
|
result = add(result, features);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = normalize(result);
|
result = scale(result, 1.0 / _.keys(query.params).length);
|
||||||
|
|
||||||
var values = [
|
var values = [
|
||||||
query.keyword,
|
query.keyword,
|
||||||
result.food,
|
result.food || 0.0,
|
||||||
result.service,
|
result.service || 0.0,
|
||||||
result.value,
|
result.value || 0.0,
|
||||||
result.atmosphere
|
result.atmosphere || 0.0
|
||||||
];
|
];
|
||||||
|
|
||||||
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
connection.query('INSERT INTO keywords VALUES(?, ?, ?, ?, ?)', values, function(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user