emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/pyim 0d357b5fd9 08/41: pyim-candidates-create-like-znab


From: ELPA Syncer
Subject: [elpa] externals/pyim 0d357b5fd9 08/41: pyim-candidates-create-like-znabc
Date: Sat, 4 Jun 2022 09:57:45 -0400 (EDT)

branch: externals/pyim
commit 0d357b5fd94a6b77317d54b20af561fab4ae3eee
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    pyim-candidates-create-like-znabc
---
 pyim-candidates.el  | 30 ++++++++++++++----------------
 tests/pyim-tests.el | 13 +++++++++++++
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/pyim-candidates.el b/pyim-candidates.el
index dce753394f..84c40428da 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -165,22 +165,9 @@
 
 (defun pyim-candidates-create-quanpin (imobjs scheme &optional fast-search)
   "`pyim-candidates-create' 内部使用的函数。"
-  (let (;; Let indent beautiful.
-        jianpin-words znabc-words
-        personal-words common-words
-        pinyin-chars-1 pinyin-chars-2
-        chief-word)
-    ;; 智能ABC模式,得到尽可能的拼音组合,查询这些组合,得到的词条做为联想词。
-    (let ((codes (mapcar (lambda (x)
-                           (pyim-subconcat x "-"))
-                         (mapcar (lambda (imobj)
-                                   (pyim-codes-create imobj scheme))
-                                 imobjs))))
-      (setq znabc-words
-            (pyim-zip (mapcar #'pyim-dcache-get
-                              (pyim-zip codes))
-                      fast-search)))
-
+  (let ((znabc-words (pyim-candidates-create-like-znabc imobjs scheme 
fast-search))
+        jianpin-words personal-words common-words
+        pinyin-chars-1 pinyin-chars-2 chief-word)
     ;; 假如输入 "nih" ,那么搜索 code 为 "n-h" 的词条,然后筛选出所有拼音匹配
     ;; "ni-h" 或者 "ni[^-]*-h" 的词条。
     (when (and pyim-enable-shortcode
@@ -279,6 +266,17 @@
              ,@pinyin-chars-2
              )))))
 
+(defun pyim-candidates-create-like-znabc (imobjs scheme &optional fast-search)
+  "智能ABC模式,得到尽可能的拼音组合,查询这些组合,得到的词条做为联想词。"
+  (let ((codes (mapcar (lambda (x)
+                         (pyim-subconcat x "-"))
+                       (mapcar (lambda (imobj)
+                                 (pyim-codes-create imobj scheme))
+                               imobjs))))
+    (pyim-zip (mapcar #'pyim-dcache-get
+                      (pyim-zip codes))
+              fast-search)))
+
 (cl-defmethod pyim-candidates-create (_imobjs (_scheme pyim-scheme-shuangpin))
   "按照 SCHEME, 从 IMOBJS 获得候选词条,用于双拼输入法。"
   (cl-call-next-method))
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 710cfdc77b..87d8101e21 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -513,6 +513,19 @@
               wubi)
              '("㠭子叕" "㠭子又")))))
 
+(ert-deftest pyim-tests-pyim-candidates-create-like-znabc ()
+  (let* ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
+         (pyim-dhashcache-icode2word (make-hash-table :test #'equal))
+         (quanpin (pyim-scheme-get 'quanpin))
+         (imobjs (pyim-imobjs-create "nihaomapengyou" quanpin)))
+    (puthash "ni-hao" (list "你好" "尼耗") pyim-dhashcache-code2word)
+    (puthash "ni-hao-ma" (list "你好吗" "你好马") pyim-dhashcache-code2word)
+    (puthash "ni-hao-ma-peng-you" (list "你好吗朋友" "你好吗喷油") 
pyim-dhashcache-code2word)
+    (should (equal (pyim-candidates-create-like-znabc imobjs quanpin)
+                   '("你好吗朋友" "你好吗" "你好" "你好吗喷油" "你好马" "尼耗")))
+    (should (equal (pyim-candidates-create-like-znabc imobjs quanpin t)
+                   '("你好吗朋友" "你好吗" "你好")))))
+
 (ert-deftest pyim-tests-pyim-candidates-search-buffer ()
   (with-temp-buffer
     (insert "你好你好你坏你坏你话牛蛤牛和牛蛤牛蛤牛蛤牛蛤牛蛤")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]