ドキュメント内の複数のトークン文字列またはフレーズの頻度を調べたい。それは私が探している単語/単一用語の頻度ではなく、常に複数用語であり、用語の数は動的です...
例:ドキュメント内の「友達との単語」の頻度を検索する!
ヘルプ/ポインタは大歓迎です。
ありがとうDebjani
Buffered Reader を使用してドキュメントを 1 行ずつ読み取り、分割機能を使用して単語/トークンの頻度を取得できます。
int count=0;
while ((strLine = br.readLine()) != null) {
count+ = (strLine.split("words with friends").length-1);
}
return count;
編集:大文字と小文字を区別しない検索を実行する場合は、次を使用できます
Pattern myPattern = Pattern.compile("words with friends", Pattern.CASE_INSENSITIVE);
int count=0;
while ((strLine = br.readLine()) != null) {
count+ = (myPattern.split(strLine).length-1);
}
return count;
正規表現を使用してみませんか?正規表現は、この種のタスク用に最適化されています。
http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Matcher.html