Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while building hash map in TagPies.js for certain key terms #2

Open
idea-launch-lab opened this issue Nov 5, 2015 · 0 comments

Comments

@idea-launch-lab
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant