[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 33a0f5a9b7 09/41: Add pyim-candidates-create-like-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 33a0f5a9b7 09/41: Add pyim-candidates-create-like-jianpin |
Date: |
Sat, 4 Jun 2022 09:57:45 -0400 (EDT) |
branch: externals/pyim
commit 33a0f5a9b76ad3d4349f6c9228ab10c68b6a20f1
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-candidates-create-like-jianpin
---
pyim-candidates.el | 59 ++++++++++++++++++++++++++++++-----------------------
tests/pyim-tests.el | 11 ++++++++++
2 files changed, 44 insertions(+), 26 deletions(-)
diff --git a/pyim-candidates.el b/pyim-candidates.el
index 84c40428da..89279f0afa 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -166,33 +166,9 @@
(defun pyim-candidates-create-quanpin (imobjs scheme &optional fast-search)
"`pyim-candidates-create' 内部使用的函数。"
(let ((znabc-words (pyim-candidates-create-like-znabc imobjs scheme
fast-search))
- jianpin-words personal-words common-words
+ (jianpin-words (pyim-candidates-create-like-jianpin imobjs scheme))
+ 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
- (> (length (car imobjs)) 1))
- (dolist (imobj imobjs)
- (let* ((w (pyim-dcache-get
- (string-join (pyim-codes-create imobj scheme 1) "-")
- '(ishortcode2word)))
- (regexp1 (string-join
- (pyim-codes-create imobj scheme)
- "-"))
- (regexp2 (string-join
- (pyim-codes-create imobj scheme)
- "[^-]*-"))
- (w1 (cl-remove-if-not
- (lambda (cstr)
- (let ((py (pyim-cstring-to-pinyin cstr nil "-")))
- (or (string-match-p regexp1 py)
- (string-match-p regexp2 py))))
- w))
- (w2 (cl-remove-if-not
- (lambda (cstr)
- (string-match-p regexp1 (pyim-cstring-to-pinyin cstr nil
"-")))
- w1)))
- (push (append w2 w1) jianpin-words))))
;; 获取个人词条,词库词条和第一汉字列表。
(dolist (imobj imobjs)
@@ -277,6 +253,37 @@
(pyim-zip codes))
fast-search)))
+(defun pyim-candidates-create-like-jianpin (imobjs scheme)
+ "简拼模式。
+
+ 假如输入 \"nih\" ,那么搜索 code 为 \"n-h\" 的词条,然后筛选出所
+ 有拼音匹配\"ni-h\" 或者 \"ni[^-]*-h\" 的词条。"
+ (when (and pyim-enable-shortcode
+ (> (length (car imobjs)) 1))
+ (let (jianpin-words)
+ (dolist (imobj imobjs)
+ (let* ((w (pyim-dcache-get
+ (string-join (pyim-codes-create imobj scheme 1) "-")
+ '(ishortcode2word)))
+ (regexp1 (string-join
+ (pyim-codes-create imobj scheme)
+ "-"))
+ (regexp2 (string-join
+ (pyim-codes-create imobj scheme)
+ "[^-]*-"))
+ (w1 (cl-remove-if-not
+ (lambda (cstr)
+ (let ((py (pyim-cstring-to-pinyin cstr nil "-")))
+ (or (string-match-p regexp1 py)
+ (string-match-p regexp2 py))))
+ w))
+ (w2 (cl-remove-if-not
+ (lambda (cstr)
+ (string-match-p regexp1 (pyim-cstring-to-pinyin cstr nil
"-")))
+ w1)))
+ (push (delete-dups (append w2 w1)) jianpin-words)))
+ jianpin-words)))
+
(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 87d8101e21..cbc4a4bfda 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -526,6 +526,17 @@
(should (equal (pyim-candidates-create-like-znabc imobjs quanpin t)
'("你好吗朋友" "你好吗" "你好")))))
+(ert-deftest pyim-tests-pyim-candidates-create-like-jianpin ()
+ (let* ((pyim-dhashcache-code2word (make-hash-table :test #'equal))
+ (pyim-dhashcache-icode2word (make-hash-table :test #'equal))
+ (quanpin (pyim-scheme-get 'quanpin))
+ (imobjs1 (pyim-imobjs-create "nih" quanpin))
+ (imobjs2 (pyim-imobjs-create "ni" quanpin)))
+ (puthash "n-h" (list "你好" "你坏" "尼耗" "南好" "内核" "内河")
pyim-dhashcache-ishortcode2word)
+ (should (equal (pyim-candidates-create-like-jianpin imobjs1 quanpin)
+ '(("你好" "你坏" "尼耗"))))
+ (should-not (pyim-candidates-create-like-jianpin imobjs2 quanpin))))
+
(ert-deftest pyim-tests-pyim-candidates-search-buffer ()
(with-temp-buffer
(insert "你好你好你坏你坏你话牛蛤牛和牛蛤牛蛤牛蛤牛蛤牛蛤")
- [elpa] externals/pyim 845e9f6e4f 23/41: * pyim-candidates.el (pyim-candidates-create-async): Simplify shuangpin., (continued)
- [elpa] externals/pyim 845e9f6e4f 23/41: * pyim-candidates.el (pyim-candidates-create-async): Simplify shuangpin., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 5611319de0 35/41: Add page test, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim aa07a23fda 39/41: * pyim-probe.el (pyim-probe-org-latex-mode): Update., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 573fefe532 38/41: Use (eql symbol) instead of (eql 'symbol)., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 2f1aaaa9a7 41/41: Merge pull request #442 from tumashu/struct, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim c5a77c3f73 05/41: Add pyim-candidate-create-async, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 0d357b5fd9 08/41: pyim-candidates-create-like-znabc, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 6ce5f49b8f 01/41: Big refactor: use cl-defstruct and cl-defgeneric., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim f5300086fd 02/41: * tests/pyim-tests.el (pyim-tests-pyim-candidates-get-chief): New test., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim f536e5ede3 06/41: Fix warns., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 33a0f5a9b7 09/41: Add pyim-candidates-create-like-jianpin,
ELPA Syncer <=
- [elpa] externals/pyim b6b46a4e36 22/41: * pyim-candidates.el (pyim-candidates-create): Remove method of shuangpin., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim b3868caa80 29/41: Add pyim-probe tests, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 951013539c 33/41: Add progress to commentary, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim f4cc14ac64 32/41: Fix pyim-test.el, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 1b767c669e 40/41: * pyim-probe.el (pyim-probe-org-speed-commands): Updated., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 6ef8630475 11/41: pyim-candidates-create-like-znabc -> pyim-candidates-znabc-words, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 2aa48479b4 14/41: pyim-candidates-create-get-pymap-chars -> pyim-candidates-pymap-chars, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 016064e7fc 16/41: Update docstring., ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 1330b436a6 27/41: Refactor pyim-page.el, ELPA Syncer, 2022/06/04
- [elpa] externals/pyim 302f1bff4b 34/41: Refactor pyim-preview.el, ELPA Syncer, 2022/06/04