Improving efficency of RAKE

This commit is contained in:
sw5678 2024-03-11 16:57:28 +00:00
parent c4e7c41a6e
commit 81e1abd682

View file

@ -101,22 +101,17 @@ class RAKE extends Operation {
phrases = phrases.filter(subArray => subArray.length > 0); phrases = phrases.filter(subArray => subArray.length > 0);
// Remove duplicate phrases // Remove duplicate phrases
const uniquePhrases = [...new Set(phrases.map(function (phrase) { phrases = phrases.unique();
return phrase.join(" ");
}))];
phrases = uniquePhrases.map(function (phrase) {
return phrase.split(" ");
});
// Generate word_degree_matrix and populate // Generate word_degree_matrix and populate
const wordDegreeMatrix = Array.from(Array(tokens.length), _ => Array(tokens.length).fill(0)); const wordDegreeMatrix = Array(tokens.length).fill().map(() => Array(tokens.length).fill(0));
phrases.forEach(function (phrase) { for (let p=0; p < phrases.length; p++) {
phrase.forEach(function (word1) { for (let w1=0; w1 < phrases[p].length; w1++) {
phrase.forEach(function (word2) { for (let w2=0; w2 < phrases[p].length; w2++) {
wordDegreeMatrix[tokens.indexOf(word1)][tokens.indexOf(word2)]++; wordDegreeMatrix[tokens.indexOf(phrases[p][w1])][tokens.indexOf(phrases[p][w2])]++;
}); }
}); }
}); }
// Calculate degree score for each token // Calculate degree score for each token
const degreeScores = Array(tokens.length).fill(0); const degreeScores = Array(tokens.length).fill(0);