Skip to content

Commit

Permalink
Add pyim-candidates-xingma-words-function custom, see #449
Browse files Browse the repository at this point in the history
  • Loading branch information
tumashu committed Sep 8, 2023
1 parent 41c1766 commit 81459f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ Emacs启动后 "M-x toggle-input-method" 或按 "C-\\" 打开输入法。
(setq pyim-enable-shortcode nil)
#+end_example

** 形码输入法如何微调候选词序

#+begin_example
(setq pyim-candidates-xingma-words-function #'my-func)
#+end_example

** 如何将个人词条相关信息导入和导出?

1. 导入使用命令: pyim-dcache-import
Expand Down
18 changes: 15 additions & 3 deletions pyim-candidates.el
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
这个功能很好用,但偶尔会导致 pyim 卡顿。"
:type 'boolean)

(defcustom pyim-candidates-xingma-words-function
#'pyim-candidates-xingma-words-default
"形码输入法候选词列表生成函数。
如果形码输入法用户需要微调候选词词频,可以自定义这个函数。"
:type 'function)

;; ** 获取备选词列表
(defun pyim-candidates--sort (candidates)
"对 CANDIDATES 进行排序。"
Expand Down Expand Up @@ -97,20 +104,25 @@
(when other-codes
(setq prefix (mapconcat
(lambda (code)
(car (pyim-candidates--xingma-words code)))
(car (pyim-candidates-xingma-words code)))
other-codes "")))

;; 5. output => 工子又 工子叕
(setq output
(mapcar (lambda (word)
(concat prefix word))
(pyim-candidates--xingma-words last-code)))
(pyim-candidates-xingma-words last-code)))
(setq output (remove "" (or output (list prefix))))
(setq result (append result output))))
(when (car result)
(delete-dups result))))

(defun pyim-candidates--xingma-words (code)
(defun pyim-candidates-xingma-words (code)
"搜索形码 CODE, 得到相应的词条列表。"
(and (functionp pyim-candidates-xingma-words-function)
(funcall pyim-candidates-xingma-words-function code)))

(defun pyim-candidates-xingma-words-default (code)
"搜索形码 CODE, 得到相应的词条列表。
当前的词条的构建规则是:
Expand Down

0 comments on commit 81459f2

Please sign in to comment.