Skip to content

Commit

Permalink
small fixes + dynamic min similarity for fuzzysort technique
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixHuberFX committed Apr 11, 2018
1 parent a7c6016 commit 5fbe3e8
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 9 deletions.
3 changes: 2 additions & 1 deletion frontend/src/js/stringComparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

// string comparison used in source code editors (e.g. Sublime Text)
function occurrencesFuzzysort ( string, subStrings ) {
if (minSimilarity > 0) minSimilarity = FUZZY_SORT_MIN_SIMILARITY;
var words = (!!string && string != '') ? string.replace(/([^\w\d\s]+)/g, '').replace(/\s(\s+)/g, ' ').split(/\s/) : [];
var counter = 0;
var occurrences = [];
Expand All @@ -77,7 +78,7 @@
var entryPrepared = fuzzysort.prepare(entry)
subStrings.forEach ( function ( subString ) {
var value = fuzzysort.single(subString, entryPrepared);
if (!!value && value.score >= FUZZY_SORT_MIN_SIMILARITY) {
if (!!value && value.score >= minSimilarity) {
counter++;
var index = -1;
for ( var i = 0; i < occurrences.length; i++ ) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
users.forEach ( function( item ) {
var id = item.id;
var name = item.name;
$('#list').append('<div id="'+ id +'" class="list-group-item"><a href="#" name='+name+' id='+id+' class="list-group-item active">'+name +' <span id="stat_'+ id +'" class="badge">14</span> </a></div>')
$('#list').append('<div id="'+ id +'" class="list-group-item"><a href="javascript:void(0)" name='+name+' id='+id+' class="list-group-item active">'+name +' <span id="stat_'+ id +'" class="badge">14</span> </a></div>')
});
PopulateStats();
})
Expand Down Expand Up @@ -163,7 +163,7 @@
<div class="row">
<div class="col-md-6">
<div id="list" class="list-group">
<span href="#" class="list-group-item active">Reviewer Account:</span>
<span href="javascript:void(0)" class="list-group-item active">Reviewer Account:</span>

</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
dataType: 'json',
contentType:'application/json',
async: true,
data: JSON.stringify({text1: text1, text2: text2}),
data: JSON.stringify({'taxonomy_id': TAXONOMY_ID, text1: text1, text2: text2}),
success: function ( citations ) {
if (!citations) {
handleError('Cannot get papers from DB.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,9 @@ <h1 id="bibModalTitle"></h1><br>
<li style="display:inline-block;"><h4>Paper Import</h4></li>
<li style="display:inline-block;"><div style="padding:10px;"><label for="selectStringComparisonTechnique">String Comparison Technique: </label></div><div><select id="selectStringComparisonTechnique" style="width:100px;" title="String Comparison Technique">
<option title="Exact matching using regular expressions">Regex</option>
<option title="Dice's Coefficient calculates string similarity based on the number of bigrams two words have in common">Dice's Coefficient</option>
<option title="The Levenshtein distance is the minimal number of insertions, deletions and replacements needed for transforming one string into another one">Levenshtein</option>
<option title="SublimeText-like fuzzy search (https://github.com/farzher/fuzzysort)">Fuzzysort</option>
<option title="Dice's Coefficient calculates string similarity based on the number of bigrams two words have in common (value between 0 and 1)">Dice's Coefficient</option>
<option title="The Levenshtein distance is the minimal number of insertions, deletions and replacements needed for transforming one string into another one (value must be a natural number)">Levenshtein</option>
<option title="SublimeText-like fuzzy search (https://github.com/farzher/fuzzysort) (negative value, 0 standing for exact matching)">Fuzzysort</option>
</select></div></li>
<li style="display:inline-block;"><div style="padding:10px;"><label for="importMinSimilarity">Min Similarity: </label></div><div><input type="text" id="importMinSimilarity" value="" style="width:50px;" title="Min similarity"></div></li>
<li style="display:inline-block;"><div style="padding:10px;"><div><label for="importMinOccurrences">Min Occurrences: </label></div><div><input type="text" id="importMinOccurrences" value="1" style="width:50px;" title="Min occurrences"></div></li>
Expand Down
102 changes: 102 additions & 0 deletions frontend/taxonomy/cytoscape/taxonomyRelations.html
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,108 @@ <h1 id="multiselectTitle"></h1><br>
}
}

function testPerformanceAddNode ( nodeName, count, results, timeoutFactor, callback ) {
if (count <= 0) {
callback(results);
return;
}
if (!results) results = [];
var request = {'taxonomy_id': TAXONOMY_ID};
request.x = '';
request.y = '';
request.xMajor = '';
request.yMajor = '';
request.major = 0;
request.dimension = 'Attack view';
var attributeName = 'Test' + nodeName;
request.text = attributeName + '_' + count;
var startTime = window.performance.now();
$.ajax
({
type: "POST",
url: 'addAttribute',
dataType: 'json',
contentType:'application/json',
async: true,
data: JSON.stringify(request),
success: function ( result ) {
if (!result || !result.success) {
handleErrorHelper('Error occurred while adding node.');
return;
}
var endTime = window.performance.now();
results.push(endTime - startTime);
if (count <= 1) callback(results);
else {
setTimeout(function () {
testPerformanceAddNode(nodeName, count-1, results, timeoutFactor, callback);
}, timeoutFactor);
}
}
});
}

function testPerformanceRemoveNode ( nodeName, count, results, timeoutFactor, callback ) {
if (count <= 0) {
callback(results);
return;
}
if (!results) results = [];
var request = {'taxonomy_id': TAXONOMY_ID};
var attributeName = 'Test' + nodeName;
request.text = attributeName + '_' + count;
var startTime = window.performance.now();
$.ajax
({
type: "POST",
url: 'removeAttribute',
dataType: 'json',
contentType:'application/json',
async: true,
data: JSON.stringify(request),
success: function ( result ) {
if (!result || !result.success) {
handleErrorHelper('Error occurred while adding node.');
return;
}
var endTime = window.performance.now();
results.push(endTime - startTime);
if (count <= 1) callback(results);
else {
setTimeout(function () {
testPerformanceRemoveNode(nodeName, count-1, results, timeoutFactor, callback);
}, timeoutFactor);
}
}
});
}

function testPerformance ( funct, nodeName, count, timeoutFactor ) {
funct(nodeName, count, [], timeoutFactor, function ( results ) {
if (!results || results.length == 0) {
handleErrorHelper("Cannot calculate average performance.");
return;
}
results.sort( function ( a, b ) {
return a < b ? -1 : (a == b ? 0 : 1);
});
var lengthIsOdd = results.length % 2 == 1;
var median = 0;
var index = Math.floor(results.length / 2);
if (lengthIsOdd) median = results[index];
else median = (results[index-1] + results[index]) / 2;
var mean = 0;
var standardDeviation = 0;
for ( var i = 0; i < results.length; i++ ) {
mean += results[i];
standardDeviation += Math.pow(results[i] - median, 2);
}
mean /= results.length;
standardDeviation = Math.sqrt(standardDeviation / results.length);
console.log("median: " + median + ", mean: " + mean + ", deviation: " + standardDeviation);
});
}

// add concept node
function addNode ( cy, ele, e, major ) {
cy.elements().trigger('qtiphide');
Expand Down
4 changes: 2 additions & 2 deletions frontend/taxonomy/users/modals.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="modal fade" id="login-modal" class="loginmodal" tabindex="-1" role="dialog" aria-labelledby="loginLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="loginmodal-container">
<span class="close-btn"><a href="#">X</a></span>
<span class="close-btn"><a href="javascript:void(0)">X</a></span>
<h1>Login</h1><br>
<form id="loginForm">
<input type="text" name="email" title="email" placeholder="Email">
Expand All @@ -14,7 +14,7 @@ <h1>Login</h1><br>
<div class="modal fade" id="signup-modal" class="loginmodal" tabindex="-1" role="dialog" aria-labelledby="signupLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="loginmodal-container">
<span class="close-btn"><a href="#">X</a></span>
<span class="close-btn"><a href="javascript:void(0)">X</a></span>
<h1>Register</h1><br>
<form id="signupForm">
<input type="text" name="email" title="email" placeholder="Email">
Expand Down

0 comments on commit 5fbe3e8

Please sign in to comment.