Skip to content

Commit

Permalink
Cleaning unused function and adding line counting
Browse files Browse the repository at this point in the history
Signed-off-by: Alan D. Tse <alandtse@gmail.com>
  • Loading branch information
alandtse committed Jul 23, 2018
1 parent 1e91aca commit bcfa161
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions app/scripts/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ self.onmessage = function(event) {
switch (event.data.command) {
case "process":
//'license':spdxid,'hash':hash, 'selection': selection
//processSelection(event.data["license"], event.data["data"], event.data["selection"]);
break;
case "updatelicenselist":
getSPDXlist(event.data["url"], event.data["selection"]);
break;
case "compare":
files = event.data.list
compareSPDXlist(event.data["selection"], files);
//processSelection(event.data["license"], event.data["data"], event.data["selection"]);
break;
default:
//getSPDXlist(event.data["url"], event.data["selection"]);
Expand Down Expand Up @@ -115,21 +113,26 @@ function compareSPDXlist(selection, licenses) {
for (var spdxid in licenses) {
var data = licenses[spdxid].licenseText
var count = data.length
var locre = data.match(/\r?\n/g)
var loc = (locre ? locre.length: 0);
var locre2 = selection.match(/\r?\n/g)
var loc2 = (locre2 ? locre2.length: 0);
var difference = Math.abs(count2 - count);
var locdiff = Math.abs(loc2 - loc);
var maxLength = Math.max(count, count2);
var lcs = "";//longestCommonSubstring(cleanText(data), cleanText(selection));
if (difference <= maxLength && difference < 1000) {
var distance = Levenshtein.get(cleanText(data), cleanText(selection));
var percentage = ((maxLength - distance) / maxLength * 100).toFixed(1);
console.log(spdxid + " - Levenshtein Distance (clean): " + distance + " (" + percentage + "%)");
console.log(spdxid + " - Levenshtein Distance (clean): " + distance + " (" + percentage + "%)" + " Length Difference: " + difference + " LOC Diff:" + locdiff);
SPDXlist[spdxid] = {
distance: distance,
text: data,
percentage: percentage,
//patterns: result.patterns
}
}else {
console.log(spdxid + " - Length Difference: " + difference);
console.log(spdxid + " - Length Difference: " + difference + " LOC Diff:" + locdiff);
SPDXlist[spdxid] = {
distance: difference,
text: data,
Expand Down Expand Up @@ -158,36 +161,6 @@ function compareSPDXlist(selection, licenses) {
postMessage({"command": "done","result": sortable});
};

function processSelection(spdxid, data, selection) {
var result = processVariables(data); //strip out spdx variables
var data = result.data
var count = data.length
var count2 = selection.length;
var difference = Math.abs(count2 - count);
var maxLength = Math.max(count, count2);
if (difference <= maxLength && difference < 1000) {
var distance = Levenshtein.get(cleanText(data), cleanText(selection));
var percentage = ((maxLength - distance) / maxLength * 100).toFixed(1);
console.log(spdxid + " - Levenshtein Distance (clean): " + distance + " (" + percentage + "%)");
SPDXlist[spdxid] = {
distance: distance,
text: data,
percentage: percentage,
patterns: result.patterns
}
}else {
console.log(spdxid + " - Length Difference: " + difference);
SPDXlist[spdxid] = {
distance: difference,
text: data,
percentage: 0,
patterns: result.patterns
}
}
postMessage({"command": "store", "spdxid":spdxid, "raw":data, "processed":result.data, "patterns": result.patterns});
//resolve(SPDXlist[spdxid])
};

function cleanText(str) {
return str.replace(/\s+/g, ' ').replace(/(\r\n|\n|\r)/gm, ' ');
}
Expand Down

0 comments on commit bcfa161

Please # to comment.