branch: externals/pyim commit b22b27a13103a1c4c81a544291b07d32810dbbce Author: Feng Shu <tuma...@163.com> Commit: Feng Shu <tuma...@163.com>
Update pyim-dcache-get docstring --- pyim-dcache.el | 22 ++++++++++++++++++---- pyim-dhashcache.el | 16 ++++++---------- pyim-dregcache.el | 18 ++++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/pyim-dcache.el b/pyim-dcache.el index 0d3a011f5b..063d8fd5c9 100644 --- a/pyim-dcache.el +++ b/pyim-dcache.el @@ -197,11 +197,25 @@ AUTO-BACKUP-THRESHOLD 倍, 那么原值将自动备份到 FILE 对应的备份 (pyim-dcache-load-backend)) ;; ** Dcache 检索词条功能接口 -(cl-defgeneric pyim-dcache-get (_code &optional _from) - "从 FROM 对应的 dcache 中搜索 CODE, 得到对应的词条. +(cl-defgeneric pyim-dcache-get (_key &optional _from) + "从 FROM 中搜索 KEY, 得到对应的取值. -当词库文件加载完成后,pyim 就可以用这个函数从词库缓存中搜索某个 -code 对应的中文词条了." +FORM 是一个包含下面几个符号的 list, 每个符号代表一种类型的 +dcache. + +* 编码 -> 词条 +1. code2word 用编码搜索词条 +3. icode2word 用编码搜索个人词条 +4. ishortcode2word 用简码搜索个人词条 +7. shortcode2word 用简码搜索个人词条 + +* 词条 -> 编码 +2. word2code 用词条搜索编码 + +* 词条 -> 词频 +3. iword2count 用个人词条搜索编码 +4. iword2count-recent-10-words 搜索最近输入10个词的词频 +5. iword2count-recent-50-words 搜索最近输入50个词的词频" nil) (cl-defmethod pyim-dcache-get :before (_code &optional _from) diff --git a/pyim-dhashcache.el b/pyim-dhashcache.el index 1a4250ec56..68a6a86380 100644 --- a/pyim-dhashcache.el +++ b/pyim-dhashcache.el @@ -106,16 +106,12 @@ ;; ** 从 dhashcache 搜索词条相关函数 (cl-defmethod pyim-dcache-get - (code &context ((pyim-dcache-backend) (eql pyim-dhashcache)) - &optional from) - "从 FROM 对应的 dcaches 中搜索 CODE, 得到对应的词条. + (key &context ((pyim-dcache-backend) (eql pyim-dhashcache)) + &optional from) + "从 FROM 中搜索 key, 得到对应的结果。 -当词库文件加载完成后,pyim 就可以用这个函数从词库缓存中搜索某个 -code 对应的中文词条了。 - -如果 FROM 为 nil, 则默认搜索 `pyim-dhashcache-icode2word' 和 -`pyim-dhashcache-code2word' 两个 dcache." - (when code +用于 pyim-dhashcache 类型的 dcache 后端。" + (when key (let* ((caches (mapcar (lambda (x) (intern (concat "pyim-dhashcache-" (symbol-name x)))) (or (and from @@ -126,7 +122,7 @@ code 对应的中文词条了。 result) (dolist (cache caches) (let* ((cache (ignore-errors (symbol-value cache))) - (value (and cache (gethash code cache)))) + (value (and cache (gethash key cache)))) ;; 处理 iword2count. (unless (listp value) (setq value (list value))) diff --git a/pyim-dregcache.el b/pyim-dregcache.el index e5418a745f..c4e492297c 100644 --- a/pyim-dregcache.el +++ b/pyim-dregcache.el @@ -59,13 +59,15 @@ ;; ** 从 dregcache 搜索词条相关函数 (cl-defmethod pyim-dcache-get - (code &context ((pyim-dcache-backend) (eql pyim-dregcache)) - &optional from) - "从 `pyim-dregcache-cache' 搜索 CODE, 得到对应的词条." - (when code + (key &context ((pyim-dcache-backend) (eql pyim-dregcache)) + &optional from) + "从 FROM 中搜索 KEY, 得到对应的结果。 + +用于 pyim-dregcache 类型的 dcache 后端。" + (when key (cond ((or (memq 'icode2word from) (memq 'ishortcode2word from)) - (pyim-dregcache-get-icode2word-ishortcode2word code)) + (pyim-dregcache-get-icode2word-ishortcode2word key)) ;; FIXME: pyim-dregcache 暂时不支持 iword2count-recent-10-words 和 ;; iword2count-recent-50-words. ((or (memq 'iword2count-recent-10-words from) @@ -74,12 +76,12 @@ (t (let ((dict-files (pyim-dregcache-all-dict-files)) result) - (when pyim-debug (message "pyim-dregcache-get is called. code=%s" code)) + (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 code file-info))) - (setq result (append (pyim-dregcache-get-1 content code) result))))) + (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))))))