Ranking the sentences
Using our word stems from the last section, we will give some scores to our sentences
const ranked = [];
for (index in sentences) {
const sentence = sentences[index];
let baseScore = sentences.length - index;
score = sentence
.split(' ')
.map((word) => {
const cleanedWord = word.match(/([a-zA-Z]+)/);
return cleanedWord && cleanedWord[0]; // remove any punctuation
})
.filter((word) => {
return word && !stopwords.includes(word); // make sure it isn't a stopword or null
})
.reduce((acc, curr) => {
return acc + stems[curr];
}, baseScore);
ranked.push({
sentance,
score,
});
}
Last updated