1

我想在文档中查找多标记字符串或短语的频率。它不是我正在寻找的单词/单项频率,它始终是多项,并且术语的数量是动态的......

例如:在文档中搜索“与朋友交流”的频率!

任何帮助/指针将不胜感激。

谢谢德布贾尼

4

2 回答 2

3

您可以使用 Buffered Reader 逐行读取文档,然后使用 split 函数获取 word/token 的频率

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;
于 2011-08-12T10:12:00.523 回答
1

为什么不使用正则表达式?正则表达式针对此类任务进行了优化。

http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Matcher.html

于 2011-08-12T10:17:24.670 回答