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

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

[elpa] externals/pyim ee677ba38f 2/5: 优化形码输入法的词条排序。


From: ELPA Syncer
Subject: [elpa] externals/pyim ee677ba38f 2/5: 优化形码输入法的词条排序。
Date: Fri, 31 Dec 2021 01:57:45 -0500 (EST)

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

    优化形码输入法的词条排序。
    
            * pyim.el (pyim-select-word:xingma): 只保存词条 count, 不调整词条位置。
    
            * pyim-candidates.el (pyim-candidates-create:xingma): 优化代码。
    
    形码输入法的第一个词选择公共词库中的第一个词,
    剩下的词条按照词条 count 大小排序。
---
 pyim-candidates.el | 47 +++++++++++++++++++++++++++++++----------------
 pyim.el            |  6 +-----
 2 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/pyim-candidates.el b/pyim-candidates.el
index 18a1e1646f..fe50cd2755 100644
--- a/pyim-candidates.el
+++ b/pyim-candidates.el
@@ -70,22 +70,37 @@ IMOBJS 获得候选词条。"
   (unless async
     (let (result)
       (dolist (imobj imobjs)
-        (let* ((codes (reverse (pyim-codes-create imobj scheme-name)))
-               (output1 (car codes))
-               (output2 (reverse (cdr codes)))
-               output3 str)
-
-          (when output2
-            (setq str (mapconcat
-                       (lambda (code)
-                         (car (pyim-dcache-get code)))
-                       output2 "")))
-          (setq output3
-                (remove "" (or (mapcar (lambda (x)
-                                         (concat str x))
-                                       (pyim-dcache-get output1 '(icode2word 
code2word shortcode2word)))
-                               (list str))))
-          (setq result (append result output3))))
+        (let* ((codes (pyim-codes-create imobj scheme-name))
+               (last-code (car (last codes)))
+               (other-codes (remove last-code codes))
+               output prefix)
+
+          ;; 如果 wubi/aaaa -> 工 㠭;wubi/bbbb -> 子 子子孙孙;wubi/cccc 又 叕;
+          ;; 用户输入为: aaaabbbbcccc
+
+          ;; 那么:
+          ;; 1. codes       =>   ("wubi/aaaa" "wubi/bbbb" "wubi/cccc")
+          ;; 2. last-code   =>   "wubi/cccc"
+          ;; 3. other-codes =>   ("wubi/aaaa" "wubi/bbbb")
+          ;; 4. prefix      =>   工子
+          (when other-codes
+            (setq prefix (mapconcat
+                          (lambda (code)
+                            (car (pyim-dcache-get code '(code2word))))
+                          other-codes "")))
+
+          ;; 5. output => 工子又 工子叕
+          (setq output
+                (mapcar (lambda (word)
+                          (concat prefix word))
+                        ;; NOTE: 形码输入法的第一个词选择公共词库中的第一个词,
+                        ;; 剩下的词按照词条 count 大小排序。这种策略是否合理?
+                        `(,(car (pyim-dcache-get last-code '(code2word)))
+                          ,@(pyim-dcache-call-api
+                             'sort-words
+                             (pyim-dcache-get last-code '(icode2word code2word 
shortcode2word))))))
+          (setq output (remove "" (or output (list prefix))))
+          (setq result (append result output))))
       (when (car result)
         (delete-dups result)))))
 
diff --git a/pyim.el b/pyim.el
index 9ba9f9aec6..a498846075 100644
--- a/pyim.el
+++ b/pyim.el
@@ -591,12 +591,8 @@ FILE 的格式与 `pyim-dcache-export' 生成的文件格式相同,
           ;; 字符串里面剪掉。
           (delete-region (point-min) (point)))
         (pyim-process-run))
-    ;; 型码输入法,只考虑将词条保存到个人词库,用于调整词频,单字不保存。
     (unless (pyim-process-select-subword-p) ;NOTE: 以词定字的时候,到底应不应该保存词条呢,需要进一步研究。
-      (when (> (length (pyim-process-get-outcome)) 1)
-        (if (member (pyim-process-get-outcome) (pyim-process-get-candidates))
-            (pyim-process-create-word (pyim-process-get-outcome) t)
-          (pyim-process-create-word (pyim-process-get-outcome)))))
+      (pyim-process-create-word (pyim-process-get-outcome)))
     (pyim-process-terminate)
     ;; pyim 使用这个 hook 来处理联想词。
     (run-hooks 'pyim-select-finish-hook)))



reply via email to

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