[uim-commit] r916 - branches/composer/scm
yamaken at freedesktop.org
yamaken at freedesktop.org
Sat Jul 2 07:15:56 PDT 2005
Author: yamaken
Date: 2005-07-02 07:15:42 -0700 (Sat, 02 Jul 2005)
New Revision: 916
Modified:
branches/composer/scm/segmental-converter.scm
Log:
* This commit adds partial commit and candidate index handlings
features to the segconv-engine interface. anthy-engine has fully
implemented it and canna-engine is not yet.
* scm/segmental-converter.scm
- (segconv-engine-method-table-spec, segconv-engine-spec,
anthy-engine-spec, canna-engine-spec): Rename to *-rec-spec
- (segconv-engine-method-table-rec-spec):
* Renamed from segconv-engine-method-table-spec
* Remove commit-segment! and nth-candidate
* Add commit!, candidate-index, set-candidate-index!, candidate
methods
- (segconv-engine-method-table, segconv-engine-rec-spec): Reflect
above changes
- (segconv-engine-set-source-str!): Replace the arg 'str' with 'utexts'
- (segconv-engine-commit!, segconv-engine-candidate-index,
segconv-engine-set-candidate-index!, segconv-engine-candidate):
New procedure
- (segconv-engine-commit-segment!, segconv-engine-nth-candidate):
Removed
- (anthy-default-locale, anthy-intrinsic-transposition-hiragana?,
anthy-intrinsic-transposition-katakana?,
anthy-intrinsic-transposition-halfkana?,
anthy-intrinsic-transposition-half-alnum?,
anthy-intrinsic-transposition-full-alnum?): New variable
- (anthy-engine-finalize!, anthy-engine-reset!,
anthy-engine-set-source-str!, anthy-engine-nr-segments,
anthy-engine-segment-source-length, anthy-engine-resize-segment!,
anthy-engine-nr-candidates):
* Add partial commit and candidate index handlings features
* Replace raw string for input and output with utexts to support
per-string locale and arbitrary text properties such as ruby
- (anthy-engine-commit!, anthy-engine-candidate-index,
anthy-engine-set-candidate-index!, anthy-engine-candidate,
anthy-engine-nr-committed-segments,
anthy-engine-internal-seg-idx): New procedure
- (anthy-engine-commit-segment!, anthy-engine-nth-candidate): Removed
- (anthy-engine-method-table): Follow definition change of
segconv-engine-method-table
- (anthy-engine-rec-spec):
* Renamed from anthy-engine-spec
* Add new member cand-indices
- (anthy-engine, anthy-engine-new): Reflect above changes
- (canna-default-locale, canna-intrinsic-transposition-hiragana?,
canna-intrinsic-transposition-katakana?,
canna-intrinsic-transposition-half-alnum?,
canna-intrinsic-transposition-full-alnum?): New variable
- (canna-engine-set-source-str!): Follow the specification changes
of segconv-engine. Partial commit and candidate index handlings
features are not supported yet
- (canna-engine-commit!, canna-engine-candidate-index,
canna-engine-set-candidate-index!, canna-engine-candidate): New
procedure
- (canna-engine-commit-segment!, canna-engine-nth-candidate):
Removed
- (canna-engine-method-table): Follow definition change of
segconv-engine-method-table
- (canna-engine-rec-spec): Renamed from canna-engine-spec
- (canna-engine): Reflect above change
Modified: branches/composer/scm/segmental-converter.scm
===================================================================
--- branches/composer/scm/segmental-converter.scm 2005-07-02 07:10:31 UTC (rev 915)
+++ branches/composer/scm/segmental-converter.scm 2005-07-02 14:15:42 UTC (rev 916)
@@ -46,19 +46,21 @@
;; segconv-engine
;;
-(define segconv-engine-method-table-spec
+(define segconv-engine-method-table-rec-spec
'((finalize! #f)
(reset! #f)
(set-source-str! #f)
+ (commit! #f)
(nr-segments #f)
(segment-source-length #f)
(resize-segment! #f)
- (commit-segment! #f)
(nr-candidates #f)
- (nth-candidate #f)))
-(define-record 'segconv-engine-method-table segconv-engine-method-table-spec)
+ (candidate-index #f)
+ (set-candidate-index! #f)
+ (candidate #f)))
+(define-record 'segconv-engine-method-table segconv-engine-method-table-rec-spec)
-(define segconv-engine-spec
+(define segconv-engine-rec-spec
'((methods #f)))
(define segconv-engine-finalize!
@@ -70,9 +72,14 @@
((segconv-engine-method-table-reset! self) self)))
(define segconv-engine-set-source-str!
- (lambda (self str)
- ((segconv-engine-method-table-set-source-str! self) self str)))
+ (lambda (self utexts)
+ ((segconv-engine-method-table-set-source-str! self) self utexts)))
+;; .returns Commit string as utext-list
+(define segconv-engine-commit!
+ (lambda (self)
+ ((segconv-engine-method-table-commit! self) self)))
+
(define segconv-engine-nr-segments
(lambda (self)
((segconv-engine-method-table-nr-segments self) self)))
@@ -82,87 +89,172 @@
(lambda (self seg-idx)
((segconv-engine-method-table-segment-source-length self) self seg-idx)))
+;; side effect: invalidates nr-segments and all segment info
(define segconv-engine-resize-segment!
(lambda (self seg-idx offset)
((segconv-engine-method-table-resize-segment! self) self seg-idx offset)))
-(define segconv-engine-commit-segment!
- (lambda (self seg-idx cand-idx)
- ((segconv-engine-method-table-commit-segment! self) self seg-idx cand-idx)))
-
(define segconv-engine-nr-candidates
(lambda (self seg-idx)
((segconv-engine-method-table-nr-candidates self) self seg-idx)))
-(define segconv-engine-nth-candidate
+(define segconv-engine-candidate-index
+ (lambda (self seg-idx)
+ ((segconv-engine-method-table-candidate-index self) self seg-idx)))
+
+;; side effect: invalidates nr-segments and all segment info
+;; .parameter commit Instructs partial (sequencial) commit if #t
+;; .returns Commit string as utext-list if commit is #t
+(define segconv-engine-set-candidate-index!
+ (lambda (self seg-idx cand-idx commit)
+ ((segconv-engine-method-table-set-candidate-index! self) self seg-idx cand-idx commit)))
+
+;; .returns Converted segment string as utext-list
+(define segconv-engine-candidate
(lambda (self seg-idx cand-idx)
- ((segconv-engine-method-table-nth-candidate self) self seg-idx cand-idx)))
+ ((segconv-engine-method-table-candidate self) self seg-idx cand-idx)))
;;
;; anthy-engine
;;
-;; TODO: move into anthy.scm
+;; TODO: move into ng-anthy.scm
+(require "i18n.scm")
+(require "ustr.scm")
+
(define anthy-lib-initialized? #f)
+(define anthy-default-locale (locale-new "ja_JP.EUC-JP"))
+(define anthy-intrinsic-transposition-hiragana? #f) ;; NTH_UNCONVERTED_CANDIDATE
+(define anthy-intrinsic-transposition-katakana? #f)
+(define anthy-intrinsic-transposition-halfkana? #f)
+(define anthy-intrinsic-transposition-half-alnum? #f)
+(define anthy-intrinsic-transposition-full-alnum? #f)
(define anthy-engine-finalize!
(lambda (self)
(anthy-lib-free-context (anthy-engine-ac-id self))
- (anthy-engine-set-ac-id! -1)))
+ (anthy-engine-set-ac-id! -1)
+ (ustr-clear! (anthy-engine-cand-indices self))))
+;; TODO: rewrite with anthy_reset_context()
(define anthy-engine-reset!
(lambda (self)
+ ;;(anthy-lib-reset-context (anthy-engine-ac-id self))
(anthy-lib-free-context (anthy-engine-ac-id self))
(anthy-engine-set-ac-id! (or (anthy-lib-alloc-context)
- -1))))
+ -1))
+ (ustr-clear! (anthy-engine-cand-indices self))))
(define anthy-engine-set-source-str!
- (lambda (self str)
- (anthy-lib-set-string (anthy-engine-ac-id self) str)))
+ (lambda (self utexts)
+ (anthy-lib-set-string (anthy-engine-ac-id self)
+ (string-append-map utext-str
+ utexts))
+ (let ((nsegs (segconv-engine-nr-segments self))
+ (cands (anthy-engine-cand-indices self)))
+ (ustr-clear! cands)
+ (ustr-set-latter-seq! cands (make-list nsegs 0)))))
+(define anthy-engine-commit!
+ (lambda (self)
+ (append-map
+ (lambda (seg-idx)
+ (let ((cand-idx (segconv-engine-candidate-index seg-idx)))
+ (segconv-engine-set-candidate-index! self seg-idx cand-idx #t)))
+ (iota (segconv-engine-nr-segments self)))))
+
(define anthy-engine-nr-segments
(lambda (self)
- (anthy-lib-get-nr-segments (anthy-engine-ac-id self))))
+ (- (anthy-lib-get-nr-segments (anthy-engine-ac-id self))
+ (anthy-engine-nr-committed-segments self))))
(define anthy-engine-segment-source-length
(lambda (self seg-idx)
- (anthy-lib-get-segment-length (anthy-engine-ac-id self) seg-idx)))
+ (let ((iseg-idx (anthy-engine-internal-seg-idx self seg-idx)))
+ (anthy-lib-get-segment-length (anthy-engine-ac-id self) iseg-idx))))
(define anthy-engine-resize-segment!
(lambda (self seg-idx offset)
- (anthy-lib-resize-segment (anthy-engine-ac-id self) seg-idx offset)))
+ (let ((iseg-idx (anthy-engine-internal-seg-idx self seg-idx)))
+ (anthy-lib-resize-segment (anthy-engine-ac-id self) iseg-idx offset)
+ (let* ((new-nseg (anthy-lib-get-nr-segments ac-id))
+ (latter-nseg (- new-nseg iseg-idx))
+ (cands (anthy-engine-cand-indices self))
+ (orig-pos (ustr-cursor-pos cands)))
+ (ustr-set-cursor-pos! cands iseg-idx)
+ (ustr-set-latter-seq! cands (make-list latter-nseg 0))
+ (ustr-set-cursor-pos! cands orig-pos)))))
-(define anthy-engine-commit-segment!
- (lambda (self seg-idx cand-idx)
- (anthy-lib-commit-segment (anthy-engine-ac-id self) seg-idx cand-idx)))
-
(define anthy-engine-nr-candidates
(lambda (self seg-idx)
- (anthy-lib-get-nr-candidates (anthy-engine-ac-id self) seg-idx)))
+ (let ((iseg-idx (anthy-engine-internal-seg-idx self seg-idx)))
+ (anthy-lib-get-nr-candidates (anthy-engine-ac-id self) iseg-idx))))
-(define anthy-engine-nth-candidate
+(define anthy-engine-candidate-index
+ (lambda (self seg-idx)
+ (ustr-nth (anthy-engine-internal-seg-idx self seg-idx)
+ (anthy-engine-cand-indices self))))
+
+(define anthy-engine-set-candidate-index!
+ (lambda (self seg-idx cand-idx commit)
+ (let ((ac-id (anthy-engine-ac-id self))
+ (iseg-idx (anthy-engine-internal-seg-idx self seg-idx))
+ (cands (anthy-engine-cand-indices self)))
+ (ustr-set-nth! cands iseg-idx cand-idx)
+ (and commit
+ (let ((committer
+ (lambda (i)
+ (let ((iseg-idx (anthy-engine-internal-seg-idx self i))
+ (cand-idx (anthy-engine-candidate-index self i)))
+ (anthy-lib-commit-segment ac-id iseg-idx cand-idx)
+ (segconv-engine-candidate self i cand-idx))))
+ (utexts (append-map committer (iota (+ seg-idx 1)))))
+ (ustr-set-cursor-pos! cands iseg-idx)
+ (and (ustr-cursor-at-end? cands)
+ (ustr-clear! cands))
+ utexts)))))
+
+(define anthy-engine-candidate
(lambda (self seg-idx cand-idx)
- (anthy-lib-get-nth-candidate (anthy-engine-ac-id self) seg-idx cand-idx)))
+ (let ((ac-id (anthy-engine-ac-id self))
+ (iseg-idx (anthy-engine-internal-seg-idx self seg-idx))
+ (str (anthy-lib-get-nth-candidate ac-id iseg-idx cand-idx)))
+ (list (utext-new str anthy-default-locale ;;'((ruby . "¤Õ¤ê¤¬¤Ê"))
+ )))))
+;; for partial commission feature
+(define anthy-engine-nr-committed-segments
+ (lambda (self)
+ (ustr-cursor-pos (anthy-engine-cand-indices self))))
+
+;; for partial commission feature
+(define anthy-engine-internal-seg-idx
+ (lambda (self seg-idx)
+ (+ (anthy-engine-nr-committed-segments self)
+ seg-idx)))
+
(define anthy-engine-method-table
(segconv-engine-method-table-new
anthy-engine-finalize!
anthy-engine-reset!
anthy-engine-set-source-str!
+ anthy-engine-commit!
anthy-engine-nr-segments
anthy-engine-segment-source-length
anthy-engine-resize-segment!
- anthy-engine-commit-segment!
anthy-engine-nr-candidates
- anthy-engine-nth-candidate))
+ anthy-engine-candidate-index
+ anthy-engine-set-candidate-index!
+ anthy-engine-candidate))
-(define anthy-engine-spec
+(define anthy-engine-rec-spec
(append
- segconv-engine-spec
- '((ac-id -1))))
-(define-record 'anthy-engine anthy-engine-spec)
+ segconv-engine-rec-spec
+ '((ac-id -1) ;; anthy-context-id
+ (cand-indices #f))))
+(define-record 'anthy-engine anthy-engine-rec-spec)
(define anthy-engine-new-internal anthy-engine-new)
(define anthy-engine-new
@@ -173,16 +265,24 @@
(let ((ac-id (and anthy-lib-initialized?
(anthy-lib-alloc-context))))
(and ac-id
- (anthy-engine-new anthy-engine-methods ac-id)))))
+ (anthy-engine-new anthy-engine-methods ac-id (ustr-new))))))
;;
;; canna-engine
;;
-;; TODO: move into canna.scm
+;; TODO: move into ng-canna.scm
+(require "i18n.scm")
+
(define canna-lib-initialized? #f)
+(define canna-default-locale (locale-new "ja_JP.EUC-JP"))
+(define canna-intrinsic-transposition-hiragana? #f) ;; RK_XFER
+(define canna-intrinsic-transposition-katakana? #f) ;; RK_KFER
+;;(define canna-intrinsic-transposition-halfkana? #f)
+(define canna-intrinsic-transposition-half-alnum? #f) ;; RK_HFER
+(define canna-intrinsic-transposition-full-alnum? #f) ;; RK_ZFER
(define canna-engine-finalize!
(lambda (self)
@@ -194,9 +294,14 @@
(canna-lib-reset-context (canna-engine-cc-id self))))
(define canna-engine-set-source-str!
- (lambda (self str)
- (canna-lib-begin-conversion (canna-engine-cc-id self) str)))
+ (lambda (self utexts)
+ (canna-lib-begin-conversion (canna-engine-cc-id self)
+ (string-append-map utext-str utexts))))
+(define canna-engine-commit!
+ (lambda (self)
+ (canna-lib-commit-segment (canna-engine-cc-id self) 'dummy 'dummy)))
+
(define canna-engine-nr-segments
(lambda (self)
(canna-lib-get-nr-segments (canna-engine-cc-id self))))
@@ -207,40 +312,54 @@
;;(canna-lib-get-segment-source-length (canna-engine-cc-id self) seg-idx)))
0))
+;; TODO: support other than -1 and 1 for offset
(define canna-engine-resize-segment!
(lambda (self seg-idx offset)
(canna-lib-resize-segment (canna-engine-cc-id self) seg-idx offset)))
-;; commit all segments even if called for one segment
-(define canna-engine-commit-segment!
- (lambda (self seg-idx cand-idx)
- (canna-lib-commit-segment (canna-engine-cc-id self) seg-idx cand-idx)))
-
(define canna-engine-nr-candidates
(lambda (self seg-idx)
(canna-lib-get-nr-candidates (canna-engine-cc-id self) seg-idx)))
-(define canna-engine-nth-candidate
+;; TODO: get proper cand-idx by RkGetStat()
+(define canna-engine-candidate-index
+ (lambda (self seg-idx)
+ 0))
+
+;; TODO: support partial commit
+(define canna-engine-set-candidate-index!
+ (lambda (self seg-idx cand-idx commit)
+ (if commit
+ (canna-lib-commit-segment (canna-engine-cc-id self) seg-idx cand-idx)
+ ;; TODO: set cand-idx by RkXfer()
+ )))
+
+(define canna-engine-candidate
(lambda (self seg-idx cand-idx)
- (canna-lib-get-nth-candidate (canna-engine-cc-id self) seg-idx cand-idx)))
+ (let ((cc-id (canna-engine-cc-id self))
+ (str (canna-lib-get-nth-candidate cc-id seg-idx cand-idx)))
+ (list (utext-new str canna-default-locale)))))
+
(define canna-engine-method-table
(segconv-engine-method-table-new
canna-engine-finalize!
canna-engine-reset!
canna-engine-set-source-str!
+ canna-engine-commit!
canna-engine-nr-segments
canna-engine-segment-source-length
canna-engine-resize-segment!
- canna-engine-commit-segment!
canna-engine-nr-candidates
- canna-engine-nth-candidate))
+ canna-engine-candidate-index
+ canna-engine-set-candidate-index!
+ canna-engine-candidate))
-(define canna-engine-spec
+(define canna-engine-rec-spec
(append
- segconv-engine-spec
- '((cc-id -1))))
-(define-record 'canna-engine canna-engine-spec)
+ segconv-engine-rec-spec
+ '((cc-id -1)))) ;; canna-context-id
+(define-record 'canna-engine canna-engine-rec-spec)
(define canna-engine-new-internal canna-engine-new)
(define canna-engine-new
More information about the uim-commit
mailing list