我想使用這個JavaScript代碼:如何從文本中刪除所有停用詞?
var aStopWords = new Array ("a", "the", "blah"...);
(code to make it run, full code can be found here: https://jsfiddle.net/j2kbpdjr/)
// sText is the body of text that the keywords are being extracted from.
// It's being separated into an array of words.
// remove stop words
for (var m = 0; m < aStopWords.length; m++) {
sText = sText.replace(' ' + aStopWords[m] + ' ', ' ');
}
從文本的身體得到的關鍵字。它工作得很好,但是,我遇到的問題是,它似乎只是遍歷並忽略數組aStopWords
中的單詞的一個實例。
所以,如果我有文字的以下機身:
how are you today? Are you well?
我把var aStopWords = new Array("are","well")
的話,好像它會忽略的are
一審,但仍顯示第二are
作爲關鍵字。而它會從關鍵字中完全刪除/忽略well
。
如果有人能夠幫助忽略關鍵字aStopWords
中所有單詞的實例,我將不勝感激。
是您的目標是從文本中刪除單詞列表的每一次出現? –
@ T.J.Crowder,道歉。我已經更新了這個問題。 – Jack
@ ssc-hrep3是的,這是正確的 – Jack