Skip to content

ViterbiSegment 自定义 CustomDictionaryForcing 时启用 enableCustomDictionaryForcing 不生效 #1712

@XhstormR

Description

@XhstormR

Describe the bug
ViterbiSegment 使用 DynamicCustomDictionary 时,同时启用 enableCustomDictionaryForcing 不生效。

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

val dictionary = DynamicCustomDictionary()
dictionary.insert("fuck", "ZH_CN_COMMON")

val segment = ViterbiSegment()
    .enableCustomDictionaryForcing(true)
    .enableCustomDictionary(dictionary)
val text = "fucking,fuckkkkkk,fuck123"

//自定义Dictionary未生效
println(segment.seg(text))

//全局Dictionary才会生效
CustomDictionary.add("fuck")
println(segment.seg(text))

输出:
[fucking/nx, ,/w, fuckkkkkk/nx, ,/w, fuck/ZH_CN_COMMON, 123/m]
[fuck/ZH_CN_COMMON, ing/nx, ,/w, fuck/ZH_CN_COMMON, kkkkk/nx, ,/w, fuck/ZH_CN_COMMON, 123/m]

Describe the current behavior
自定义DynamicCustomDictionary不生效,使用全局的CustomDictionary才会生效。

Expected behavior
自定义DynamicCustomDictionary生效。

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):MacOS
  • Python version:
  • HanLP version: image

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

  • I've completed this form and searched the web for solutions.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions