如何从文档文本中过滤常用词? (哈希图)

How to filter commonly used words from document text? (Hash Maps)

感谢您的阅读。我目前有一个我真正坚持的学校项目。目的是从网络中检索文档文本,然后将每个单词存储到地图对象中,同时省略 "which, about, during, after," 等常用单词

基本上可以归结为:

//要忽略的单词列表

    Set<String> ignore = new HashSet<>(Arrays.asList(new String[]{
  "after", "which", "later", "other", "during", "their", "about"}));

//将遍历文档文本(内容)以查找符合的词 到 word_pattern(为了简单起见,假设单词将有 5 个或更多字母)

Matcher match = Pattern.compile(word_pattern).matcher(content);
while (match.find()) {
   String word = match.group().toLowerCase();

所以现在在这个 while 循环中,我希望跳过忽略集中的任何单词,否则将其添加到地图对象...但我似乎无法正确处理,似乎没有任何内容适合我。我可以轻松地将所有单词添加到地图对象并扣除一些分数,但为了我的理智,我希望能够做到这一点。

您的忽略词列表是一种 Set which offer the contains 方法,因此您 可以简单地在你的循环中添加这个条件:

if(!ignore.contains(word))
{
    //addToList
}