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

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

[elpa] externals/pyim cdff979715 2/3: Remove pyim-dcache-search-word-cod


From: ELPA Syncer
Subject: [elpa] externals/pyim cdff979715 2/3: Remove pyim-dcache-search-word-code
Date: Fri, 10 Jun 2022 05:58:04 -0400 (EDT)

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

    Remove pyim-dcache-search-word-code
---
 pyim-cstring.el    |  2 +-
 pyim-dcache.el     |  4 ----
 pyim-dhashcache.el |  5 -----
 pyim-dregcache.el  | 61 +++++++++++++++++++++---------------------------------
 4 files changed, 25 insertions(+), 47 deletions(-)

diff --git a/pyim-cstring.el b/pyim-cstring.el
index 7e9dbff6ba..5127f5993f 100644
--- a/pyim-cstring.el
+++ b/pyim-cstring.el
@@ -182,7 +182,7 @@ BUG: 当 STRING 中包含其它标点符号,并且设置 SEPERATER 时,结
             (mapcar (lambda (x)
                       (when (string-prefix-p prefix x)
                         (string-remove-prefix prefix x)))
-                    (sort (cl-copy-list (pyim-dcache-search-word-code string))
+                    (sort (cl-copy-list (pyim-dcache-get string '(word2code)))
                           (lambda (a b)
                             (> (length a) (length b))))))
            (codes (remove nil dcache-codes)))
diff --git a/pyim-dcache.el b/pyim-dcache.el
index 063d8fd5c9..12946a0fa7 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -221,10 +221,6 @@ dcache.
 (cl-defmethod pyim-dcache-get :before (_code &optional _from)
   (pyim-dcache-load-backend))
 
-;; ** Dcache 代码反查功能接口
-(cl-defgeneric pyim-dcache-search-word-code (word)
-  "从 dcache 中搜索 WROD 对应的 code.")
-
 ;; ** Dcache 加词功能接口
 (cl-defgeneric pyim-dcache-insert-word (word code prepend)
   "将词条 WORD 插入到 dcache 中。
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index 68a6a86380..4ba5884225 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -130,11 +130,6 @@
             (setq result (append result value)))))
       result)))
 
-;; ** 从 dhashcache 搜索代码相关函数
-(cl-defmethod pyim-dcache-search-word-code
-  (string &context ((pyim-dcache-backend) (eql pyim-dhashcache)))
-  (gethash string pyim-dhashcache-word2code))
-
 ;; ** 给 dhashcache 添加词条相关函数
 (cl-defmethod pyim-dcache-insert-word
   (word code prepend
diff --git a/pyim-dregcache.el b/pyim-dregcache.el
index c4e492297c..06641c023e 100644
--- a/pyim-dregcache.el
+++ b/pyim-dregcache.el
@@ -68,23 +68,35 @@
     (cond ((or (memq 'icode2word from)
                (memq 'ishortcode2word from))
            (pyim-dregcache-get-icode2word-ishortcode2word key))
+          ((or (not from)
+               (memq 'code2word from)
+               (memq 'shortcode2word from))
+           (pyim-dregcache-get-code2word-shortcode2word key))
           ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和
           ;; iword2count-recent-50-words.
           ((or (memq 'iword2count-recent-10-words from)
                (memq 'iword2count-recent-50-words from))
            nil)
-          (t (let ((dict-files (pyim-dregcache-all-dict-files))
-                   result)
-
-               (when pyim-debug (message "pyim-dregcache-get is called. 
key=%s" key))
-               (when dict-files
-                 (dolist (file dict-files)
-                   (let* ((file-info (lax-plist-get pyim-dregcache-cache file))
-                          (content (pyim-dregcache-get-content key file-info)))
-                     (setq result (append (pyim-dregcache-get-1 content key) 
result)))))
-               ;; `push' plus `nreverse' is more efficient than `add-to-list'
-               ;; Many examples exist in Emacs' own code
-               (nreverse result))))))
+          ;; pyim-dregcache 目前只能用于全拼输入法,而 pyim 中全拼输入法代码反查
+          ;; 功能是通过 pymap 相关函数实现的,不使用 word2code.
+          ((memq 'word2code from)
+           nil)
+          (t nil))))
+
+(defun pyim-dregcache-get-code2word-shortcode2word (code)
+  (when pyim-debug (message "pyim-dregcache-get-code2word-shortcode2word 
called => %s" code))
+  (let ((dict-files (pyim-dregcache-all-dict-files))
+        result)
+
+    (when pyim-debug (message "pyim-dregcache-get is called. code=%s" code))
+    (when dict-files
+      (dolist (file dict-files)
+        (let* ((file-info (lax-plist-get pyim-dregcache-cache file))
+               (content (pyim-dregcache-get-content code file-info)))
+          (setq result (append (pyim-dregcache-get-1 content code) result)))))
+    ;; `push' plus `nreverse' is more efficient than `add-to-list'
+    ;; Many examples exist in Emacs' own code
+    (nreverse result)))
 
 (defun pyim-dregcache-get-icode2word-ishortcode2word (code)
   "以 CODE 搜索个人词和个人联想词.  正则表达式搜索词库,不需要为联想词开单独缓存."
@@ -191,31 +203,6 @@
     ;; fetch segment using the first character of pinyin code
     (nth idx rlt)))
 
-;; ** 从 dregcache 搜索代码相关函数
-(cl-defmethod pyim-dcache-search-word-code
-  (word &context ((pyim-dcache-backend) (eql pyim-dregcache)))
-  "从 `pyim-dregcache-cache' 和 `pyim-dregcache-icode2word' 搜索 word, 得到对应的code."
-  (when pyim-debug (message "pyim-dregcache-search-word-code word=%s" word))
-  (when pyim-dregcache-cache
-    (catch 'result
-      (let ((dict-files (pyim-dregcache-all-dict-files))
-            code)
-        (when pyim-dregcache-icode2word
-          (setq code (pyim-dregcache-search-word-code-1 word 
pyim-dregcache-icode2word))
-          (when code (throw 'result (list code))))
-        (dolist (file dict-files)
-          (let* ((file-info (lax-plist-get pyim-dregcache-cache file))
-                 (contents (lax-plist-get file-info :content)))
-            (dolist (content contents)
-              (setq code (pyim-dregcache-search-word-code-1 word content))
-              (when code (throw 'result (list code))))))))))
-
-(defun pyim-dregcache-search-word-code-1 (word content)
-  (let* ((case-fold-search t)
-         (regexp (concat "^\\([a-z-]+\\)\\(.*\\) " "\\(" word " \\|" word 
"$\\)")))
-    (when (string-match regexp content)
-      (match-string-no-properties 1 content))))
-
 ;; ** 给 dregcache 添加词条相关函数
 (cl-defmethod pyim-dcache-insert-word
   (word code prepend



reply via email to

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