[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 37168b5ca2 1/3: pyim-cstring--find-duoyinzi-pinyin
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 37168b5ca2 1/3: pyim-cstring--find-duoyinzi-pinyin -> pyim-pymap-possible-cchar-pinyin |
Date: |
Mon, 16 Jan 2023 02:58:09 -0500 (EST) |
branch: externals/pyim
commit 37168b5ca23d719fb2e042d5d7aa1cff9404d96e
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
pyim-cstring--find-duoyinzi-pinyin -> pyim-pymap-possible-cchar-pinyin
---
pyim-cstring.el | 35 +++++++++--------------------------
pyim-pymap.el | 20 ++++++++++++++++++++
tests/pyim-tests.el | 6 +++---
3 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/pyim-cstring.el b/pyim-cstring.el
index ca0cde4ab3..a0cb3b2c5c 100644
--- a/pyim-cstring.el
+++ b/pyim-cstring.el
@@ -154,14 +154,14 @@ BUG: 当 STRING 中包含其它标点符号,并且设置 SEPERATER 时,结
(dotimes (i n)
(let ((pinyins (nth i pinyins-list))
;; 当前位置对应的汉字和位置前后汉字组成的两字词语。
- (words (list (when (>= (- i 1) 0)
- (concat (nth (- i 1) string-parts)
- (nth i string-parts)))
- (when (< (+ i 1) n)
- (concat (nth i string-parts)
- (nth (+ i 1) string-parts)))))
+ (words-list (list (when (>= (- i 1) 0)
+ (concat (nth (- i 1) string-parts)
+ (nth i string-parts)))
+ (when (< (+ i 1) n)
+ (concat (nth i string-parts)
+ (nth (+ i 1) string-parts)))))
;; 当前位置汉字
- (char (list (nth i string-parts))))
+ (char-list (list (nth i string-parts))))
(if (= (length pinyins) 1)
(push pinyins output)
(let ((py-adjusted
@@ -169,14 +169,14 @@ BUG: 当 STRING 中包含其它标点符号,并且设置 SEPERATER 时,结
;; NOTE: 多音字校正规则:
;; 1. 首先通过 pyim 自带的多音字词语来校正,具体见:
;; `pyim-pymap-duoyinzi-words'
- (pyim-cstring--find-duoyinzi-pinyin pinyins words)
+ (pyim-pymap-possible-cchar-pinyin pinyins words-list)
;; 2. 然后通过 pyim 自带的多音字常用读音进行校正, 具体见:
;; `pyim-pymap-duoyinzi-chars',
;;
;; NOTE: 如果用户想要使用某个汉字的偏僻读音,这样处理是有问题
;; 的,但大多数情况我们还是使用汉字的常用读音,让偏僻的读音进
;; 入用户个人词库似乎也没有什么好处。
- (pyim-cstring--find-duoyinzi-pinyin pinyins char t))))
+ (pyim-pymap-possible-cchar-pinyin pinyins char-list t))))
;; 3. 如果多音字校正没有结果,就使用未校正的信息。
(push (if py-adjusted
(list py-adjusted)
@@ -184,23 +184,6 @@ BUG: 当 STRING 中包含其它标点符号,并且设置 SEPERATER 时,结
output)))))
(reverse output)))
-(defun pyim-cstring--find-duoyinzi-pinyin (pinyins words &optional search-char)
- "寻找一个汉字当前最可能的读音。
-
-以 (行) 作为例子:
-1. PINYINS: 此汉字所有的读音组成的列表,比如: (xing hang)
-2. WORDS: 此汉字本身或者和前后汉字组成的词语,比如: (银行 行业)
-3. SEARCH-CHAR: 如果仅仅搜索汉字本身,就设置为 t, 此处设置为 nil.
-4. 返回结果: hang"
- (cl-find-if
- (lambda (pinyin)
- (when-let ((x (string-join (pyim-pymap-py2duoyinzi-get pinyin
search-char) "-")))
- (cl-some
- (lambda (reg)
- (and reg (string-match-p reg x)))
- words)))
- pinyins))
-
;;;###autoload
(defun pyim-cstring-to-pinyin-simple (string &optional shou-zi-mu separator
return-list)
"简化版的 `pyim-cstring-to-pinyin', 不处理多音字。"
diff --git a/pyim-pymap.el b/pyim-pymap.el
index 8bf2614f54..d4f5f8e4f7 100644
--- a/pyim-pymap.el
+++ b/pyim-pymap.el
@@ -1062,6 +1062,26 @@ pyim 在特定的时候需要读取一个汉字的拼音,这个工作由此完
(when (= (length key) 1)
(gethash key pyim-pymap--cchar2py-cache))))
+(defun pyim-pymap-possible-cchar-pinyin (cchar-pinyins cchar-words &optional
search-char)
+ "寻找一个汉字当前最可能的读音。
+
+以 (行) 作为例子:
+1. PINYINS: 此汉字所有的读音组成的列表,比如: (xing hang)
+2. WORDS: 此汉字本身或者和前后汉字组成的词语,比如: (银行 行业)
+3. SEARCH-CHAR: 如果仅仅搜索汉字本身,就设置为 t, 此处设置为 nil.
+4. 返回结果: hang"
+ (cl-find-if
+ (lambda (pinyin)
+ (when-let ((x (string-join
+ (pyim-pymap-py2duoyinzi-get
+ pinyin search-char)
+ "-")))
+ (cl-some
+ (lambda (word)
+ (and word (string-match-p word x)))
+ cchar-words)))
+ cchar-pinyins))
+
(defun pyim-pymap-py2duoyinzi-get (pinyin &optional return-chars)
"获取与 PINYIN 想匹配的多音字(词)。"
(pyim-pymap--py2duoyinzi-cache-create)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index d926c72e74..987efe94f8 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -796,13 +796,13 @@
(ert-deftest pyim-tests-pyim-cstring-to-pinyin ()
- (should (equal (pyim-cstring--find-duoyinzi-pinyin
+ (should (equal (pyim-pymap-possible-cchar-pinyin
'("xing" "hang") '("银行"))
"hang"))
- (should-not (pyim-cstring--find-duoyinzi-pinyin
+ (should-not (pyim-pymap-possible-cchar-pinyin
'("xing" "hang") '("不行" "行为")))
- (should (equal (pyim-cstring--find-duoyinzi-pinyin
+ (should (equal (pyim-pymap-possible-cchar-pinyin
'("bu" "pi") '("不") t)
"bu"))