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

single_char_filter 的作用疑问与在一个用例中的副作用 #370

Closed
Ace-Who opened this issue May 20, 2019 · 3 comments
Closed

single_char_filter 的作用疑问与在一个用例中的副作用 #370

Ace-Who opened this issue May 20, 2019 · 3 comments

Comments

@Ace-Who
Copy link

Ace-Who commented May 20, 2019

作用是什么?

Rime方案制作详解:

single_char_filter 單字過濾器,如加載此組件,則屛敝詞典中的詞組〔僅table_translator有效〕

cangjie5.schema.yaml:

...
engine:
...
  filters:
    - simplifier
    - uniquifier
    - single_char_filter
...

实际使用中,候选中是有词组的,如「屏蔽 sttfk」「詞組 yrvfm」。那么「屏蔽词组」是什么意思呢?

一个用例中的不解现象

之前参考 rime/librime#184 (comment) 在仓颉中实现相同功能。

# cangjie5.custom.yaml
patch:
  translators:
    - punct_translator
    - reverse_lookup_translator
    - table_translator@fixed
    - table_translator
  # 惟独没加这两行
  # engine/filters:
  #  - uniquifier
  fixed:
    __include: cangjie5.schema:/translator
    enable_user_dict: true
    enable_encoder: true
    initial_quality: 1000
    disable_user_dict_for_patterns:
      - '.*'

结果有不少情况下——但又不是全部——候选出现重复。比如「复 oahe」「情 pqmb」「况 imrhu」「全部 ogyrl」和自造词。将 single_char_filter 移除,或将 uniquifier 移至末尾,就没有这个现象了。根据 RimeWithSchemata,看不出有何必要将 uniquifier 放在 single_char_filter 之后,也不明白为何 cangjie5.schema.yaml 又不是这样做的。

@nameoverflow
Copy link
Member

single_char_filter 是把单字提到最前,并不是屏蔽词组。

@Ace-Who
Copy link
Author

Ace-Who commented May 20, 2019

@nameoverflow 谢谢,我在 http://rimeime.github.io/release/squirrel/ 也看到这个解释。第二个问题是怎么回事呢?

@ZenLian
Copy link

ZenLian commented Apr 27, 2023

如果想只打单字而完全不显示词组,可以用 lua 自定义过滤器。贴一下我刚摸索到的方法,可在词组和单字模式间切换,供参考:

-- rime.lua
function single_char_filter(input, env)
  on = env.engine.context:get_option("single_char")
  for cand in input:iter() do
    if not on or utf8.len(cand.text) == 1 then
      yield(cand)
    end
  end
end
# wubi86.custom.yaml
patch:
  switches/+:
    - name: single_char
      states: [词组, 单字]
      reset: 1
  engine/filters/+:
    - lua_filter@single_char_filter

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

No branches or pull requests

3 participants