[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 367aecd1f8 2/4: pyim-candidates-dcache-quanpin-wor
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 367aecd1f8 2/4: pyim-candidates-dcache-quanpin-words remove char-num arg. |
Date: |
Mon, 20 Jun 2022 21:58:02 -0400 (EDT) |
branch: externals/pyim
commit 367aecd1f8876fdce3f48f88107685bdcdd7e8a4
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
pyim-candidates-dcache-quanpin-words remove char-num arg.
---
pyim-candidates.el | 23 +++++++++--------------
tests/pyim-tests.el | 35 +++++++++++++++++++++++++++++------
2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/pyim-candidates.el b/pyim-candidates.el
index 40ab8728a9..bf6f0c0759 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -211,16 +211,15 @@
(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 char-num)
+(defun pyim-candidates-dcache-quanpin-words (imobjs scheme &optional
fast-search)
"从 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-first-chars imobj scheme char-num))
+ (w3 (pyim-candidates-quanpin-first-chars imobj scheme))
(w4 (unless w3
- (pyim-candidates-quanpin-first-possible-chars
- imobj scheme char-num))))
+ (pyim-candidates-quanpin-first-possible-chars imobj
scheme))))
(push w1 personal-words)
(push w2 common-words)
(push w3 pinyin-chars-1)
@@ -245,19 +244,17 @@
'(code2word shortcode2word)
'(code2word))))
-(defun pyim-candidates-quanpin-first-chars (imobj scheme &optional num)
+(defun pyim-candidates-quanpin-first-chars (imobj scheme)
"获取输入的全拼对应的第一个汉字。
假如用户输入 nihao 时,获取 ni 对应的汉字。"
(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)))
+ ,@(pyim-pymap-py2cchar-get code t t)))))
+ chars))
-(defun pyim-candidates-quanpin-first-possible-chars (imobj scheme &optional
num)
+(defun pyim-candidates-quanpin-first-possible-chars (imobj scheme)
"获取输入的全拼对应的第一个可能的常用汉字。
1. 假如用户输入 ni 时,获取拼音匹配 ni.* 的常用汉字,比如: ni
@@ -272,10 +269,8 @@
;; 论只是猜测。
(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)))
+ pinyin (> (length imobj) 1)))))))
+ chars))
(cl-defgeneric pyim-candidates-create-limit-time (_imobjs _scheme)
"按照 SCHEME, 使用限时运行的方式从 IMOBJS 获得候选词条。
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 4dd7d7ccbf..b112934529 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -567,6 +567,29 @@
'("你好" "你坏" "尼耗")))
(should-not (pyim-candidates-jianpin-words imobjs2 quanpin))))
+(defun pyim-tests-sublist (list n)
+ (if (>= (length list) n)
+ (cl-subseq list 0 n)
+ list))
+
+(defun pyim-tests-sublists (lists n)
+ (cl-mapcar
+ (lambda (x)
+ (pyim-tests-sublist x n))
+ lists))
+
+(ert-deftest pyim-tests-sublist ()
+ (let ((list '(1 2 3 4 5 6)))
+ (should (equal (pyim-tests-sublist list 7) list))
+ (should (equal (pyim-tests-sublist list 6) list))
+ (should (equal (pyim-tests-sublist list 5)
+ '(1 2 3 4 5)))))
+
+(ert-deftest pyim-tests-sublists ()
+ (let ((lists '((1 2 3) (1 2 3 4 5))))
+ (should (equal (pyim-tests-sublists lists 4)
+ '((1 2 3) (1 2 3 4))))))
+
(ert-deftest pyim-tests-pyim-candidates-get-dcache-words ()
(let* ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
(pyim-dhashcache-icode2word (make-hash-table :test #'equal))
@@ -582,11 +605,11 @@
(puthash "ni-hao" (list "你好" "尼耗" "呢耗") pyim-dhashcache-icode2word)
(puthash "ni-hao" (list "你好" "尼耗") pyim-dhashcache-code2word)
(puthash "n-h" (list "你好" "你坏" "尼耗" "南好" "内核" "内河")
pyim-dhashcache-ishortcode2word)
- (should (equal (pyim-candidates-dcache-quanpin-words imobjs1 quanpin nil
10)
+ (should (equal (pyim-tests-sublists (pyim-candidates-dcache-quanpin-words
imobjs1 quanpin nil) 10)
'(("你" "您" "妮") nil nil ("南" "乃" "囊" "脑" "呢" "内" "嫩" "能"
"你" "年"))))
- (should (equal (pyim-candidates-dcache-quanpin-words imobjs2 quanpin nil
10)
+ (should (equal (pyim-tests-sublists (pyim-candidates-dcache-quanpin-words
imobjs2 quanpin nil) 10)
'(("你" "尼") ("尼" "你") ("你" "尼" "呢" "泥" "拟" "逆" "倪" "妮" "腻"
"匿") nil)))
- (should (equal (pyim-candidates-dcache-quanpin-words imobjs3 quanpin nil
10)
+ (should (equal (pyim-tests-sublists (pyim-candidates-dcache-quanpin-words
imobjs3 quanpin nil) 10)
'(("你好" "尼耗" "呢耗") ("你好" "尼耗") ("你好" "尼耗" "呢耗") nil)))))
(ert-deftest pyim-tests-pyim-candidates-quanpin-personal-words ()
@@ -632,16 +655,16 @@
(imobjs (pyim-imobjs-create "nihao" quanpin)))
(puthash "ni" (list "你" "呢") pyim-dhashcache-icode2word)
(puthash "ni" (list "你" "尼") pyim-dhashcache-code2word)
- (should (equal (pyim-candidates-quanpin-first-chars (car imobjs) quanpin
10)
+ (should (equal (pyim-tests-sublist (pyim-candidates-quanpin-first-chars
(car imobjs) quanpin) 10)
'("你" "呢" "尼" "泥" "拟" "逆" "倪" "妮" "腻" "匿")))))
(ert-deftest pyim-tests-pyim-candidates-quanpin-first-possible-chars ()
(let* ((quanpin (pyim-scheme-get 'quanpin))
(imobjs1 (pyim-imobjs-create "ni" quanpin))
(imobjs2 (pyim-imobjs-create "nihao" quanpin)))
- (should (equal (pyim-candidates-quanpin-first-possible-chars (car imobjs1)
quanpin 10)
+ (should (equal (pyim-tests-sublist
(pyim-candidates-quanpin-first-possible-chars (car imobjs1) quanpin) 10)
'("你" "年" "娘" "鸟" "摄" "您" "宁" "牛" "尼" "念")))
- (should (equal (pyim-candidates-quanpin-first-possible-chars (car imobjs2)
quanpin 10)
+ (should (equal (pyim-tests-sublist
(pyim-candidates-quanpin-first-possible-chars (car imobjs2) quanpin) 10)
'("你" "尼" "呢" "泥" "拟" "逆" "倪" "妮" "腻" "匿")))))
(ert-deftest pyim-tests-pyim-candidates-search-buffer ()