-
Notifications
You must be signed in to change notification settings - Fork 1
Error while building hash map in TagPies.js for certain key terms #2
Copy link
Copy link
Open
Description
While testing TagPies with a document corpus I found that building the hash map prioHash in TagPies.js file can have issues when word.key conflicts with JavaScript standard attributes for Array object.
In code below when word.key = "length" or one of the other JS attributes for arrays (like 'map', 'slice', etc.) then the line if(typeof prioHash[word.key] == "undefined") returns false even though the key is not present in prioHash, resulting in error in the subsequent line prioHash[word.key].push(word);
My first and rather basic solution is to create a list of possible conflict terms and catch them before testing the hash map. I modify the terms by adding a space at end to avoid the conflict.
// var problemTerms = ['length', 'map', 'filter', 'slice', 'sort'];
for(var i = 0; i < tags1.length; i++) {
var word = tags1[i];
globalHash[word.id] = word;
//if (problemTerms.indexOf (word.key) > -1) {
// word.key += ' ';
// //console.log ("!!! problem term: " + word.key);
//}
if(typeof prioHash[word.key] == "undefined") {
prioHash[word.key] = [];
freqHash[word.key] = 0;
}
prioHash[word.key].push(word); // Error here if word.key is one from problemTerms
freqHash[word.key] += word.value;
if(word.value > maxFreq) {
maxFreq = word.value;
}
if(word.value < minFreq) {
minFreq = word.value;
}
}
Thanks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels