開發了新的 windows 輸入法架構 - PIME

1,627 views
Skip to first unread message

PCMan

unread,
Aug 8, 2015, 7:11:52 AM8/8/15
to chewin...@googlegroups.com
Hi,
先前移植新酷音輸入法到 Windows TSF 之後
深感全用 C++/COM 撰寫 dll 的開發方式很困難
很難除錯,也不好維護和修改
於是就 fork 以原 windows-chewing-tsf 內的 libIME
為基礎,開發了新的專案 - PIME (python IME)
顧名思義,可以使用 python 語言開發中文輸入法
TSF 的 dll 部份仍然是以 C++ 和 COM 撰寫,
但是以 IPC 機制和 python 的輸入法 server 相接
如此實做輸入法,比原來簡單非常多
只要會 python,不需要理解 C++/COM/TSF 等細節
可以專注在演算法和資料處理、甚至是自然語言處理
應該對於未來的輸入法開發很有幫助,目前已支援 windows 10
8/15 將會在 COSCUP 2015 發表
希望尋找有興趣的朋友一起來開發,補完剩下的部份
Thanks!

PCMan

unread,
Aug 9, 2015, 11:49:49 AM8/9/15
to chewin...@googlegroups.com
今天花了點時間,把新酷音輸入法也移植到 PIME 架構下了
目前還沒完成,只有基本功能,但已經可以打字 (還不能選字)
之後新酷音 windows 版本將可以使用 python 來開發和維護
Cheers!

詹博丞

unread,
Aug 9, 2015, 12:16:56 PM8/9/15
to chewin...@googlegroups.com
Dear all,

> 今天花了點時間,把新酷音輸入法也移植到 PIME 架構下了
> 目前還沒完成,只有基本功能,但已經可以打字 (還不能選字)
> 之後新酷音 windows 版本將可以使用 python 來開發和維護

想請教一下各位,目前 contrib/python 裡面的 code 似乎有點老舊 (還在用 zuin 為名的 API)
是否有計畫維修一下那段 code? 以下尚有二個相關問題:

1. API 分 const char* (static) 與 char* 兩種,但寫到 python 都是 .restype = c_char_p
像 chewing_get_KBString 沒有 static 版本,設 .restype = c_char_p 看不出 runtime error
但是 python 裡面並沒有 call chewing_free 如說明文件所指示的,會不會導致 memory leak?
這點我一直無法查證,還請 python 有經驗的夥伴協助!

2. chewing_bopomofo_String_static 沒找到對應之 non-static 版本,各位覺得是否也要補回去?

如上的問題,多謝!

ChangZhuo Chen (陳昌倬)

unread,
Aug 10, 2015, 12:42:05 AM8/10/15
to chewin...@googlegroups.com
On Mon, Aug 10, 2015 at 12:16:55AM +0800, 詹博丞 wrote:
> Dear all,
>
> > 今天花了點時間,把新酷音輸入法也移植到 PIME 架構下了
> > 目前還沒完成,只有基本功能,但已經可以打字 (還不能選字)
> > 之後新酷音 windows 版本將可以使用 python 來開發和維護
>
> 想請教一下各位,目前 contrib/python 裡面的 code 似乎有點老舊 (還在用 zuin 為名的 API)
> 是否有計畫維修一下那段 code? 以下尚有二個相關問題:
>
> 1. API 分 const char* (static) 與 char* 兩種,但寫到 python 都是 .restype = c_char_p
> 像 chewing_get_KBString 沒有 static 版本,設 .restype = c_char_p 看不出 runtime error
> 但是 python 裡面並沒有 call chewing_free 如說明文件所指示的,會不會導致 memory leak?
> 這點我一直無法查證,還請 python 有經驗的夥伴協助!

會造成 memory leak。這裡應該要用 static API。

>
> 2. chewing_bopomofo_String_static 沒找到對應之 non-static 版本,各位覺得是否也要補回去?

No

如果使用者需要 non-static,可以直接用 strdup(chewing_bopomofo_String_static)。

>
> 如上的問題,多謝!
>
> --
> 您已訂閱「Google 網上論壇」的「Chewing IM Development」群組,因此我們特別傳送這封郵件通知您。
> 如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 chewing-deve...@googlegroups.com
> 如要在此群組張貼留言,請傳送電子郵件至 chewin...@googlegroups.com
> 請前往以下網址造訪這個群組:http://groups.google.com/group/chewing-devel
> 如需更多選項,請前往:https://groups.google.com/d/optout

--
ChangZhuo Chen (陳昌倬) <czc...@gmail.com>
http://czchen.info/
Key fingerprint = EC9F 905D 866D BE46 A896 C827 BE0C 9242 03F4 552D
signature.asc

詹博丞

unread,
Aug 10, 2015, 2:15:01 PM8/10/15
to chewin...@googlegroups.com
Dear all,

回應 czchen 以及增加二個 issue


>> 像 chewing_get_KBString 沒有 static 版本,設 .restype = c_char_p 看不出 runtime error
>> 但是 python 裡面並沒有 call chewing_free 如說明文件所指示的,會不會導致 memory leak?
> 會造成 memory leak。這裡應該要用 static API。
>
>>
>> 2. chewing_bopomofo_String_static 沒找到對應之 non-static 版本,各位覺得是否也要補回去?
>
> No
>
> 如果使用者需要 non-static,可以直接用 strdup(chewing_bopomofo_String_static)。

依照現行 chewing.py 寫法,全部都 call non-static API... 這樣說來就全部都是 memory leak...

如果對 non-static API 的需求全部都建議用 strdup 取代,以後是否要將 static 的分別除去,只要給 const
char* 版本的 API 就好?

(不過這很大改變,幾乎整個 .h 和文件都要整修...)

Issues:

1.
chewing.py 用 __dict__ 檢驗 attribute 存在,根據 [0] 這方法 generally speaking
是不大正確的,我想建議改為 hasattr+getattr 的方式來檢驗 (see patch)

2.
用 chewing.dll 當預設的 dll name, 想請教 mingw 編譯出來該如何讓檔名是 chewing.dll?
目前 cmake+mingw 的產品為 libchewing.dll

Thanks!

[0] http://stackoverflow.com/questions/9748678/which-is-the-best-way-to-check-for-the-existence-of-an-attribute
0001-Detect-attribute-existence-by-hasattr-not-__dict__.patch

PCMan

unread,
Aug 16, 2015, 1:13:33 PM8/16/15
to chewin...@googlegroups.com
COSCUP 2015 會後相關資料釋出

編譯好的安裝程式,可供測試:
(使用前需先安裝 python 3 和 python 的 pywin32 套件):
注意:目前安裝好後 python server 並不會自動啟動,所以無法打字,需要自己手動執行 server.py 才能進行測試

簡報:

blog post:

Cheers!

Rifur

unread,
Aug 17, 2015, 10:50:18 AM8/17/15
to chewin...@googlegroups.com
Hi, 
我在 Windows 8 環境執行 PIME,發現原本 input_methods/chewing 目錄中的 chewing.dll 會跳出「msvcr120d.dll 找不到」的錯誤訊息,所以嘗試重新編譯 libchewing。編譯過程的筆記,我寫在 hackpad 中: https://hackpad.com/-PIME-Python-IME--gwO5QBZB1wD

另外,發現當 server.py 開著一段時間,就會跳出 client disconnected 的錯誤,traceback 訊息記錄在 hackpad 中。


--
這是 Google 網上論壇針對「Chewing IM Development」群組發送的訂閱通知郵件。
如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 chewing-deve...@googlegroups.com
如要在這個群組張貼留言,請傳送電子郵件到 chewin...@googlegroups.com

PCMan

unread,
Aug 19, 2015, 10:45:16 PM8/19/15
to chewin...@googlegroups.com
2015-08-11 2:14 GMT+08:00 詹博丞 <school...@gmail.com>:
Dear all,

回應 czchen 以及增加二個 issue


>> 像 chewing_get_KBString 沒有 static 版本,設 .restype = c_char_p 看不出 runtime error
>> 但是 python 裡面並沒有 call chewing_free 如說明文件所指示的,會不會導致 memory leak?
> 會造成 memory leak。這裡應該要用 static API。
>
>>
>> 2. chewing_bopomofo_String_static 沒找到對應之 non-static 版本,各位覺得是否也要補回去?
>
> No
>
> 如果使用者需要 non-static,可以直接用 strdup(chewing_bopomofo_String_static)。

依照現行 chewing.py 寫法,全部都 call non-static API... 這樣說來就全部都是 memory leak...

如果對 non-static API 的需求全部都建議用 strdup 取代,以後是否要將 static 的分別除去,只要給 const
char* 版本的 API 就好?

(不過這很大改變,幾乎整個 .h 和文件都要整修...)

Issues:

1.
 chewing.py 用 __dict__ 檢驗 attribute 存在,根據 [0] 這方法 generally speaking
是不大正確的,我想建議改為 hasattr+getattr 的方式來檢驗 (see patch)

看起來沒有大問題,測試過可以正常運作,我剛 merge 了這個 patch
Thanks!


2.
用 chewing.dll 當預設的 dll name, 想請教 mingw 編譯出來該如何讓檔名是 chewing.dll?
目前 cmake+mingw 的產品為 libchewing.dll

Thanks!

[0] http://stackoverflow.com/questions/9748678/which-is-the-best-way-to-check-for-the-existence-of-an-attribute

PCMan

unread,
Aug 19, 2015, 10:47:42 PM8/19/15
to chewin...@googlegroups.com
2015-08-17 22:50 GMT+08:00 Rifur <rifu...@gmail.com>:
Hi, 
我在 Windows 8 環境執行 PIME,發現原本 input_methods/chewing 目錄中的 chewing.dll 會跳出「msvcr120d.dll 找不到」的錯誤訊息,所以嘗試重新編譯 libchewing。編譯過程的筆記,我寫在 hackpad 中: https://hackpad.com/-PIME-Python-IME--gwO5QBZB1wD

另外,發現當 server.py 開著一段時間,就會跳出 client disconnected 的錯誤,traceback 訊息記錄在 hackpad 中。


多謝測試,
libchewing  的問題,可以調整編譯參數讓他 statically link 到 VC++ runtime
就可以解決,這需要改 cmake,我之後可以幫忙看這部份
至於 server 開一段時間就會 disconnected 不確定原因
我這裡無法重現
請問一開始是可以輸入後來才變不行,還是一開始就無法輸入?
另外酷音的問題比較複雜
是否方便先測試「喵喵輸入法」?
喵喵輸入法是一個沒什麼用處的 minimal test case,只能輸入「喵」這個字
實做簡單好除錯
謝謝
Reply all
Reply to author
Forward
0 new messages