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

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

[elpa] externals/pyim 90fdc99: pyim-*-update-iword2count: remove prepend


From: ELPA Syncer
Subject: [elpa] externals/pyim 90fdc99: pyim-*-update-iword2count: remove prepend argument.
Date: Tue, 14 Dec 2021 05:57:31 -0500 (EST)

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

    pyim-*-update-iword2count: remove prepend argument.
    
        * tests/pyim-tests.el (pyim-tests-pyim-dhashcache-update-iword2count):
    
        * pyim-process.el (pyim-process-create-word):
    
        * pyim-dregcache.el (pyim-dregcache-update-iword2count):
    
        * pyim-dhashcache.el (pyim-dhashcache-update-iword2count):
    
        * pyim-dcache.el (pyim-dcache-update-wordcount):
---
 pyim-dcache.el      | 11 ++++++++---
 pyim-dhashcache.el  |  4 ++--
 pyim-dregcache.el   |  2 +-
 pyim-process.el     |  2 +-
 tests/pyim-tests.el |  6 ++++--
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/pyim-dcache.el b/pyim-dcache.el
index dbd71f4..b061e72 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -224,9 +224,14 @@ non-nil,文件存在时将会提示用户是否覆盖,默认为覆盖模式"
                     (list version file (nth 5 (file-attributes file 'string))))
                   dict-files)))))
 
-(defun pyim-dcache-update-wordcount (word &optional prepend wordcount-handler)
-  "保存词频到缓存."
-  (pyim-dcache-call-api 'update-iword2count word prepend wordcount-handler))
+(defun pyim-dcache-update-wordcount (word &optional wordcount-handler)
+  "保存 WORD 词频.
+
+1. 如果 WORDCOUNT-HANDLER 是一个函数:那么其返回值将作为词频保存,
+   参数为原有词频。
+2. 如果 WORDCOUNT-HANDLER 是一个数值:那么这个数值直接作为词频保存。
+3. 如果 WORDCOUNT-HANDLER 为其他值:词频不变."
+  (pyim-dcache-call-api 'update-iword2count word wordcount-handler))
 
 ;; ** Dcache 加词功能
 (defun pyim-dcache-insert-word (word code prepend)
diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el
index aae3dc0..adfe9d3 100644
--- a/pyim-dhashcache.el
+++ b/pyim-dhashcache.el
@@ -416,7 +416,7 @@ code 对应的中文词条了。
        (setq ,new-value (progn ,@body))
        (puthash ,key ,new-value ,table))))
 
-(defun pyim-dhashcache-update-iword2count (word &optional _prepend 
wordcount-handler)
+(defun pyim-dhashcache-update-iword2count (word &optional wordcount-handler)
   "保存词频到缓存."
   (pyim-dhashcache-put
     pyim-dhashcache-iword2count word
@@ -425,7 +425,7 @@ code 对应的中文词条了。
       (funcall wordcount-handler orig-value))
      ((numberp wordcount-handler)
       wordcount-handler)
-     (t (+ (or orig-value 0) 1)))))
+     (t orig-value))))
 
 (defun pyim-dhashcache-delete-word (word)
   "将中文词条 WORD 从个人词库中删除"
diff --git a/pyim-dregcache.el b/pyim-dregcache.el
index 667a1ea..bb93515 100644
--- a/pyim-dregcache.el
+++ b/pyim-dregcache.el
@@ -352,7 +352,7 @@ DICT-FILES 是词库文件列表. DICTS-MD5 是词库的MD5校验码.
   "TODO"
   )
 
-(defun pyim-dregcache-update-iword2count (word &optional _prepend 
wordcount-handler)
+(defun pyim-dregcache-update-iword2count (word &optional wordcount-handler)
   "保存词频到缓存."
   (when pyim-debug (message "pyim-dregcache-update-iword2count. word=%s" word))
   (let* ((orig-value (gethash word pyim-dregcache-iword2count))
diff --git a/pyim-process.el b/pyim-process.el
index f793118..f59422c 100644
--- a/pyim-process.el
+++ b/pyim-process.el
@@ -557,7 +557,7 @@ BUG:拼音无法有效地处理多音字。"
                    (or criteria pyim-cstring-to-code-criteria))))
       ;; 保存对应词条的词频
       (when (> (length word) 0)
-        (pyim-dcache-update-wordcount word prepend wordcount-handler))
+        (pyim-dcache-update-wordcount word (or wordcount-handler #'1+)))
       ;; 添加词条到个人缓存
       (dolist (code codes)
         (unless (pyim-string-match-p "[^ a-z-]" code)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 5824c05..72b15a0 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -711,10 +711,12 @@ zuo-zuo-you-mang 作作有芒")
   (let ((pyim-dhashcache-iword2count (make-hash-table :test #'equal)))
     (puthash "你好" 1 pyim-dhashcache-iword2count)
     (pyim-dhashcache-update-iword2count "你好")
+    (should (equal (gethash "你好" pyim-dhashcache-iword2count) 1))
+    (pyim-dhashcache-update-iword2count "你好" #'1+)
     (should (equal (gethash "你好" pyim-dhashcache-iword2count) 2))
-    (pyim-dhashcache-update-iword2count "你好" nil 10)
+    (pyim-dhashcache-update-iword2count "你好" 10)
     (should (equal (gethash "你好" pyim-dhashcache-iword2count) 10))
-    (pyim-dhashcache-update-iword2count "你好" nil (lambda (x) (* x 2)))
+    (pyim-dhashcache-update-iword2count "你好" (lambda (x) (* x 2)))
     (should (equal (gethash "你好" pyim-dhashcache-iword2count) 20))))
 
 (ert-deftest pyim-tests-pyim-dhashcache-export ()



reply via email to

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