branch: externals/pyim commit 77d7fdb31f75a1245dbeda2909fabf70bfc70064 Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
造词时,使用 entered 来进一步矫正多音字 * pyim.el (pyim-create-pyim-word): 使用 entered 来进一步矫正多音字。 * pyim-cstring.el (pyim-cstring-to-codes): 使用 entered 来进一步矫正多音字。 --- pyim-cstring.el | 13 +++++++++++-- pyim.el | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pyim-cstring.el b/pyim-cstring.el index 73a3880..a5acb30 100644 --- a/pyim-cstring.el +++ b/pyim-cstring.el @@ -350,13 +350,22 @@ code-prefix)。当RETURN-LIST 设置为 t 时,返回一个 code list。" (substring s4 0 1)))))) (t nil)))) -(defun pyim-cstring-to-codes (string scheme-name) +(defun pyim-cstring-to-codes (string scheme-name &optional entered) "将 STRING 转换为 SCHEME-NAME 对应的 codes." (let ((class (pyim-scheme-get-option scheme-name :class))) (cond ((eq class 'xingma) (pyim-cstring-to-xingma string scheme-name t)) ;;拼音使用了多音字校正 - (t (pyim-cstring-to-pinyin string nil "-" t nil t))))) + (t (let* ((entered (or entered "")) + (codes (pyim-cstring-to-pinyin string nil "-" t nil t)) + (codes-sorted + (sort codes + (lambda (a b) + (< (string-distance a entered) + (string-distance b entered)))))) + ;; 将 code 与用户输入 entered 比对,选取一个与用户输入最类似的 + ;; code. 这种处理方式适合拼音输入法。 + (list (car codes-sorted))))))) ;; ** 获取光标处中文字符串或者中文词条的功能 (defun pyim-cstring-at-point (&optional number) diff --git a/pyim.el b/pyim.el index 63f77c9..e700df2 100644 --- a/pyim.el +++ b/pyim.el @@ -465,8 +465,9 @@ BUG:拼音无法有效地处理多音字。" (setq pyim-last-created-word word) (let* ((scheme-name (pyim-scheme-name)) (class (pyim-scheme-get-option scheme-name :class)) + (entered (pyim-entered-get 'point-before)) (code-prefix (pyim-scheme-get-option scheme-name :code-prefix)) - (codes (pyim-cstring-to-codes word scheme-name))) + (codes (pyim-cstring-to-codes word scheme-name entered))) ;; 保存对应词条的词频 (when (> (length word) 0) (pyim-dcache-update-iword2count word prepend wordcount-handler))