mirror of
https://github.com/gchq/CyberChef
synced 2025-01-01 07:18:47 +00:00
Improving efficency of RAKE
This commit is contained in:
parent
c4e7c41a6e
commit
81e1abd682
1 changed files with 10 additions and 15 deletions
|
@ -101,22 +101,17 @@ class RAKE extends Operation {
|
|||
phrases = phrases.filter(subArray => subArray.length > 0);
|
||||
|
||||
// Remove duplicate phrases
|
||||
const uniquePhrases = [...new Set(phrases.map(function (phrase) {
|
||||
return phrase.join(" ");
|
||||
}))];
|
||||
phrases = uniquePhrases.map(function (phrase) {
|
||||
return phrase.split(" ");
|
||||
});
|
||||
|
||||
phrases = phrases.unique();
|
||||
|
||||
// Generate word_degree_matrix and populate
|
||||
const wordDegreeMatrix = Array.from(Array(tokens.length), _ => Array(tokens.length).fill(0));
|
||||
phrases.forEach(function (phrase) {
|
||||
phrase.forEach(function (word1) {
|
||||
phrase.forEach(function (word2) {
|
||||
wordDegreeMatrix[tokens.indexOf(word1)][tokens.indexOf(word2)]++;
|
||||
});
|
||||
});
|
||||
});
|
||||
const wordDegreeMatrix = Array(tokens.length).fill().map(() => Array(tokens.length).fill(0));
|
||||
for (let p=0; p < phrases.length; p++) {
|
||||
for (let w1=0; w1 < phrases[p].length; w1++) {
|
||||
for (let w2=0; w2 < phrases[p].length; w2++) {
|
||||
wordDegreeMatrix[tokens.indexOf(phrases[p][w1])][tokens.indexOf(phrases[p][w2])]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate degree score for each token
|
||||
const degreeScores = Array(tokens.length).fill(0);
|
||||
|
|
Loading…
Reference in a new issue