Skip to content

Commit 793ae91

Browse files
author
Chen Bin
committed
update pyim.el
1 parent 30d65d1 commit 793ae91

File tree

3 files changed

+57
-71
lines changed

3 files changed

+57
-71
lines changed

site-lisp/pyim/pyim-dcache.el

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
(defvar pyim-dcache-ishortcode2word nil)
1010
(defvar pyim-dcache-update:shortcode2word nil)
1111
(defvar pyim-dcache-update:ishortcode2word nil)
12-
12+
(defvar pyim-dcache-update:icode2word-p nil)
1313

1414
(defun pyim-dcache-get-value-from-file (file)
1515
"读取保存到 FILE 里面的 value."
@@ -341,5 +341,46 @@ code 对应的中文词条了。
341341
(setq result (append result value)))))
342342
`(,@result ,@(pyim-pinyin2cchar-get code t t))))
343343

344+
(defun pyim-dcache-update:icode2word (&optional force)
345+
"对 personal 缓存中的词条进行排序,加载排序后的结果.
346+
347+
在这个过程中使用了 `pyim-dcache-iword2count' 中记录的词频信息。
348+
如果 FORCE 为真,强制排序。"
349+
(interactive)
350+
(when (or force (not pyim-dcache-update:icode2word-p))
351+
(if (pyim-use-emacs-thread-p)
352+
(make-thread
353+
`(lambda ()
354+
(maphash
355+
#'(lambda (key value)
356+
(puthash key (pyim-dcache-sort-words value)
357+
pyim-dcache-icode2word))
358+
pyim-dcache-icode2word)
359+
(pyim-dcache-save-variable 'pyim-dcache-icode2word)
360+
(setq pyim-dcache-update:icode2word-p t)))
361+
(async-start
362+
`(lambda ()
363+
,(async-inject-variables "^load-path$")
364+
,(async-inject-variables "^exec-path$")
365+
,(async-inject-variables "^pyim-.+?directory$")
366+
(require 'pyim)
367+
(pyim-hashtable-set-variable 'pyim-dcache-icode2word)
368+
(pyim-hashtable-set-variable 'pyim-iword2count)
369+
(maphash
370+
#'(lambda (key value)
371+
(puthash key (pyim-dcache-sort-words value)
372+
pyim-dcache-icode2word))
373+
pyim-dcache-icode2word)
374+
(pyim-dcache-save-variable 'pyim-dcache-icode2word)
375+
nil)
376+
`(lambda (result)
377+
(setq pyim-dcache-update:icode2word-p t)
378+
(unless (eq pyim-backend 'pyim-dregcache)
379+
(pyim-hashtable-set-variable 'pyim-dcache-icode2word t)))))))
380+
381+
(defun pyim-dcache-update-personal-words (&optional force)
382+
(pyim-dcache-update:icode2word force)
383+
(pyim-dcache-update:ishortcode2word force))
384+
344385
(provide 'pyim-dcache)
345386
;;; pyim-dcache.el ends here

site-lisp/pyim/pyim-dregcache.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
(require 'pyim-sdk)
12
(defvar pyim-dregcache-cache nil)
23
(defvar pyim-dregcache-icode2word nil)
34
(defvar pyim-dregcache-dicts-md5 nil)
@@ -169,6 +170,13 @@ CACHE-LIST 只是符号而已,并不代表真实的缓存数据."
169170
(setq start (+ start 2 (length code) (length word))))))
170171
`(,@result ,@(pyim-pinyin2cchar-get code t t)))))
171172

173+
(defun pyim-dregcache-update-personal-words (&optional force)
174+
"Could update iword2count. TODO!"
175+
)
176+
177+
(defun pyim-dregcache-update:shortcode2word (&optional restart)
178+
"Dummy function."
179+
)
172180
(provide 'pyim-dregcache)
173181
;;; pyim-dregcache.el ends here
174182

site-lisp/pyim/pyim.el

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,6 @@ If you don't like this funciton, set the variable to nil")
12141214
(defvar pyim-cchar2pinyin-cache nil
12151215
"汉字转拼音功能需要的变量.")
12161216

1217-
(defvar pyim-update:icode2word-p nil)
1218-
12191217
(defvar pyim-auto-update t
12201218
"是否自动创建和更新词库对应的 cache 文件.
12211219
@@ -1425,10 +1423,7 @@ pyim 使用函数 `pyim-start' 启动输入法的时候,会将变量
14251423
(pyim-init-variables)
14261424

14271425
(when pyim-auto-update
1428-
;; 使用 pyim-iword2count 中的信息对 personal 缓存中的词频进行调整。
1429-
(pyim-update:icode2word restart)
1430-
;; 创建简拼缓存, 比如 "ni-hao" -> "n-h"
1431-
(pyim-dcache-update:ishortcode2word restart))
1426+
(funcall (pyim-backend-api "update-personal-words") restart))
14321427

14331428
(pyim-cchar2pinyin-cache-create)
14341429
(pyim-pinyin2cchar-cache-create)
@@ -1438,7 +1433,7 @@ pyim 使用函数 `pyim-start' 启动输入法的时候,会将变量
14381433
;; 如果 `pyim-dicts' 有变化,重新生成 `pyim-dcache-code2word' 缓存。
14391434
(pyim-update:code2word refresh-common-cache)
14401435
;; 这个命令 *当前* 主要用于五笔输入法。
1441-
(pyim-dcache-update:shortcode2word restart))
1436+
(funcall (pyim-backend-api "update:shortcode2word") restart))
14421437

14431438
(unless (member 'pyim-save-caches kill-emacs-hook)
14441439
(add-to-list 'kill-emacs-hook 'pyim-save-caches))
@@ -1501,7 +1496,7 @@ pyim 使用函数 `pyim-start' 启动输入法的时候,会将变量
15011496
"Get backend API from API-NAME."
15021497
;; make sure the backend is load
15031498
(unless (featurep pyim-backend) (require pyim-backend))
1504-
(intern (concat (symbol-name pyim-backend) api-name)))
1499+
(intern (concat (symbol-name pyim-backend) "-" api-name)))
15051500

15061501
(defun pyim-update:code2word (&optional force)
15071502
"读取并加载词库.
@@ -1514,65 +1509,8 @@ pyim 使用函数 `pyim-start' 启动输入法的时候,会将变量
15141509
(unless (plist-get x :disable)
15151510
(plist-get x :file)))
15161511
`(,@pyim-dicts ,@pyim-extra-dicts)))
1517-
(dicts-md5 (pyim-create-dicts-md5 dict-files))
1518-
(fn (pyim-backend-api "-update:code2word")))
1519-
(cond
1520-
((string= pyim-backend "pyim-dregcache")
1521-
(message "====hello")
1522-
(funcall fn dict-files dicts-md5 force))
1523-
(t
1524-
(pyim-dcache-update:code2word dict-files dicts-md5 force)))))
1525-
1526-
(defun pyim-update:icode2word (&optional force)
1527-
"对 personal 缓存中的词条进行排序,加载排序后的结果.
1528-
1529-
在这个过程中使用了 `pyim-dcache-iword2count' 中记录的词频信息。
1530-
如果 FORCE 为真,强制排序。"
1531-
(interactive)
1532-
(when (or force (not pyim-update:icode2word-p))
1533-
(if (pyim-use-emacs-thread-p)
1534-
(make-thread
1535-
`(lambda ()
1536-
(cond
1537-
((eq pyim-backend 'pyim-dregcache)
1538-
(pyim-dregcache-sort-icode2word)
1539-
(pyim-dcache-save-variable 'pyim-dregcache-icode2word))
1540-
(t
1541-
(maphash
1542-
#'(lambda (key value)
1543-
(puthash key (pyim-dcache-sort-words value)
1544-
pyim-dcache-icode2word))
1545-
pyim-dcache-icode2word)
1546-
(pyim-dcache-save-variable 'pyim-dcache-icode2word)))
1547-
1548-
(setq pyim-update:icode2word-p t)))
1549-
(async-start
1550-
`(lambda ()
1551-
,(async-inject-variables "^load-path$")
1552-
,(async-inject-variables "^exec-path$")
1553-
,(async-inject-variables "^pyim-.+?directory$")
1554-
(require 'pyim)
1555-
(cond
1556-
((eq pyim-backend 'pyim-dregcache)
1557-
1558-
(pyim-dcache-save-variable 'pyim-dregcache-icode2word)
1559-
(pyim-hashtable-set-variable 'pyim-iword2count)
1560-
(pyim-dregcache-sort-icode2word)
1561-
(pyim-dcache-save-variable 'pyim-dregcache-icode2word))
1562-
(t
1563-
(pyim-hashtable-set-variable 'pyim-dcache-icode2word)
1564-
(pyim-hashtable-set-variable 'pyim-iword2count)
1565-
(maphash
1566-
#'(lambda (key value)
1567-
(puthash key (pyim-dcache-sort-words value)
1568-
pyim-dcache-icode2word))
1569-
pyim-dcache-icode2word)
1570-
(pyim-dcache-save-variable 'pyim-dcache-icode2word)))
1571-
nil)
1572-
`(lambda (result)
1573-
(setq pyim-update:icode2word-p t)
1574-
(unless (eq pyim-backend 'pyim-dregcache)
1575-
(pyim-hashtable-set-variable 'pyim-dcache-icode2word t)))))))
1512+
(dicts-md5 (pyim-create-dicts-md5 dict-files)))
1513+
(funcall (pyim-backend-api "update:code2word") dict-files dicts-md5 force)))
15761514

15771515
(defun pyim-init-variables ()
15781516
"初始化 dcache 缓存相关变量."
@@ -1690,9 +1628,8 @@ MERGE-METHOD 是一个函数,这个函数需要两个数字参数,代表
16901628
;; 不存在此问题。
16911629
(unless pyim-prefer-emacs-thread
16921630
(pyim-save-caches))
1693-
;; 更新相关的 dcache
1694-
(pyim-update:icode2word t)
1695-
(pyim-dcache-update:ishortcode2word t)
1631+
;; 更新相关的 cache
1632+
(funcall (pyim-backend-api "update-personal-words") t)
16961633

16971634
(message "pyim: 词条相关信息导入完成!"))
16981635

0 commit comments

Comments
 (0)