[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim f88d0d0 2/2: 优化智能ABC模式
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim f88d0d0 2/2: 优化智能ABC模式 |
Date: |
Sat, 4 Dec 2021 21:57:35 -0500 (EST) |
branch: externals/pyim
commit f88d0d09fc5f8cbe8bdc66bd6eada71dd76f0a6b
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
优化智能ABC模式
* pyim-candidates.el (pyim-candidates-create:quanpin): 优化智能ABC模式。
* pyim-common.el (pyim-subconcat): New function.
(pyim-zip): the result delete dups.
---
pyim-candidates.el | 19 ++++++++-----------
pyim-common.el | 30 ++++++++++++++++++++----------
2 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/pyim-candidates.el b/pyim-candidates.el
index a05e483..8c81237 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -93,17 +93,14 @@ IMOBJS 获得候选词条。"
(unless async
(let (znabc-words pinyin-chars personal-words common-words)
;; 智能ABC模式,得到尽可能的拼音组合,查询这些组合,得到的词条做为联想词。
- ;;
- ;; NOTE: 智能ABC模式 *目前* 不处理模糊音,因为这个模式会进行大量的搜索,如
- ;; 果再处理模糊音的话,有可能导致性能下降。
- (let* ((codes (pyim-codes-create (car imobjs) scheme-name))
- (n (- (length codes) 1))
- output)
- (dotimes (i (- n 1))
- (let ((lst (cl-subseq codes 0 (- n i))))
- (push (mapconcat #'identity lst "-") output)))
- (dolist (code (reverse output))
- (setq znabc-words (append znabc-words (pyim-dcache-get code)))))
+ (let ((codes (mapcar (lambda (x)
+ (pyim-subconcat x "-"))
+ (mapcar (lambda (imobj)
+ (pyim-codes-create imobj scheme-name))
+ imobjs))))
+ (setq znabc-words
+ (pyim-zip (mapcar #'pyim-dcache-get
+ (pyim-zip codes)))))
;; 获取个人词条,词库词条和第一汉字列表。
(dolist (imobj imobjs)
diff --git a/pyim-common.el b/pyim-common.el
index f794291..7b84473 100644
--- a/pyim-common.el
+++ b/pyim-common.el
@@ -86,16 +86,26 @@
(pyim-permutate-list list-tail)))))))
(defun pyim-zip (lists)
- "Zip LISTS: ((a b c) (d e)) => (a d b e c)."
- (let* ((n (apply #'max (mapcar #'length lists)))
- (lists (mapcar
- (lambda (x)
- (append x (make-list (- n (length x)) nil)))
- lists)))
- (flatten-tree
- (apply #'cl-mapcar
- (lambda (&rest x) x)
- lists))))
+ "Zip LISTS and delete dups: ((a b c) (d e)) => (a d b e c)."
+ (when lists
+ (let* ((n (apply #'max (mapcar #'length lists)))
+ (lists (mapcar
+ (lambda (x)
+ (append x (make-list (- n (length x)) nil)))
+ lists)))
+ (delete-dups
+ (flatten-tree
+ (apply #'cl-mapcar
+ #'list lists))))))
+
+(defun pyim-subconcat (list &optional sep)
+ "Concat sublist of LIST with SEP: (a b c d) => (a-b-c a-b)."
+ (let ((n (- (length list) 1))
+ output)
+ (dotimes (i (- n 1))
+ (let ((list (cl-subseq list 0 (- n i))))
+ (push (mapconcat #'identity list (or sep "-")) output)))
+ (nreverse output)))
(defun pyim-char-before-to-string (num)
"得到光标前第 `num' 个字符,并将其转换为字符串。"