-1

外部ライブラリを使用したくありませんが、独自のストップワードの削除を開始する方法の手がかりがあるかどうか疑問に思います.HashSetを作成した後、テキストのストップワードを削除するためにどのように機能させることができますか?一度繰り返しますが、外部ライブラリを使用したくありません。

4

3 に答える 3

2

私はそれらをファイルから読みます。単語ごとに1行。

Set<String> stopWords = new LinkedHashSet<String>();
BufferedReader br = new BufferedReader(new FileReader("stop-words.txt"));
for(String line;(line = br.readLine()) != null;)
   stopWords.add(line.trim());
br.close();

if(stopWords.contains(word))
   // it's a stop word
else
   // it's not a stop word.
于 2011-12-08T10:33:47.933 に答える
1

ストップ ワードのセットと、ストップ ワードを削除したい単語のリストがある場合は、リストを反復処理して、ストップ ワード セットに含まれるすべての単語を削除します。

Set<String> stopWords = new HashSet<String>(  );
//fill stopWords

//use a linked list to make removal faster, you don't need random access here
List<String> text = new LinkedList<String>(  ); 
//fill text

Iterator<String> textIterator = text.iterator();
while( textIterator.hasNext() ) {
  //this assumes there are no null entries in the list       
  //and all stopwords are stored in lower case
  if( stopWords.contains( textIterator.next().toLowerCase() )) {
    textIterator.remove();
  }
}
于 2011-12-08T10:47:58.987 に答える
0

単語の削除を停止する方法の一般的な考え方は、入力テキストを単語に分割し、ストップワード マップ内の各単語を検索することです。ストップワード検索では、大文字と小文字を区別しない必要があります。

詳細は、テキストの内容とその内容によって異なります。

于 2011-12-08T10:48:20.760 に答える