[Prime-cvs] CVS update: prime/lib

Back to archive index

Hiroyuki Komatsu komat****@users*****
2005年 3月 17日 (木) 21:01:57 JST


Index: prime/lib/composer.rb
diff -u prime/lib/composer.rb:1.7 prime/lib/composer.rb:1.8
--- prime/lib/composer.rb:1.7	Thu Mar 10 13:01:34 2005
+++ prime/lib/composer.rb	Thu Mar 17 21:01:57 2005
@@ -1,5 +1,5 @@
 # composer.rb: Module of composition for PrimeSession
-# $Id: composer.rb,v 1.7 2005/03/10 04:01:34 komatsu Exp $
+# $Id: composer.rb,v 1.8 2005/03/17 12:01:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -43,22 +43,20 @@
   ## 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
+    original_result = super
 
     if PRIME_ENV['hybrid_typing_use_dictionaries'] == false then
-      return true
+      return original_result
     end
 
     ## The following function is only supported with the Romaji mode.
     if PRIME_ENV['typing_method'] != 'romaji' then
-      return true
+      return original_result
     end
 
     rawinput = edit_get_raw_input()[0]
     if rawinput.nil? then
-      return true
+      return original_result
     end
 
     ## The original hybrid_typing_check_validation returns true, if
@@ -98,7 +96,7 @@
     else
       threshold = 4000
     end
-    $stderr.puts( "[ " + prev_words.join(" | ") + " ] :#{threshold}" )
+#    $stderr.puts( "[ " + prev_words.join(" | ") + " ] :#{threshold}" )
 
     words.each { | word |
       if max_score - word.score > threshold then
@@ -112,6 +110,77 @@
     
     return false
   end
+
+  def hybrid_typing_check_validation_old ()
+    if super == false then
+      return false
+    end
+
+    if PRIME_ENV['hybrid_typing_use_dictionaries'] == false then
+      return true
+    end
+
+    ## The following function is only supported with the Romaji mode.
+    if PRIME_ENV['typing_method'] != 'romaji' then
+      return true
+    end
+
+    rawinput = edit_get_raw_input()[0]
+    if rawinput.nil? then
+      return true
+    end
+
+    ## The original hybrid_typing_check_validation returns true, if
+    ## the first character of rawinput is a upper case and the
+    ## subsequent characters are lower cases.
+    if rawinput =~ /[A-Z]/ then
+      return false
+    end
+
+    ## 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
+
+    max_score = words[0].score
+
+    prev_words = @prime_context.previous_words()
+    #    if prev_words.length >= 2 and
+    #        prev_words[-1] == " " and prev_words[-2] =~ /[a-z]$/ then
+#     if prev_words.length >= 1 and prev_words[-1] =~ /[a-z]$/ then
+
+#       query_line = prev_words[-1] + " " + rawinput
+#       query = PrimeQuery.new( [ query_line ], nil, :exact )
+#       words_list = @composer_prime_engine_english.command( :search, query )
+#       words2 = PrimeWordList::merge(words_list)
+#       if words2.length > 0 then
+#         return false
+#       end
+
+#       threshold = 1
+#     else
+#       threshold = 4000
+#     end
+#    $stderr.puts( "[ " + prev_words.join(" | ") + " ]" )
+
+    words.each { | word |
+#       if max_score - word.score > threshold then
+#         break
+#       end
+
+      if word.pron.index(rawinput) != 0 then
+        return true
+      end
+    }
+    
+    return false
+  end
 end
 
 module PrimeComposerModule
Index: prime/lib/engines.rb
diff -u prime/lib/engines.rb:1.1 prime/lib/engines.rb:1.2
--- prime/lib/engines.rb:1.1	Mon Mar  7 19:01:57 2005
+++ prime/lib/engines.rb	Thu Mar 17 21:01:57 2005
@@ -1,5 +1,5 @@
 # engines.rb:
-# $Id: engines.rb,v 1.1 2005/03/07 10:01:57 komatsu Exp $
+# $Id: engines.rb,v 1.2 2005/03/17 12:01:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -8,27 +8,30 @@
 # You can redistribute it and/or modify it under the terms of 
 # the GNU General Public License version 2.
 
-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-english'
-require 'prime/engine/engine-userdict2-en'
-
-require 'prime/engine/engine-network'
-require 'prime/engine/engine-userdict2-static'
+PRIME_ENV['engines_path'] = {
+  :PrimeEngineBasic            => 'prime/engine/engine-basic',
+  :PrimeEngineUserdict2        => 'prime/engine/engine-userdict2',
+  :PrimeEnginePersonalDict     => 'prime/engine/engine-personaldict',
+  :PrimeEngineAlphabet         => 'prime/engine/engine-alphabet',
+  :PrimeEngineNumber           => 'prime/engine/engine-number',
+# English
+  :PrimeEngineEnglish          => 'prime/engine/engine-english',
+  :PrimeEngineUserdict2English => 'prime/engine/engine-userdict2-en',
+# Experimental
+  :PrimeEngineNetwork          => 'prime/engine/engine-network',
+  :PrimeEngineUserdict2Static  => 'prime/engine/engine-userdict2-static',
+}
 
 ## This class is like a factory pattern.
 class PrimeEngines
   @@engine_cache = {}
 
-  def PrimeEngines::initialize_engines (engine_classes)
+  def PrimeEngines::initialize_engines ( engine_classes )
     engines = engine_classes.map { | engine_class |
       if @@engine_cache.has_key?( engine_class ) then
         @@engine_cache[ engine_class ]
       else
+        require( PRIME_ENV['engines_path'][ engine_class ] )
         @@engine_cache[ engine_class ] = eval( engine_class.to_s ).new()
       end        
     }
Index: prime/lib/protocol.rb
diff -u prime/lib/protocol.rb:1.2 prime/lib/protocol.rb:1.3
--- prime/lib/protocol.rb:1.2	Mon Mar  7 16:51:32 2005
+++ prime/lib/protocol.rb	Thu Mar 17 21:01:57 2005
@@ -1,5 +1,5 @@
 # protocol.rb
-# $Id: protocol.rb,v 1.2 2005/03/07 07:51:32 komatsu Exp $
+# $Id: protocol.rb,v 1.3 2005/03/17 12:01:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -185,6 +185,8 @@
       output = format("string\t%s", value)
     elsif value.kind_of?(Array) then
       output = format("array\t%s", value.join("\t"))
+    elsif value.kind_of?(Hash) then
+      output = 'dict'
     elsif value.kind_of?(TrueClass) or value.kind_of?(FalseClass) then
       output = format("boolean\t%s", value ? "true" : "false")
     elsif value == nil then
Index: prime/lib/session-prime08.rb
diff -u prime/lib/session-prime08.rb:1.3 prime/lib/session-prime08.rb:1.4
--- prime/lib/session-prime08.rb:1.3	Mon Mar  7 18:26:57 2005
+++ prime/lib/session-prime08.rb	Thu Mar 17 21:01:57 2005
@@ -1,5 +1,5 @@
 # session-prime08.rb: Session library for the PRIME 0.8 protocol
-# $Id: session-prime08.rb,v 1.3 2005/03/07 09:26:57 komatsu Exp $
+# $Id: session-prime08.rb,v 1.4 2005/03/17 12:01:57 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -12,14 +12,6 @@
 require 'prime/prime-japanese'
 require 'prime/prime-mixed'
 
-require 'prime/engine/engine-basic'
-require 'prime/engine/engine-english'
-require 'prime/engine/engine-userdict2'
-require 'prime/engine/engine-userdict2-en'
-require 'prime/engine/engine-personaldict'
-require 'prime/engine/engine-alphabet'
-require 'prime/engine/engine-number'
-
 class PrimeSessionPrime08 < PrimeSession
   include PrimeJapanese
   include PrimeMixed
@@ -51,7 +43,7 @@
   end
 
   def set_context (context)
-    @context = context
+    @context = PrimeContext.new( context )
   end
 
   def learn_word (pron, literal, pos = "",
@@ -260,7 +252,7 @@
   def predict_with_multi_clauses!(results)
     unless results.empty? then
       word1 = results.first
-      context = (word1.literal + word1.conjugation)
+      context = PrimeContext.new( word1.literal + word1.conjugation )
       query = PrimeQuery.new([""], nil, :context, context)
       word2 = search(query).first
       if word2.non_nil? then


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