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

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

[elpa] externals/pyim 408cbeb 19/36: Add pyim-imobjs-codes


From: ELPA Syncer
Subject: [elpa] externals/pyim 408cbeb 19/36: Add pyim-imobjs-codes
Date: Thu, 22 Apr 2021 22:57:18 -0400 (EDT)

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

    Add pyim-imobjs-codes
---
 pyim-imobjs-codes.el | 266 +++++++++++++++++++++++++++++++++++++++++++++++++++
 pyim.el              | 231 +-------------------------------------------
 2 files changed, 267 insertions(+), 230 deletions(-)

diff --git a/pyim-imobjs-codes.el b/pyim-imobjs-codes.el
new file mode 100644
index 0000000..7694cc2
--- /dev/null
+++ b/pyim-imobjs-codes.el
@@ -0,0 +1,266 @@
+;;; pyim-imobjs-codes.el --- imobjs and codes lib for pyim.        -*- 
lexical-binding: t; -*-
+
+;; * Header
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; Author: Feng Shu <tumashu@163.com>
+;; Maintainer: Feng Shu <tumashu@163.com>
+;; URL: https://github.com/tumashu/pyim
+;; Keywords: convenience, Chinese, pinyin, input-method
+;; Package-Requires: ((emacs "24.4") (async "1.6") (xr "1.13"))
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+;; * 代码                                                           :code:
+(require 'cl-lib)
+
+(defvar pyim-imobjs nil
+  "Imobj (Input method object) 组成的 list.
+
+imobj 在 pyim 里面的概念,类似与编译器里面的语法树,
+它代表 pyim 输入的字符串 entered 解析得到的一个结构化对象,
+以全拼输入法的为例:
+
+1. entered: nihaoma
+2. imobj: ((\"n\" \"i\" \"n\" \"i\") (\"h\" \"ao\" \"h\" \"ao\") (\"m\" \"a\" 
\"m\" \"a\"))
+
+而 imobjs 是 imobj 组成的一个列表,因为有模糊音等概念的存在,一个
+entered 需要以多种方式或者多步骤解析,得到多种可能的 imobj, 这些
+imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
+
+1. entered: guafeng (设置了模糊音 en -> eng)
+2. imobj-1: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"eng\"))
+3. imobj-2: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"eng\" \"f\" \"eng\"))
+4. imobjs:  (((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"eng\"))
+             ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"eng\" \"f\" \"eng\")))
+
+这个变量用来保存解析得到的 imobjs。
+
+解析完成之后,pyim 会为每一个 imobj 创建对应 code 字符串, 然后在词库
+中搜索 code 字符串来得到所需要的词条,最后使用特定的方式将得到的
+词条组合成一个候选词列表:`pyim-candidates' 并通过 pyim-page 相关
+功能来显示选词框,供用户选择词条,比如:
+
+1. imobj: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"en\"))
+2. code: gua-fen
+
+从上面的说明可以看出,imobj 本身也是有结构的:
+
+1. imobj: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"en\"))
+
+我们将 (\"g\" \"ua\" \"g\" \"ua\") 这些子结构,叫做 imelem (IM element), *大
+多数情况下*, 一个 imelem 能够代表一个汉字,这个概念在编辑 entered
+的时候,非常有用。
+
+另外要注意的是,不同的输入法, imelem 的内部结构是不一样的,比如:
+1. quanping:  (\"g\" \"ua\" \"g\" \"ua\")
+2. shuangpin: (\"h\" \"ao\" \"h\" \"c\")
+3. wubi:      (\"aaaa\")")
+
+(defun pyim-imobjs-create (entered &optional scheme-name)
+  "按照 SCHEME-NAME 对应的输入法方案,从 ENTERED 字符串中创建一个
+或者多个 imobj 组成的列表,不同的输入法,imobj 的结构也是不一样的。"
+  (let ((class (pyim-scheme-get-option scheme-name :class)))
+    (when class
+      (funcall (intern (format "pyim-imobjs-create:%S" class))
+               entered scheme-name))))
+
+(defun pyim-imobjs-create:quanpin (entered &optional _)
+  "从用户输入的字符串 ENTERED 创建一个输入法内部对象列表: imobjs.
+
+这个 imobjs 可能包含一个 imobj, 也可能包含多个,每个 imobj 都包含
+声母和韵母的相关信息,比如:
+
+    (pyim-imobjs-create:quanpin \"woaimeinv\" 'quanpin)
+
+结果为:
+
+    (((\"w\" \"o\" \"w\" \"o\") (\"\" \"ai\" \"\" \"ai\") (\"m\" \"ei\" \"m\" 
\"ei\") (\"n\" \"v\" \"n\" \"v\")))
+
+如果字符串无法正确处理,则返回 nil, 比如:
+
+   (pyim-imobjs-create \"ua\" 'quanpin)
+
+全拼输入法的 imelem 是四个字符串组成的 list, 类似:
+
+  (\"w\" \"o\" \"w\" \"o\")
+
+代表:
+
+  (声母1, 韵母1, 声母2, 韵母2)
+
+声母1和声母2一般用来生成 code 字符串,用于词库中寻找词条。声母2和
+韵母2一般用来反向构建 entered 字符串,用于“多次选择生成词条”这个
+功能。
+
+大多数情况,声母1 = 声母2, 韵母1 = 韵母2, 只有在使用模糊音的时候,
+才可能出现不一致的情况。"
+  (when (and entered (string< "" entered))
+    (let* ((str-list (remove "" (split-string entered "'")))
+           (n (length str-list))
+           output)
+      (dotimes (i n)
+        (let* ((str (nth i str-list))
+               (x (pyim-pinyin-split str)))
+          (if (not x)
+              (setq output nil)
+            (when (> i 0)
+              ;; 将强制分割符号附加到封分割符后面的声母开头,
+              ;; 类似: ("'n" "i" "n" "i"), 用于 `pyim-page-preview-create' 函数。
+              (setf (caar x)
+                    (concat "'" (caar x))))
+            (setq output (append output x)))))
+      (when output
+        (pyim-imobjs-find-fuzzy:quanpin (list output))))))
+
+;; "nihc" -> (((\"n\" \"i\" \"n\" \"i\") (\"h\" \"ao\" \"h\" \"c\")))
+(defun pyim-imobjs-create:shuangpin (entered &optional scheme-name)
+  (let ((keymaps (pyim-scheme-get-option scheme-name :keymaps))
+        (list (string-to-list (replace-regexp-in-string "-" "" entered)))
+        results)
+    (while list
+      (let* ((sp-sm (pop list))
+             (sp-ym (pop list))
+             (sp-sm (when sp-sm (char-to-string sp-sm)))
+             (sp-ym (when sp-ym (char-to-string sp-ym)))
+             (sm (nth 1 (assoc sp-sm keymaps)))
+             (ym (or (cdr (cdr (assoc sp-ym keymaps))) (list "")))
+             one-word-pinyins)
+
+        (dolist (x ym)
+          (let* ((y (concat sp-sm (or sp-ym " ")))
+                 (z (cadr (assoc y keymaps)))
+                 (py (if z (list "" z sp-sm sp-ym) (list sm x sp-sm sp-ym))))
+            (unless (string-match-p pyim-pinyin-shuangpin-invalid-pinyin-regexp
+                                    (concat (nth 0 py) (nth 1 py)))
+              (push py one-word-pinyins))))
+
+        (when (and one-word-pinyins (> (length one-word-pinyins) 0))
+          (push one-word-pinyins results))))
+    (pyim-imobjs-find-fuzzy:quanpin
+     (pyim-permutate-list (nreverse results)))))
+
+(defun pyim-imobjs-create:xingma (entered &optional scheme-name)
+  (let ((n (pyim-scheme-get-option scheme-name :code-split-length)))
+    (let (output)
+      (mapc (lambda (x)
+              (while (not (string-empty-p x))
+                (if (< (length x) n)
+                    (progn
+                      (push x output)
+                      (setq x ""))
+                  (push (substring x 0 n) output)
+                  (setq x (substring x n)))))
+            (split-string entered "'"))
+      (list (nreverse output)))))
+
+(defun pyim-imobjs-find-fuzzy:quanpin (imobjs)
+  "用于处理模糊音的函数。"
+  (let (fuzzy-imobjs result1 result2)
+    (dolist (imobj imobjs)
+      (setq fuzzy-imobjs
+            (pyim-permutate-list
+             (mapcar #'pyim-imobjs-find-fuzzy:quanpin-1 imobj)))
+      (push (car fuzzy-imobjs) result1)
+      (setq result2 (append result2 (cdr fuzzy-imobjs))))
+    (append result1 result2)))
+
+;; (\"f\" \"en\" \"f\" \"en\") -> ((\"f\" \"en\" \"f\" \"en\") (\"f\" \"eng\" 
\"f\" \"en\"))
+(defun pyim-imobjs-find-fuzzy:quanpin-1 (imelem)
+  "Find all fuzzy pinyins."
+  (cl-labels ((find-list (str list)
+                         (let (result)
+                           (dolist (x list)
+                             (when (member str x)
+                               (setq list nil)
+                               (setq result
+                                     (delete-dups
+                                      `(,str ,@(cl-copy-list x))))))
+                           (or result (list str)))))
+    (let* ((fuzzy-alist pyim-fuzzy-pinyin-alist)
+           (sm-list (find-list (nth 0 imelem) fuzzy-alist))
+           (ym-list (find-list (nth 1 imelem) fuzzy-alist))
+           result)
+      (dolist (a sm-list)
+        (dolist (b ym-list)
+          (push `(,a ,b ,@(nthcdr 2 imelem)) result)))
+      (reverse result))))
+
+(defun pyim-codes-create (imobj scheme-name &optional first-n)
+  "按照 SCHEME-NAME 对应的输入法方案,从一个 IMOBJ 创建一个列表 codes, 这个列表
+包含一个或者多个 code 字符串,这些 code 字符串用于从词库中搜索词条."
+  (let ((class (pyim-scheme-get-option scheme-name :class)))
+    (when class
+      (funcall (intern (format "pyim-codes-create:%S" class))
+               imobj scheme-name first-n))))
+
+(defun pyim-codes-create:quanpin (imobj _scheme-name &optional first-n)
+  "从IMOBJ 创建一个 code 列表:codes.
+
+列表 codes 中包含一个或者多个 code 字符串,这些 code 字符串用于从
+词库中搜索相关词条。
+
+    (pyim-codes-create '((\"w\" \"o\" \"w\" \"o\") (\"\" \"ai\" \"\" \"ai\") 
(\"m\" \"ei\" \"m\" \"ei\") (\"n\"  \"v\" \"n\"  \"v\")) 'quanpin)
+
+结果为:
+
+   (\"wo\" \"ai\" \"mei\" \"nv\")"
+  (mapcar
+   #'(lambda (w)
+       (let ((py (replace-regexp-in-string ;去掉分隔符,在词库中搜索候选词不需要分隔符
+                  "'" "" (concat (nth 0 w) (nth 1 w)))))
+         (if (numberp first-n)
+             (substring py 0 (min first-n (length py)))
+           py)))
+   imobj))
+
+(defun pyim-codes-create:shuangpin (imobj _scheme-name &optional first-n)
+  (pyim-codes-create:quanpin imobj 'quanpin first-n))
+
+(defun pyim-codes-create:xingma (imobj scheme-name &optional first-n)
+  (when scheme-name
+    (let ((code-prefix (pyim-scheme-get-option scheme-name :code-prefix)))
+      (mapcar
+       #'(lambda (x)
+           (concat (or code-prefix "")
+                   (if (numberp first-n)
+                       (substring x 0 (min first-n (length x)))
+                     x)))
+       imobj))))
+
+(defun pyim-code-search (word scheme-name)
+  "从 SCHEME-NAME 对应的输入法词库中,搜索 WORD 对应的 code.
+
+返回最长的 code."
+  (when (and (stringp word)
+             (> (length word) 0))
+    (let* ((prefix (pyim-scheme-get-option scheme-name :code-prefix))
+           (code
+            (cl-find-if
+             #'(lambda (x)
+                 (equal (substring (or x " ") 0 1) prefix))
+             (sort
+              (cl-copy-list (pyim-dcache-call-api 'search-word-code word))
+              #'(lambda (a b) (> (length a) (length b)))))))
+      (substring (or code " ") 1))))
+
+;; * Footer
+(provide 'pyim-imobjs-codes)
+
+;;; pyim-imobjs.el ends here
diff --git a/pyim.el b/pyim.el
index 7c9b0de..340e895 100644
--- a/pyim.el
+++ b/pyim.el
@@ -585,6 +585,7 @@
 (require 'pyim-dict)
 (require 'pyim-dcache)
 (require 'pyim-scheme)
+(require 'pyim-imobjs-codes)
 (require 'pyim-page)
 (require 'pyim-entered)
 (require 'pyim-candidates)
@@ -713,49 +714,6 @@ pyim 使用函数 `pyim-translate' 来处理特殊功能触发字符。当待输
 ;;;###autoload
 (defvar pyim-titles '("PYIM " "PYIM-EN " "PYIM-AU ") "Pyim 在 mode-line 
中显示的名称.")
 
-(defvar pyim-imobjs nil
-  "Imobj (Input method object) 组成的 list.
-
-imobj 在 pyim 里面的概念,类似与编译器里面的语法树,
-它代表 pyim 输入的字符串 entered 解析得到的一个结构化对象,
-以全拼输入法的为例:
-
-1. entered: nihaoma
-2. imobj: ((\"n\" \"i\" \"n\" \"i\") (\"h\" \"ao\" \"h\" \"ao\") (\"m\" \"a\" 
\"m\" \"a\"))
-
-而 imobjs 是 imobj 组成的一个列表,因为有模糊音等概念的存在,一个
-entered 需要以多种方式或者多步骤解析,得到多种可能的 imobj, 这些
-imobj 组合构成在一起,构成了 imobjs 这个概念。比如:
-
-1. entered: guafeng (设置了模糊音 en -> eng)
-2. imobj-1: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"eng\"))
-3. imobj-2: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"eng\" \"f\" \"eng\"))
-4. imobjs:  (((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"eng\"))
-             ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"eng\" \"f\" \"eng\")))
-
-这个变量用来保存解析得到的 imobjs。
-
-解析完成之后,pyim 会为每一个 imobj 创建对应 code 字符串, 然后在词库
-中搜索 code 字符串来得到所需要的词条,最后使用特定的方式将得到的
-词条组合成一个候选词列表:`pyim-candidates' 并通过 pyim-page 相关
-功能来显示选词框,供用户选择词条,比如:
-
-1. imobj: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"en\"))
-2. code: gua-fen
-
-从上面的说明可以看出,imobj 本身也是有结构的:
-
-1. imobj: ((\"g\" \"ua\" \"g\" \"ua\") (\"f\" \"en\" \"f\" \"en\"))
-
-我们将 (\"g\" \"ua\" \"g\" \"ua\") 这些子结构,叫做 imelem (IM element), *大
-多数情况下*, 一个 imelem 能够代表一个汉字,这个概念在编辑 entered
-的时候,非常有用。
-
-另外要注意的是,不同的输入法, imelem 的内部结构是不一样的,比如:
-1. quanping:  (\"g\" \"ua\" \"g\" \"ua\")
-2. shuangpin: (\"h\" \"ao\" \"h\" \"c\")
-3. wubi:      (\"aaaa\")")
-
 (defvar pyim-preview-overlay nil
   "用于保存光标处预览字符串的 overlay.")
 
@@ -1424,193 +1382,6 @@ Return the input string.
           (not pyim-assistant-scheme-enable))
     (pyim-entered-refresh)))
 
-(defun pyim-imobjs-create (entered &optional scheme-name)
-  "按照 SCHEME-NAME 对应的输入法方案,从 ENTERED 字符串中创建一个
-或者多个 imobj 组成的列表,不同的输入法,imobj 的结构也是不一样的。"
-  (let ((class (pyim-scheme-get-option scheme-name :class)))
-    (when class
-      (funcall (intern (format "pyim-imobjs-create:%S" class))
-               entered scheme-name))))
-
-(defun pyim-imobjs-create:quanpin (entered &optional _)
-  "从用户输入的字符串 ENTERED 创建一个输入法内部对象列表: imobjs.
-
-这个 imobjs 可能包含一个 imobj, 也可能包含多个,每个 imobj 都包含
-声母和韵母的相关信息,比如:
-
-    (pyim-imobjs-create:quanpin \"woaimeinv\" 'quanpin)
-
-结果为:
-
-    (((\"w\" \"o\" \"w\" \"o\") (\"\" \"ai\" \"\" \"ai\") (\"m\" \"ei\" \"m\" 
\"ei\") (\"n\" \"v\" \"n\" \"v\")))
-
-如果字符串无法正确处理,则返回 nil, 比如:
-
-   (pyim-imobjs-create \"ua\" 'quanpin)
-
-全拼输入法的 imelem 是四个字符串组成的 list, 类似:
-
-  (\"w\" \"o\" \"w\" \"o\")
-
-代表:
-
-  (声母1, 韵母1, 声母2, 韵母2)
-
-声母1和声母2一般用来生成 code 字符串,用于词库中寻找词条。声母2和
-韵母2一般用来反向构建 entered 字符串,用于“多次选择生成词条”这个
-功能。
-
-大多数情况,声母1 = 声母2, 韵母1 = 韵母2, 只有在使用模糊音的时候,
-才可能出现不一致的情况。"
-  (when (and entered (string< "" entered))
-    (let* ((str-list (remove "" (split-string entered "'")))
-           (n (length str-list))
-           output)
-      (dotimes (i n)
-        (let* ((str (nth i str-list))
-               (x (pyim-pinyin-split str)))
-          (if (not x)
-              (setq output nil)
-            (when (> i 0)
-              ;; 将强制分割符号附加到封分割符后面的声母开头,
-              ;; 类似: ("'n" "i" "n" "i"), 用于 `pyim-page-preview-create' 函数。
-              (setf (caar x)
-                    (concat "'" (caar x))))
-            (setq output (append output x)))))
-      (when output
-        (pyim-imobjs-find-fuzzy:quanpin (list output))))))
-
-;; "nihc" -> (((\"n\" \"i\" \"n\" \"i\") (\"h\" \"ao\" \"h\" \"c\")))
-(defun pyim-imobjs-create:shuangpin (entered &optional scheme-name)
-  (let ((keymaps (pyim-scheme-get-option scheme-name :keymaps))
-        (list (string-to-list (replace-regexp-in-string "-" "" entered)))
-        results)
-    (while list
-      (let* ((sp-sm (pop list))
-             (sp-ym (pop list))
-             (sp-sm (when sp-sm (char-to-string sp-sm)))
-             (sp-ym (when sp-ym (char-to-string sp-ym)))
-             (sm (nth 1 (assoc sp-sm keymaps)))
-             (ym (or (cdr (cdr (assoc sp-ym keymaps))) (list "")))
-             one-word-pinyins)
-
-        (dolist (x ym)
-          (let* ((y (concat sp-sm (or sp-ym " ")))
-                 (z (cadr (assoc y keymaps)))
-                 (py (if z (list "" z sp-sm sp-ym) (list sm x sp-sm sp-ym))))
-            (unless (string-match-p pyim-pinyin-shuangpin-invalid-pinyin-regexp
-                                    (concat (nth 0 py) (nth 1 py)))
-              (push py one-word-pinyins))))
-
-        (when (and one-word-pinyins (> (length one-word-pinyins) 0))
-          (push one-word-pinyins results))))
-    (pyim-imobjs-find-fuzzy:quanpin
-     (pyim-permutate-list (nreverse results)))))
-
-(defun pyim-imobjs-create:xingma (entered &optional scheme-name)
-  (let ((n (pyim-scheme-get-option scheme-name :code-split-length)))
-    (let (output)
-      (mapc (lambda (x)
-              (while (not (string-empty-p x))
-                (if (< (length x) n)
-                    (progn
-                      (push x output)
-                      (setq x ""))
-                  (push (substring x 0 n) output)
-                  (setq x (substring x n)))))
-            (split-string entered "'"))
-      (list (nreverse output)))))
-
-(defun pyim-imobjs-find-fuzzy:quanpin (imobjs)
-  "用于处理模糊音的函数。"
-  (let (fuzzy-imobjs result1 result2)
-    (dolist (imobj imobjs)
-      (setq fuzzy-imobjs
-            (pyim-permutate-list
-             (mapcar #'pyim-imobjs-find-fuzzy:quanpin-1 imobj)))
-      (push (car fuzzy-imobjs) result1)
-      (setq result2 (append result2 (cdr fuzzy-imobjs))))
-    (append result1 result2)))
-
-;; (\"f\" \"en\" \"f\" \"en\") -> ((\"f\" \"en\" \"f\" \"en\") (\"f\" \"eng\" 
\"f\" \"en\"))
-(defun pyim-imobjs-find-fuzzy:quanpin-1 (imelem)
-  "Find all fuzzy pinyins."
-  (cl-labels ((find-list (str list)
-                         (let (result)
-                           (dolist (x list)
-                             (when (member str x)
-                               (setq list nil)
-                               (setq result
-                                     (delete-dups
-                                      `(,str ,@(cl-copy-list x))))))
-                           (or result (list str)))))
-    (let* ((fuzzy-alist pyim-fuzzy-pinyin-alist)
-           (sm-list (find-list (nth 0 imelem) fuzzy-alist))
-           (ym-list (find-list (nth 1 imelem) fuzzy-alist))
-           result)
-      (dolist (a sm-list)
-        (dolist (b ym-list)
-          (push `(,a ,b ,@(nthcdr 2 imelem)) result)))
-      (reverse result))))
-
-(defun pyim-codes-create (imobj scheme-name &optional first-n)
-  "按照 SCHEME-NAME 对应的输入法方案,从一个 IMOBJ 创建一个列表 codes, 这个列表
-包含一个或者多个 code 字符串,这些 code 字符串用于从词库中搜索词条."
-  (let ((class (pyim-scheme-get-option scheme-name :class)))
-    (when class
-      (funcall (intern (format "pyim-codes-create:%S" class))
-               imobj scheme-name first-n))))
-
-(defun pyim-codes-create:quanpin (imobj _scheme-name &optional first-n)
-  "从IMOBJ 创建一个 code 列表:codes.
-
-列表 codes 中包含一个或者多个 code 字符串,这些 code 字符串用于从
-词库中搜索相关词条。
-
-    (pyim-codes-create '((\"w\" \"o\" \"w\" \"o\") (\"\" \"ai\" \"\" \"ai\") 
(\"m\" \"ei\" \"m\" \"ei\") (\"n\"  \"v\" \"n\"  \"v\")) 'quanpin)
-
-结果为:
-
-   (\"wo\" \"ai\" \"mei\" \"nv\")"
-  (mapcar
-   #'(lambda (w)
-       (let ((py (replace-regexp-in-string ;去掉分隔符,在词库中搜索候选词不需要分隔符
-                  "'" "" (concat (nth 0 w) (nth 1 w)))))
-         (if (numberp first-n)
-             (substring py 0 (min first-n (length py)))
-           py)))
-   imobj))
-
-(defun pyim-codes-create:shuangpin (imobj _scheme-name &optional first-n)
-  (pyim-codes-create:quanpin imobj 'quanpin first-n))
-
-(defun pyim-codes-create:xingma (imobj scheme-name &optional first-n)
-  (when scheme-name
-    (let ((code-prefix (pyim-scheme-get-option scheme-name :code-prefix)))
-      (mapcar
-       #'(lambda (x)
-           (concat (or code-prefix "")
-                   (if (numberp first-n)
-                       (substring x 0 (min first-n (length x)))
-                     x)))
-       imobj))))
-
-(defun pyim-code-search (word scheme-name)
-  "从 SCHEME-NAME 对应的输入法词库中,搜索 WORD 对应的 code.
-
-返回最长的 code."
-  (when (and (stringp word)
-             (> (length word) 0))
-    (let* ((prefix (pyim-scheme-get-option scheme-name :code-prefix))
-           (code
-            (cl-find-if
-             #'(lambda (x)
-                 (equal (substring (or x " ") 0 1) prefix))
-             (sort
-              (cl-copy-list (pyim-dcache-call-api 'search-word-code word))
-              #'(lambda (a b) (> (length a) (length b)))))))
-      (substring (or code " ") 1))))
-
 ;; ** 待输入字符串预览
 (defun pyim-preview-setup-overlay ()
   "设置 pyim 光标处实时预览功能所需要的 overlay.



reply via email to

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