HanLP icon indicating copy to clipboard operation
HanLP copied to clipboard

python 词共现统计 Occurrence 如何停用 CustomDictionary

Open yesseecity opened this issue 9 years ago • 3 comments

和 DemoOccurrence 結果不同 同樣都是用 在计算机音视频和图形图像技术等二维信息算法处理方面目前比较先进的视频处理算法

Demo 的 uniGram 結果 [信息=信息=1, 先进=先进=1, 图形图像=图形图像=1, 处理=处理=2, 技术=技术=1, 方面=方面=1, 比较=比较=1, 目前=目前=1, 算法=算法=2, 视频=视频=1, 计算机=计算机=1, 音视频=音视频=1]

我的結果 [先进=先进=1, 图形图像=图形图像=1, 处理=处理=2, 技术=技术=1, 比较=比较=1]

因為我的自訂詞典中

[在/p, 计算机/product, 音视频/product, 和/cc, 图形图像/nz, 技术/keyword, 等/udeng, 二/m, 维/b, 信息/product, 算法/product, 处理/keyword, 方面/product, 目前/product, 比较/keyword, 先进/a, 的/ude1, 视频/product, 处理/keyword, 算法/product]

CRF有停用自訂詞典的功能 CRFSegment().enableCustomDictionary(false);

我要如何在 使用 occurrence 時停用 CustomDictionary ?


另外,自訂字詞我是用 LexiconUtility.setAttribute 去加詞,因為我加的詞含有 space

yesseecity avatar Mar 15 '17 07:03 yesseecity

可以通过com.hankcs.hanlp.corpus.occurrence.Occurrence#addAll(java.util.List<com.hankcs.hanlp.seg.common.Term>)加入提前过滤了停用词的单词列表。

hankcs avatar Mar 20 '17 01:03 hankcs

這樣子? JClass('com.hankcs.hanlp.corpus.occurrence.Occurrence#addAll')

系統報錯 java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.hankcs.hanlp.corpus.occurrence.Occurrence#addAll not found

yesseecity avatar Mar 20 '17 03:03 yesseecity

不是的,这是个非静态方法,直接在对象上调用即可。我用这种方式告诉你具体路径而已。

hankcs avatar Mar 24 '17 14:03 hankcs