[Prime-cvs] CVS update: prime/lib

Back to archive index

Hiroyuki Komatsu komat****@users*****
2005年 3月 7日 (月) 18:26:58 JST


Index: prime/lib/composer.rb
diff -u prime/lib/composer.rb:1.2 prime/lib/composer.rb:1.3
--- prime/lib/composer.rb:1.2	Mon Mar  7 16:51:32 2005
+++ prime/lib/composer.rb	Mon Mar  7 18:26:57 2005
@@ -1,5 +1,5 @@
 # composer.rb: Module of composition for PrimeSession
-# $Id: composer.rb,v 1.2 2005/03/07 07:51:32 komatsu Exp $
+# $Id: composer.rb,v 1.3 2005/03/07 09:26:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -8,7 +8,65 @@
 # You can redistribute it and/or modify it under the terms of 
 # the GNU General Public License version 2.
 
-module PrimeComposer
+require 'prime/engines'
+require 'suikyo/suikyo-composer'
+
+class PrimeComposer < SuikyoComposer
+  def initialize (table = nil, table_reverse = nil)
+    super
+
+    @composer_prime_engines =
+      PrimeEngines::initialize_engines( [ :PrimeEngineBasic,
+                                          :PrimeEngineEnglish,
+                                          :PrimeEngineUserdict2,
+                                          :PrimeEngineUserdict2English,
+                                          :PrimeEnginePersonalDict ] )
+  end
+
+  ## This checks the validation of the preediting string.  If the preedition
+  ## is valid, it returns true.  If invalid, false.
+  ## ex). "apple (あっplえ)" => false, "ringo(りんご)" => true.
+  def hybrid_typing_check_validation ()
+    if super == false then
+      return false
+    end
+
+    ## The following function is only supported with the Romaji mode.
+    if PRIME_ENV['typing_method'] != 'romaji' then
+      return true
+    end
+
+#    ## If the cursor does not locate the end of the preedition, 
+#    ## the preedition will not be modified.
+#    if preedition[1] != '' or preedition[2] != '' then
+#      return preedition
+#    end
+#    conversion = preedition[0]
+
+    ## edit_get_expansion_internal ignores the typing_mode.
+    ## If the typing_mode is :raw, edit_get_expansion just returns rawinput.
+    expansion = edit_get_expansion_internal()
+    query = PrimeQuery.new( expansion, nil, :prefix )
+    words_list = @composer_prime_engines.command( :search, query )
+    words = PrimeWordList::merge(words_list)
+
+    if words.length == 0 then
+      return true
+    end
+
+    rawinput = edit_get_raw_input()[0]
+
+    words.each { | word |
+      if word.pron.index(rawinput) != 0 then
+        return true
+      end
+    }
+    
+    return false
+  end
+end
+
+module PrimeComposerModule
   ## 
   ## Composition methods
   ##
@@ -54,6 +112,45 @@
 
   ## This returns a list of the preediting string divided by the cursor 
   ## position.
+  def edit_get_preedition_new ()
+    preedition =****@compo*****_get_preediting_string()
+    ## The following function is only supported with the Romaji mode.
+    if PRIME_ENV['typing_method'] != 'romaji' then
+      return preedition
+    end
+
+    ## If the cursor does not locate the end of the preedition, 
+    ## the preedition will not be modified.
+    if preedition[1] != '' or preedition[2] != '' then
+      return preedition
+    end
+    conversion = preedition[0]
+
+    ## If the preedition is already the raw input, 
+    ## the preedition will not be modified.
+    rawinput =****@compo*****_get_raw_input()[0]
+    if rawinput.nil? or rawinput == conversion then
+      return preedition
+    end
+
+    expansion =****@compo*****_get_expansion()
+    query = PrimeQuery.new( expansion, nil, :prefix )
+    words_list = @composer_prime_engines.command( :search, query )
+    words = PrimeWordList::merge(words_list)
+
+    if words.length == 0 then
+      return preedition
+    end
+
+    words.each { | word |
+      if word.pron.index(rawinput) != 0 then
+        return preedition
+      end
+    }
+    
+    return [rawinput, '', '']
+  end
+
   def edit_get_preedition ()
     retur****@compo*****_get_preediting_string()
   end
Index: prime/lib/session-english.rb
diff -u prime/lib/session-english.rb:1.2 prime/lib/session-english.rb:1.3
--- prime/lib/session-english.rb:1.2	Mon Mar  7 16:51:32 2005
+++ prime/lib/session-english.rb	Mon Mar  7 18:26:57 2005
@@ -1,5 +1,5 @@
 # session-english.rb: Session library for English.
-# $Id: session-english.rb,v 1.2 2005/03/07 07:51:32 komatsu Exp $
+# $Id: session-english.rb,v 1.3 2005/03/07 09:26:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -11,14 +11,8 @@
 require 'prime/session'
 require 'prime/composer'
 
-require 'prime/engine/engine-english'
-require 'prime/engine/engine-userdict2-en'
-require 'prime/engine/engine-personaldict'
-require 'prime/engine/engine-alphabet'
-require 'prime/engine/engine-number'
-
 class PrimeSessionEnglish < PrimeSession
-  include PrimeComposer
+  include PrimeComposerModule
 
   def initialize ()
     name = "English"
Index: prime/lib/session-japanese.rb
diff -u prime/lib/session-japanese.rb:1.2 prime/lib/session-japanese.rb:1.3
--- prime/lib/session-japanese.rb:1.2	Mon Mar  7 16:51:32 2005
+++ prime/lib/session-japanese.rb	Mon Mar  7 18:26:57 2005
@@ -1,5 +1,5 @@
 # session-japanese.rb: Session library for Japanese.
-# $Id: session-japanese.rb,v 1.2 2005/03/07 07:51:32 komatsu Exp $
+# $Id: session-japanese.rb,v 1.3 2005/03/07 09:26:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -13,17 +13,8 @@
 require 'prime/prime-japanese'
 require 'prime/prime-mixed'
 
-require 'prime/engine/engine-basic'
-require 'prime/engine/engine-userdict2'
-require 'prime/engine/engine-personaldict'
-require 'prime/engine/engine-alphabet'
-require 'prime/engine/engine-number'
-
-require 'prime/engine/engine-network'
-require 'prime/engine/engine-userdict2-static'
-
 class PrimeSessionJapanese < PrimeSession
-  include PrimeComposer
+  include PrimeComposerModule
   include PrimeJapanese
   include PrimeMixed
 
@@ -42,7 +33,7 @@
   end
 
   def initialize_composer ()
-    composer = SuikyoComposer.new()
+    composer = PrimeComposer.new()
     composer.set_table(PRIME_ENV['suikyo_tables'])
     composer.set_reverse_table(PRIME_ENV['suikyo_reverse_tables'])
 
Index: prime/lib/session-prime08.rb
diff -u prime/lib/session-prime08.rb:1.2 prime/lib/session-prime08.rb:1.3
--- prime/lib/session-prime08.rb:1.2	Mon Mar  7 16:51:32 2005
+++ prime/lib/session-prime08.rb	Mon Mar  7 18:26:57 2005
@@ -1,5 +1,5 @@
 # session-prime08.rb: Session library for the PRIME 0.8 protocol
-# $Id: session-prime08.rb,v 1.2 2005/03/07 07:51:32 komatsu Exp $
+# $Id: session-prime08.rb,v 1.3 2005/03/07 09:26:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
Index: prime/lib/session.rb
diff -u prime/lib/session.rb:1.8 prime/lib/session.rb:1.9
--- prime/lib/session.rb:1.8	Mon Mar  7 16:51:32 2005
+++ prime/lib/session.rb	Mon Mar  7 18:26:57 2005
@@ -1,5 +1,5 @@
 # session.rb:
-# $Id: session.rb,v 1.8 2005/03/07 07:51:32 komatsu Exp $
+# $Id: session.rb,v 1.9 2005/03/07 09:26:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -8,6 +8,8 @@
 # You can redistribute it and/or modify it under the terms of 
 # the GNU General Public License version 2.
 
+require 'prime/engines'
+
 class PrimeSession
   @@engine_cache = {}
 
@@ -16,7 +18,7 @@
     @language       = ""
     @engine_classes = engine_classes
     @composer       = initialize_composer()
-    @engines        = initialize_engines(engine_classes)
+    @engines        = PrimeEngines::initialize_engines(engine_classes)
     @conversions    = PrimeConversionList.new()
     @context        = nil
   end


Prime-cvs メーリングリストの案内
Back to archive index