Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreStopWordDictionary.add() 如何持久化 #1356

Closed
1 task done
xiuqiang1995 opened this issue Dec 17, 2019 · 2 comments
Closed
1 task done

CoreStopWordDictionary.add() 如何持久化 #1356

xiuqiang1995 opened this issue Dec 17, 2019 · 2 comments
Labels

Comments

@xiuqiang1995
Copy link

注意事项

请确认下列注意事项:

  • 我已仔细阅读下列文档,都没有找到答案:
  • 我已经通过Googleissue区检索功能搜索了我的问题,也没有找到答案。
  • 我明白开源社区是出于兴趣爱好聚集起来的自由社区,不承担任何责任或义务。我会礼貌发言,向每一个帮助我的人表示感谢。
  • 我在此括号内输入x打钩,代表上述事项确认完毕。

版本号

当前最新版本号是:1.7.5
我使用的版本是:1.7.4

我的问题

CoreStopWordDictionary.add() 如何将停用词写入stopwords.txt?
还是说只能手动修改stopword.txt或者用文件流的方式。

复现问题

步骤

  1. 首先……
  2. 然后……
  3. 接着……

触发代码

  public class DemoStopWord
{
    public static void main(String[] args) throws Exception {
        System.out.println(CoreStopWordDictionary.contains("一起"));
        stopwords();
        add();
        stopwords();
    }

    public static void add() {
        boolean add = CoreStopWordDictionary.add("一起");
        CoreStopWordDictionary.reload();
        System.out.println("add = " + add);
    }
    public static void stopwords() throws Exception {
        String con = "我们一起去逛超市,我们先去城西银泰,我们再去城南银泰。然后我们再一起回家";
        List<String> strings = HanLP.extractKeyword(con, 5);
        System.out.println("strings = " + strings);
    }
}

期望输出

我期望是调用CoreStopWordDictionary.add("一起");后,将停用词"一起"加入停用词词典。然后调用CoreStopWordDictionary.reload();重新加载字典和缓存达到动态修改停用词词典的功能。

false
strings = [一起, 银泰, 城, 再, 西]
add = true
strings = [城, 西, 银泰, 先, 再]

实际输出

CoreStopWordDictionary.add("一起");并没有将“一起”写入停用词词典,只是在内存中。调用CoreStopWordDictionary.reload();以后停用词字典里没有“一起”

false
strings = [一起, 银泰, 城, 再, 西]
add = true
strings = [一起, 银泰, 城, 再, 西]

其他信息

所以说现在还是要手动修改stopword.txt或者是使用文件流的形式来修改对么?那CoreStopWordDictionary.add()和CoreStopWordDictionary.remove()这两个方法应该怎么用?

@hankcs
Copy link
Owner

hankcs commented Dec 18, 2019

目前不支持序列化,你需要遍历 CoreStopWordDictionary.dictionary 存到你想存的地方。

@xiuqiang1995
Copy link
Author

目前不支持序列化,你需要遍历 CoreStopWordDictionary.dictionary 存到你想存的地方。

好的 谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants