私はこの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
の単語の1つのインスタンスを繰り返して無視するように見えるということです。
だから私は、テキストの次の体がある場合:
how are you today? Are you well?
を私はvar aStopWords = new Array("are","well")
を置くが、それはare
の最初のインスタンスを無視し、まだキーワードとして第2 are
が表示されますようです。それは、キーワードから完全に除外/無視されますが、well
です。
キーワードからaStopWords
の単語のすべてのインスタンスを無視するのに役立つ人は、大変ありがとうございます。
テキストから単語のリストのすべての発生を削除するにはあなたの目標ですか? –
@ T.J.Crowder、Apologies。私は質問を更新しました。 – Jack
@ ssc-hrep3うん、そうだよ – Jack