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