Hiroyuki Komatsu
komat****@users*****
2004年 12月 22日 (水) 03:23:34 JST
Index: prime/uim/prime.scm diff -u prime/uim/prime.scm:1.1.2.9 prime/uim/prime.scm:1.1.2.10 --- prime/uim/prime.scm:1.1.2.9 Mon Dec 13 18:06:53 2004 +++ prime/uim/prime.scm Wed Dec 22 03:23:33 2004 @@ -426,7 +426,7 @@ (print "prime-get-nth-candidate") (if (>= n (prime-get-nr-candidates context)) #f - (nth 1 (nth n (prime-context-candidates context)))))) + (car (nth n (prime-context-candidates context)))))) ;; This returns the data sepecified by key of the N th word. ;; This is called by prime-get-nth-usage and prime-get-nth-annotation. @@ -435,7 +435,7 @@ (if (> n (prime-get-nr-candidates context)) #f (cadr (assoc key - (nth 2 (nth n (prime-context-candidates context)))))))) + (nth 1 (nth n (prime-context-candidates context)))))))) (define prime-get-nth-usage (lambda (context n) @@ -456,6 +456,7 @@ (print "prime-get-current-candidate") (prime-get-nth-candidate context (prime-context-nth context)))) +;; DELETEME: obsolete (define prime-get-candidates! ;;もうちょっと関数名をどうにかしたい (lambda (context preedit prime-context) (print "prime-get-candidates!") @@ -465,6 +466,7 @@ (prime-engine-lookup prime-engine-command-lookup preedit)) )) +;; DELETEME: obsolete (define prime-get-all-candidates! ;;これももうちょっと関数名をどうにかしたい (lambda (context preedit prime-context) (prime-engine-set-context prime-context) @@ -474,6 +476,7 @@ )) + ;;;; ------------------------------------------------------------ ;;;; prime-util: General purpose functions ;;;; ------------------------------------------------------------ @@ -537,6 +540,7 @@ (string-append (prime-util-string-concat arg-list "\t") "\n")) "\n")))) +;; DELETEME: Obsolete function. (define prime-engine-lookup (lambda (command string) (print "prime-engine-lookup") @@ -548,6 +552,40 @@ (prime-util-assoc-list (nthcdr 2 word-data))))) (prime-engine-send-command (list command string))))) +(define prime-engine-conv-predict + (lambda (prime-session) + (prime-engine-conv-convert-internal prime-session "conv_predict"))) + +(define prime-engine-conv-convert + (lambda (prime-session) + (prime-engine-conv-convert-internal prime-session "conv_convert"))) + +(define prime-engine-conv-convert-internal + (lambda (prime-session command) + (let* ((result + (prime-engine-send-command (list command prime-session))) + (index (car result)) + (words (cdr result))) + (mapcar + (lambda (string-line) + (let ((word-data (prime-util-string-split string-line "\t"))) + (list (car word-data) ; literal + (prime-util-assoc-list (cdr word-data))))) + words)))) + +(define prime-engine-conv-select + (lambda (prime-session index-no) + (prime-engine-send-command (list "conv_select" + prime-session + (digit->string index-no))))) + +;; This sends a conv_commit command to the server and returns the commited +;; string. +(define prime-engine-conv-commit + (lambda (prime-session) + (car (prime-engine-send-command (list "conv_commit" prime-session))))) + + (define prime-engine-set-context (lambda (prime-context) (if (string=? prime-context "") @@ -580,6 +618,12 @@ (lambda (prime-session) (prime-engine-send-command (list "edit_erase" prime-session)))) +;; This sends a edit_commit command to the server and returns the commited +;; string. +(define prime-engine-edit-commit + (lambda (prime-session) + (car (prime-engine-send-command (list "edit_commit" prime-session))))) + ;; cursor operations (define prime-engine-edit-cursor-left (lambda (prime-session) @@ -842,11 +886,12 @@ (define prime-command-preedit-commit (lambda (context key key-state) - (let* ((word-committed (prime-preedit-get-string-label context)) - (word-data (list (list "basekey" word-committed) - (list "base" word-committed)))) - (prime-commit-word-data context word-data) - ))) + (prime-commit-preedition context))) +; (let* ((word-committed (prime-preedit-get-string-label context)) +; (word-data (list (list "basekey" word-committed) +; (list "base" word-committed)))) +; (prime-commit-word-data context word-data) +; ))) (define prime-command-register-preedit-commit (lambda (context key key-state) @@ -966,6 +1011,8 @@ ;; This registers the specified word to the PRIME dictionary and ;; reset the status to the normal fund mode. +;; FIXME: Create a new learn_word command on a PRIME server. +;; FIXME: (2004-12-22) <Hiro> (define prime-command-register-fund-commit (lambda (context key key-state) (print "prime-command-register-fund-commit") @@ -1171,6 +1218,7 @@ (prime-context-set-last-word! context "") )) +;; obsolete (define prime-commit-word-data (lambda (context word-data) (print "prime-commit-word-data") @@ -1181,12 +1229,25 @@ (prime-learn-word context word-data) (prime-preedit-reset! context))) +(define prime-commit-preedition + (lambda (context) + (print "prime-commit-preedition") + (let* ((prime-session (prime-context-session-default context)) + (commited-string (prime-engine-edit-commit prime-session))) + (im-commit context commited-string) + (prime-preedit-reset! context)))) + (define prime-commit-candidate - (lambda (context n) + (lambda (context index-no) (print "prime-commit-candidate") - (let ((word-data - (nth 2 (nth n (prime-context-candidates context))))) - (prime-commit-word-data context word-data)))) + (let* ((prime-session (prime-context-session-default context)) + (commited-string (begin + (prime-engine-conv-select prime-session index-no) + (prime-engine-conv-commit prime-session)))) + (im-commit context commited-string) + (prime-preedit-reset! context)))) +; (let ((word-data (nth 1 (nth n (prime-context-candidates context))))) +; (prime-commit-word-data context word-data)))) (define prime-commit-to-register-buffer (lambda (context word) @@ -1233,16 +1294,28 @@ (prime-context-set-state! context 'prime-state-preedit) (prime-context-set-nth! context 0))) +;; This executes 'conv_predict' to predict candidate words and stores them. +(define prime-convert-get-prediction + (lambda (context) + (print "prime-convert-get-prediction") + (prime-context-set-candidates! ;; FIXME: candidates -> conversions + context + (prime-engine-conv-predict (prime-context-session-default context))))) + +;; This executes 'conv_convert' to get candidate words and stores them. +(define prime-convert-get-conversion + (lambda (context) + (print "prime-convert-get-conversion") + (prime-context-set-candidates! ;; FIXME: candidates -> conversions + context + (prime-engine-conv-convert (prime-context-session-default context))))) (define prime-begin-conversion-internal (lambda (context init-idx) (print "prime-begin-conversion-internal") (let ((res)) - (prime-get-all-candidates! context - (prime-preedit-get-string-raw context) - (prime-context-last-word context)) + (prime-convert-get-conversion context) (set! res (prime-get-nth-candidate context init-idx)) - (print res) (if res (begin (prime-context-set-nth! context init-idx) @@ -1397,20 +1470,14 @@ (last-word (prime-context-last-word context))) (cond ((= state 'prime-state-preedit) - (prime-get-candidates! context - (prime-preedit-get-string-raw context) - (prime-context-last-word context))) + (prime-convert-get-prediction context)) ((= state 'prime-state-converting) - (prime-get-all-candidates! context - (prime-preedit-get-string-raw context) - (prime-context-last-word context))) + (prime-convert-get-conversion context)) ((= state 'prime-state-no-preedit) (prime-context-set-candidates! context '())) ))) ((= diff 'preedit) - (prime-get-candidates! context - (prime-preedit-get-string-raw context) - (prime-context-last-word context))) + (prime-convert-get-prediction context)) )))) (define prime-update-candidate-window Index: prime/uim/ChangeLog diff -u prime/uim/ChangeLog:1.1.2.9 prime/uim/ChangeLog:1.1.2.10 --- prime/uim/ChangeLog:1.1.2.9 Mon Dec 13 18:06:53 2004 +++ prime/uim/ChangeLog Wed Dec 22 03:23:33 2004 @@ -1,3 +1,8 @@ +2004-12-22 Hiroyuki Komatsu <komat****@taiya*****> + + * prime.scm: + Implementing functions for the PRIME2 protocol (for PRIME 0.9.4). + 2004-12-13 Hiroyuki Komatsu <komat****@taiya*****> * prime.scm (prime-command-conv-cancel):