[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 7bc274f153: Fix: 候选词丢失bug(有复现步骤) #445
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 7bc274f153: Fix: 候选词丢失bug(有复现步骤) #445 |
Date: |
Thu, 16 Jun 2022 18:57:50 -0400 (EDT) |
branch: externals/pyim
commit 7bc274f1534598ec57a977f252be80e9088a3697
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Fix: 候选词丢失bug(有复现步骤) #445
---
pyim-candidates.el | 42 ++++++++++++++++++++++++------------------
tests/pyim-tests.el | 17 +++++++++++------
2 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/pyim-candidates.el b/pyim-candidates.el
index fce9bf2f41..9664bced47 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -211,20 +211,18 @@
(push (delete-dups (append w2 w1)) jianpin-words)))
(pyim-zip (nreverse jianpin-words) fast-search))))
-(defun pyim-candidates-dcache-quanpin-words (imobjs scheme &optional
fast-search pymap-chars-num)
+(defun pyim-candidates-dcache-quanpin-words (imobjs scheme &optional
fast-search char-num)
"从 dcache 获取个人词条,词库词条和第一汉字列表。"
(let (personal-words common-words pinyin-chars-1 pinyin-chars-2)
(dolist (imobj imobjs)
(let* ((w1 (pyim-candidates-quanpin-personal-words imobj scheme))
(w2 (pyim-candidates-quanpin-common-words imobj scheme))
;; 第一个汉字
- (w3 (pyim-candidates-quanpin-chars imobj scheme))
+ (w3 (pyim-candidates-quanpin-chars imobj scheme char-num))
;; 如果 w3 找不到第一个拼音对应的汉字,那就进一步使用
;; `pyim-pymap-py2cchar-get' 来查找,这个函数支持声母搜索。可以得到
;; 更多的词条。
- (w4 (unless w3
- (pyim-candidates-pymap-chars
- (car (pyim-codes-create imobj scheme)) pymap-chars-num))))
+ (w4 (unless w3 (pyim-candidates-pymap-chars imobj scheme
char-num))))
(push w1 personal-words)
(push w2 common-words)
(push w3 pinyin-chars-1)
@@ -249,21 +247,29 @@
'(code2word shortcode2word)
'(code2word))))
-(defun pyim-candidates-quanpin-chars (imobj scheme)
- (pyim-dcache-get
- (car (pyim-codes-create imobj scheme))
- '(icode2word code2word)))
+(defun pyim-candidates-quanpin-chars (imobj scheme &optional num)
+ (let* ((code (car (pyim-codes-create imobj scheme)))
+ (chars (delete-dups
+ `(,@(pyim-dcache-get code '(icode2word code2word))
+ ,@(pyim-pymap-py2cchar-get code t t))))
+ (num (when (numberp num)
+ (min num (length chars)))))
+ (cl-subseq chars 0 num)))
-(defun pyim-candidates-pymap-chars (pinyin &optional num)
+(defun pyim-candidates-pymap-chars (imobj scheme &optional num)
"从 pymap 表获取汉字。"
- (let ((chars (mapcar #'char-to-string
- (pyim-zip
- (mapcar (lambda (x)
- ;; NOTE: 这里只取最常用的汉字,太多的汉字会带
- ;; 来后续处理压力,可能拖慢输入法。不过这个结
- ;; 论只是猜测。
- (car (split-string x "|")))
- (pyim-pymap-py2cchar-get pinyin))))))
+ (let* ((pinyin (car (pyim-codes-create imobj scheme)))
+ (chars (mapcar #'char-to-string
+ (pyim-zip
+ (mapcar (lambda (x)
+ ;; NOTE: 这里只取最常用的汉字,太多的汉字会带
+ ;; 来后续处理压力,可能拖慢输入法。不过这个结
+ ;; 论只是猜测。
+ (car (split-string x "|")))
+ (pyim-pymap-py2cchar-get
+ pinyin (> (length imobj) 1))))))
+ (num (when (numberp num)
+ (min num (length chars)))))
(cl-subseq chars 0 num)))
(cl-defgeneric pyim-candidates-create-limit-time (_imobjs _scheme)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index e046548e84..a40b52d6db 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -585,9 +585,9 @@
(should (equal (pyim-candidates-dcache-quanpin-words imobjs1 quanpin nil
10)
'(("你" "您" "妮") nil nil ("南" "乃" "囊" "脑" "呢" "内" "嫩" "能"
"你" "年"))))
(should (equal (pyim-candidates-dcache-quanpin-words imobjs2 quanpin nil
10)
- '(("你" "尼") ("尼" "你") ("你" "尼" "尼" "你") nil)))
+ '(("你" "尼") ("尼" "你") ("你" "尼" "呢" "泥" "拟" "逆" "倪" "妮" "腻"
"匿") nil)))
(should (equal (pyim-candidates-dcache-quanpin-words imobjs3 quanpin nil
10)
- '(("你好" "尼耗" "呢耗") ("你好" "尼耗") ("你好" "尼耗" "呢耗" "你好" "尼耗")
nil)))))
+ '(("你好" "尼耗" "呢耗") ("你好" "尼耗") ("你好" "尼耗" "呢耗") nil)))))
(ert-deftest pyim-tests-pyim-candidates-quanpin-personal-words ()
(let* ((pyim-dhashcache-icode2word (make-hash-table :test #'equal))
@@ -632,12 +632,17 @@
(imobjs (pyim-imobjs-create "nihao" quanpin)))
(puthash "ni" (list "你" "呢") pyim-dhashcache-icode2word)
(puthash "ni" (list "你" "尼") pyim-dhashcache-code2word)
- (should (equal (pyim-candidates-quanpin-chars (car imobjs) quanpin)
- '("你" "呢" "你" "尼")))))
+ (should (equal (pyim-candidates-quanpin-chars (car imobjs) quanpin 10)
+ '("你" "呢" "尼" "泥" "拟" "逆" "倪" "妮" "腻" "匿")))))
(ert-deftest pyim-tests-pyim-candidates-pymap-chars ()
- (should (equal (pyim-candidates-pymap-chars "ni" 10)
- '("你" "年" "娘" "鸟" "摄" "您" "宁" "牛" "尼" "念"))))
+ (let* ((quanpin (pyim-scheme-get 'quanpin))
+ (imobjs1 (pyim-imobjs-create "ni" quanpin))
+ (imobjs2 (pyim-imobjs-create "nihao" quanpin)))
+ (should (equal (pyim-candidates-pymap-chars (car imobjs1) quanpin 10)
+ '("你" "年" "娘" "鸟" "摄" "您" "宁" "牛" "尼" "念")))
+ (should (equal (pyim-candidates-pymap-chars (car imobjs2) quanpin 10)
+ '("你" "尼" "呢" "泥" "拟" "逆" "倪" "妮" "腻" "匿")))))
(ert-deftest pyim-tests-pyim-candidates-search-buffer ()
(with-temp-buffer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/pyim 7bc274f153: Fix: 候选词丢失bug(有复现步骤) #445,
ELPA Syncer <=