[Prime-cvs] CVS update: prime/lib

Back to archive index

Hiroyuki Komatsu komat****@users*****
2005年 2月 1日 (火) 08:37:45 JST


Index: prime/lib/session.rb
diff -u prime/lib/session.rb:1.4.4.22 prime/lib/session.rb:1.4.4.23
--- prime/lib/session.rb:1.4.4.22	Mon Jan 31 04:45:48 2005
+++ prime/lib/session.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # session.rb:
-# $Id: session.rb,v 1.4.4.22 2005/01/30 19:45:48 komatsu Exp $
+# $Id: session.rb,v 1.4.4.23 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -8,109 +8,18 @@
 # You can redistribute it and/or modify it under the terms of 
 # the GNU General Public License version 2.
 
-require 'prime/prime-japanese'
-
 class PrimeSession
-  ## FIXME: Create PrimeSession-Japanese
-  ## FIXME: (2005-01-31) <komat****@taiya*****>
-  include PrimeJapanese
-
-  def initialize ( language = "Japanese" )
-    @language    = (language or "Japanese")
-    @composer    = initialize_composer(@language)
-    @engines     = initialize_engines(@language)
-    @conversions = PrimeConversionList.new()
-    @context     = nil
-    initialize_prime_japanese()
-  end
-
-  def initialize_composer (language)
-    case language
-    when "Japanese" then
-      @composer = initialize_composer_japanese()
-    when "English" then
-      @composer = initialize_composer_english()
-    end
-    return @composer
-  end
-
-  def initialize_composer_japanese ()
-    composer = SuikyoComposer.new()
-    composer.set_table(PRIME_ENV['suikyo_tables'])
-    composer.set_reverse_table(PRIME_ENV['suikyo_reverse_tables'])
-
-    ## Setting hybrid_typing.
-    if PRIME_ENV['hybrid_typing'].nil? then
-      if PRIME_ENV['typing_method'] == 'romaji' then
-        PRIME_ENV['hybrid_typing'] = true
-        composer.hybrid_typing     = true
-      end
-    else
-      composer.hybrid_typing = PRIME_ENV['hybrid_typing']
-    end
-
-    ## Setting period and comma in Japanese.
-    period = PRIME_ENV['style_japanese_period']
-    comma  = PRIME_ENV['style_japanese_comma']
-    case PRIME_ENV['typing_method']
-    when "romaji" then
-      composer.set_table_entry('.', period)
-      composer.set_table_entry(',', comma)
-      composer.set_reverse_table_entry(period, '.')
-      composer.set_reverse_table_entry(comma,  ',')
-    when "kana" then
-      composer.set_table_entry('>', period)
-      composer.set_table_entry('<', comma)
-      composer.set_reverse_table_entry(period, '>')
-      composer.set_reverse_table_entry(comma,  '<')
-    when "tcode" then
-      for char in 'A'..'Z' do
-        composer.set_table_entry(char, char)
-        composer.set_reverse_table_entry(char, char)
-      end
-    end
-
-    return composer
-  end
-
-  def initialize_composer_english ()
-    composer = SuikyoComposer.new()
-    return composer
-  end
-
-  def initialize_engines (language)
-    case language
-    when "Japanese" then 
-      @engines = initialize_engines_japanese()
-    when "English" then
-      @engines = initialize_engines_english()
-    end
-    return @engines
-  end
-
-  def initialize_engines_japanese ()
-    engine_classes = [
-      :PrimeEngineBasic,
-      :PrimeEngineUserdict2,
-      :PrimeEnginePersonalDict,
-      :PrimeEngineAlphabet,
-      :PrimeEngineNumber,
-    ]
-    return initialize_engines_internal(engine_classes)
-  end
-
-  def initialize_engines_english ()
-    engine_classes = [
-      :PrimeEngineEnglish,
-      :PrimeEngineUserdict2English,
-      :PrimeEnginePersonalDict,
-      :PrimeEngineAlphabet,
-      :PrimeEngineNumber,
-    ]
-    return initialize_engines_internal(engine_classes)
+  def initialize (name, engine_classes)
+    @name           = name
+    @language       = ""
+    @engine_classes = engine_classes
+    @composer       = initialize_composer()
+    @engines        = initialize_engines(engine_classes)
+    @conversions    = PrimeConversionList.new()
+    @context        = nil
   end
 
-  def initialize_engines_internal (engine_classes)
+  def initialize_engines (engine_classes)
     engines = engine_classes.map { | engine_class |
       eval( engine_class.to_s ).new()
     }
@@ -124,6 +33,20 @@
     return engines
   end
 
+  def initialize_composer ()
+    composer = SuikyoComposer.new()
+    return composer
+  end
+
+  def session_get_env (variable)
+    case variable
+    when "language" then
+      return @language
+    else
+      return nil
+    end
+  end
+
   def set_conversions (conversions)
     @conversions = conversions
   end
@@ -143,103 +66,6 @@
     return @context
   end
 
-  ## 
-  ## Composition methods
-  ##
-  def edit_insert (string)
-    @composer.edit_insert(string)
-    return true
-  end
-  def edit_delete ()
-    @composer.edit_delete()
-    return true
-  end
-  def edit_backspace ()
-    @composer.edit_backspace()
-    return true
-  end
-  def edit_erase ()
-    @composer.edit_erase()
-    if PRIME_ENV['hybrid_typing'] then
-      @composer.set_mode_hybrid()
-    end
-    return true
-  end
-  def edit_undo ()
-    @composer.undo()
-    return true
-  end
-  def edit_cursor_right ()
-    @composer.cursor_right()
-    return true
-  end
-  def edit_cursor_left ()
-    @composer.cursor_left()
-    return true
-  end
-  def edit_cursor_right_edge ()
-    @composer.cursor_right_edge()
-    return true
-  end
-  def edit_cursor_left_edge ()
-    @composer.cursor_left_edge()
-    return true
-  end
-
-  ## This returns a list of the preediting string divided by the cursor 
-  ## position.
-  def edit_get_preedition ()
-    retur****@compo*****_get_preediting_string()
-  end
-
-  def edit_get_query_string ()
-    retur****@compo*****_get_query_string()
-  end
-
-  def edit_set_mode (mode)
-    case mode
-    when "hybrid" then         # Original
-      @composer.set_mode_hybrid()
-    when "default" then        # F6
-      @composer.set_mode_default()
-    when "katakana" then       # F7
-      @composer.set_mode_katakana()
-    when "half_katakana" then  # F8
-      @composer.set_mode_half_katakana()
-    when "wide_ascii" then     # F9
-      @composer.set_mode_wide_ascii()
-    when "raw" then            # F10
-      @composer.set_mode_raw()
-    else
-      return false
-    end
-    return true
-  end
-
-  def edit_commit ()
-    reading = edit_get_preedition().join()
-
-    ## Commit the current conversion
-    base         = reading
-    base_reading = reading
-    pos          = nil
-    context      = get_context()
-    adjunct      = ""
-    rest         = ""
-
-    @engines.command(:learn_word,
-                     base_reading, base, pos, context, adjunct, rest)
-
-    ## Set next context
-    context_reset()
-    context_set_previous_word(reading)
-
-    ## Reset the conversion.
-    edit_erase()
-
-    return reading
-  end
-
   ##
   ## Context methods
   ##
@@ -254,427 +80,4 @@
   def context_set_previous_word (word)
     set_context(word)
   end
-
-
-  ##
-  ## Conversion methods
-  ##
-
-  ## This returns a PrimeConversionList.
-  def conv_convert (method = nil)
-    case @language
-    when "Japanese" then
-      if PRIME_ENV['typing_method'] == 'tcode' or 
-          PRIME_ENV['typing_method'] == 'handwrite' then
-        candidates = lookup_direct_all(string)
-      else
-        conversions_compact  = convert_compact()
-        ## FIXME: Delete the magic number.
-        ## FIXME: (2004-12-22) <Hiro>
-        conversions_compact.add_score( 50000 )
-        conversions_japanese = convert_japanese()
-        conversions_overall  = convert_overall()
-
-        conversions = PrimeConversionList::merge( conversions_compact,
-                                                  conversions_japanese,
-                                                  conversions_overall )
-      end
-
-      set_conversions(conversions)
-      return conversions
-
-    when "English" then
-      conversions = convert_prefix()
-      set_conversions(conversions)
-      return conversions
-    end
-  end
-
-  def conv_predict (method = nil)
-    case @language
-    when "Japanese" then
-      if PRIME_ENV['typing_method'] == 'tcode' or 
-          PRIME_ENV['typing_method'] == 'handwrite' then
-        candidates = lookup_direct(string)
-      else
-        conversions = convert_compact()
-      end
-
-      set_conversions(conversions)
-      return conversions
-
-    when "English" then
-      conversions = convert_prefix()
-      set_conversions(conversions)
-      return conversions
-    end
-  end
-
-  def conv_select (index)
-    conversion = set_selection(index)
-    return conversion
-  end
-
-  def conv_commit ()
-    conversion = get_selection()
-
-    ## Commit the current conversion
-    conversion.segments.each { | segment |
-      learn_segment( segment, get_context() )
-
-      context_reset()
-      context_set_previous_segment(segment)
-    }
-    commited_string = conversion.get_literal()
-
-    ## Reset the conversion.
-    edit_erase()
-
-    return commited_string
-  end
-
-  def learn_segment (segment, context)
-    base         = segment.get_base()
-    base_reading = segment.get_base_reading()
-    pos          = segment.get_pos()
-    adjunct      = segment.get_adjunct()
-    rest         = ""
-
-    @engines.command(:learn_word,
-                     base_reading, base, pos, context, adjunct, rest)
-  end
-
-  def _adhoc_wordlist_to_conversionlist (wordlist)
-    conversion_list = []
-    wordlist.length.times { | index |
-      word = wordlist[index]
-      reading = word.to_text_pron()
-
-      segment = PrimeSegment.new(reading)
-      segment.set_candidates(wordlist, index)
-
-      conversion_list.push( PrimeConversion.new( [segment], word.score ) )
-    }
-    return PrimeConversionList.new(conversion_list)
-  end
-
-  ##
-  ## Modification methods
-  ##
-  def modify_start ()
-    conversion = get_selection()
-    conversion.position_right_edge()
-  end
-
-  def modify_select (index_no)
-    conversion = get_selection()
-    conversion.candidate_select(index_no)
-  end
-
-  def modify_commit ()
-  end
-
-  def modify_reconvert ()
-    conversion = get_selection()
-    segment    = conversion.get_segment()
-
-    segment_reconvert(segment)
-
-    return modify_get_segment()
-  end
-
-  def modify_get_segment ()
-    conversion = get_selection()
-    return conversion.get_segment()
-  end
-
-  def modify_get_conversion ()
-    conversion = get_selection()
-    return conversion.get_conversion()
-  end
-
-  def modify_cursor_left ()
-    conversion = get_selection()
-    conversion.position_left()
-  end
-  def modify_cursor_right ()
-    conversion = get_selection()
-    conversion.position_right()
-  end
-  def modify_cursor_left_edge ()
-    conversion = get_selection()
-    conversion.position_left_edge()
-  end
-  def modify_cursor_right_edge ()
-    conversion = get_selection()
-    conversion.position_right_edge()
-  end
-  def modify_cursor_expand ()
-    conversion = get_selection()
-    conversion.segment_expand()
-  end
-  def modify_cursor_shrink ()
-    conversion = get_selection()
-    conversion.segment_shrink()
-  end
-
-  private
-  ## This is a wrapper for convert_*.  This converts query to
-  ## a PrimeConversionList insted of PrimeWordList and returns it.
-  def convert (query)
-    query.input.uniq!()
-    words_list =****@engin*****(:search, query)
-    wordlist = PrimeWordList::merge(words_list)
-
-    PrimeWordList::attach_prefix(@context, wordlist)
-    return _adhoc_wordlist_to_conversionlist( wordlist )
-  end
-  private :convert
-
-  def convert_prefix ()
-    # 「よ→予測」
-    context  = get_context()
-    expansion =****@compo*****_get_expansion()
-    query = PrimeQuery.new(expansion, nil, :prefix, context)
-    return convert(query)
-  end
-
-  def convert_exact ()
-    # 「よそく→予測」
-    context  = get_context()
-    conversion =****@compo*****_get_conversion()
-    query = PrimeQuery.new(conversion, nil, :exact, context)
-    return convert(query)
-  end
-
-  def convert_overall ()
-    # 「1+1=→2」, 「aiueo→アイウエオ」
-    raw_input =****@compo*****_get_raw_input()
-    query = PrimeQuery.new(raw_input, nil, :overall)
-    return convert(query)
-  end
-
-  def convert_compact ()
-    conversion_prefix = convert_prefix().first()
-
-    ## If the result of search_prefix is empty, this method stops the following
-    ## search_japanese_uniclause for the quickness.
-    if conversion_prefix.nil?() then
-      return PrimeConversionList.new()
-    end
-
-    ## If the result of convert_japanese_uniclause exists and the score of it
-    ## is greater than the result of convert_prefix, the return conversion
-    ## becomes the convert_japanese_uniclause's one.
-    conversion_japanese = convert_japanese_uniclause().first()
-    if conversion_japanese.nil?() then
-      conversion = conversion_prefix
-    elsif conversion_japanese.score < conversion_prefix.score then
-      conversion = conversion_prefix
-    else  ## conversion_japanese.score >= conversion_prefix.score
-      conversion = conversion_japanese
-    end
-
-    ## Predict a next segment of the conversion.
-    next_segment = predict_next_segment( conversion )
-    if next_segment.nil? then
-      return PrimeConversionList.new( [conversion] )
-    end
-
-    conversion2 = conversion.dup()
-    conversion2.segment_insert(next_segment)
-    return PrimeConversionList.new( [conversion, conversion2] )
-  end
-
-  ## This predicts candidate words as a next word for the specified conversion
-  ## data.  For example when the specified conversion means "どうもありがとう",
-  ## one of the results would contain "ございます".
-  def predict_next_segment (conversion)
-    if conversion.nil? then
-      return nil
-    end
-
-    ## The current context is just the previous word.
-    context = conversion.get_literal()
-
-    ## If the last character of the specified conversion is one of stop_words,
-    ## This method stops its prediction.  (EXPERIMENTAL)
-    stop_words = \
-    [ PRIME_ENV['style_japanese_period'],
-      PRIME_ENV['style_japanese_comma'] ]
-    if context =~ /(#{stop_words.join('|')})$/ then
-      return nil
-    end
-
-    query = PrimeQuery.new([""], nil, :context, context)
-    next_words = search(query)
-    if next_words.empty? then
-      return nil
-    end
-
-    ## Create a PrimeSegment from the first value of a PrimeWord.
-    next_words = next_words[0,1]
-
-    next_word  = next_words.first
-    next_word.prefix = Prime::get_prefix(context, next_word.literal)
-
-    reading      = next_word.to_text_pron()
-    base_reading = ""
-    pos          = nil
-    adjunct      = ""
-    pos_adjunct  = nil
-
-    next_segment = PrimeSegment.new(reading, base_reading, pos,
-                                    adjunct, pos_adjunct, context)
-    next_segment.set_candidates(next_words, 0)
-    return next_segment
-  end
-  private :predict_next_segment
-
-  ## This returns a PrimeConversionList.
-  def convert_japanese ()
-    segments_list = convert_japanese_process_segments_list(@composer)
-    conversions = []
-
-    segments_list.each { | segments |
-      if segments.length == 1 then
-        conversions += convert_from_segment( segments.first() )
-      else
-        segments.each { | segment |
-          query = PrimeQuery.new( [segment.base_reading], segment.pos )
-          words = search(query)
-          words.each { | word |
-            word.conjugation     = segment.adjunct
-            word.conjugation_pos = segment.pos_adjunct
-          }
-          index = (segment.pos == nil) ? -1 : 0
-          segment.set_candidates(words, index)
-        }
-        score = convert_japanese_get_score(segments)
-        conversions.push( PrimeConversion.new(segments, score) )
-      end
-    }
-    return PrimeConversionList.new( conversions )
-  end
-
-  ## This returns a PrimeWordList.
-  ## FIXME: Change the method name.
-  def convert_japanese_uniclause ()
-    segments_list = convert_japanese_process_segments_list(@composer, 1)
-    conversions = PrimeConversionList.new()
-
-    segments_list.each { | segments | # The lengh of segments must be 1.
-      conversions += convert_from_segment( segments.first() )
-    }
-    return conversions
-  end
-
-  ## This converts from the specified segment to convertions.
-  ## FIXME: Chage the function name.
-  ## FIXME: (2004-12-19) <Hiro>.
-  def convert_from_segment (segment)
-    conversions = PrimeConversionList.new()
-    query = PrimeQuery.new( [segment.base_reading], segment.pos )
-    words = search(query)
-
-    words.length.times { | index |
-      word = words[index]
-      word.conjugation     = segment.adjunct
-      word.conjugation_pos = segment.pos_adjunct
-
-      new_segment = segment.dup()
-      new_segment.set_candidates(words, index)
-      conversions.push( PrimeConversion.new( [new_segment], word.score ) )
-    }
-    return conversions
-  end
-  private :convert_from_segment
-
-  def segment_reconvert (segment, context = nil)
-    reading = segment.reading
-    words1  = search_raw(reading)
-    words2  = search_overall(reading)
-    words3  = search_japanese_uniclause(reading)
-#    words   = PrimeWordList::merge_by_literal(context, words1, words2, words3)
-
-    candidates      = segment.get_candidates()
-    candidate_index = segment.get_candidate_index()
-
-    candidates = PrimeWordList::merge2([candidates], [words1, words2, words3])
-    segment.set_candidates( candidates, candidate_index )
-  end
-
-  def convert_japanese_process_segments_list (composer, threshold = 4)
-    string = composer.edit_get_surface_string()
-    (depth, segments_list) = guess_clauses_internal(string, 1, nil, threshold)
-
-    conversions = []
-    min_length  = depth
-
-    segments_list.each { | segments |
-      if segments.length < min_length then
-        conversions = []
-        min_length = segments.length
-      elsif segments.length == min_length then
-        prime_segments = []
-        segments.each { | (base_reading, pos, adjunct, pos_adjunct, engines) |
-          prime_segment = PrimeSegment.new(base_reading + adjunct,
-                                           base_reading, pos,
-                                           adjunct, pos_adjunct)
-          prime_segments.push(prime_segment)
-        }
-        conversions.push(prime_segments)
-      end
-    }
-    return conversions
-  end
-  private :convert_japanese_process_segments_list
-
-  def convert_japanese_get_score (segments)
-    segment = segments[0]
-    pos     = segment.pos
-    literal = segment.get_literal()
-    score   = segment.get_score()
-
-    segments[1..-1].each { | segment2 |
-      pos2     = segment2.pos
-      literal2 = segment2.get_literal()
-      score2   = segment2.get_score()
-      if pos2.nil? then
-        cost = 0.9 ** literal2.length
-      else
-        cost = _get_connection_cost(pos, literal, pos2, literal2)
-      end
-      connection_key = [pos, pos2].join("\t")
-      pos = (@pos_connection_pos[connection_key] or pos2)
-
-      score = (Math::sqrt(score * score2) * cost).to_i
-    }
-    return score
-  end
-  private :convert_japanese_get_score
-
-  #### ------------------------------------------------------------
-  ## FIXME: revise the following mehods.
-  ## FIXME: (2005-01-31) <Hiroyuki Komatsu>
-  def search (query)
-    query.input.uniq!()
-    words_list =****@engin*****(:search, query)
-    return PrimeWordList::merge(words_list)
-  end
-
-  def search_raw (string)
-    ## FIXME: This method is an ad-hoc routine for search_japanese.
-    ## FIXME: <komat****@taiya*****> (2004-02-28)
-    query = PrimeQuery.new([string], nil, :exact, @context)
-    words = search(query)
-    return words
-  end
-
-  def search_overall (string)
-    # 「1+1=→2」, 「aiueo→アイウエオ」
-    query = PrimeQuery.new([string], nil, :overall)
-    words_overall = search(query)
-    return words_overall
-  end
 end
Index: prime/lib/session-prime08.rb
diff -u prime/lib/session-prime08.rb:1.1.2.1 prime/lib/session-prime08.rb:1.1.2.2
--- prime/lib/session-prime08.rb:1.1.2.1	Mon Jan 31 22:03:36 2005
+++ prime/lib/session-prime08.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # session-prime08.rb: Session library for the PRIME 0.8 protocol
-# $Id: session-prime08.rb,v 1.1.2.1 2005/01/31 13:03:36 komatsu Exp $
+# $Id: session-prime08.rb,v 1.1.2.2 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -12,15 +12,36 @@
 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
 
-  def initialize (language = nil)
-    super
+  def initialize ()
+    super("Prime0.8", PRIME_ENV["engines"])
     initialize_prime_japanese()
   end
 
+  def close ()
+    @engines.command(:close)
+  end
+
+  def update ()
+    @engines.command(:update)
+    refresh()
+  end
+  def refresh ()
+    PrimeTypeConv::refresh()
+    @engines.command(:refresh)
+  end
+
   def get_label (pattern)
     return PrimeTypeConv::convert(pattern).join()
   end
Index: prime/lib/protocol.rb
diff -u prime/lib/protocol.rb:1.1.2.1 prime/lib/protocol.rb:1.1.2.2
--- prime/lib/protocol.rb:1.1.2.1	Mon Jan 31 03:30:56 2005
+++ prime/lib/protocol.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # protocol.rb
-# $Id: protocol.rb,v 1.1.2.1 2005/01/30 18:30:56 komatsu Exp $
+# $Id: protocol.rb,v 1.1.2.2 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -171,6 +171,24 @@
                 "refresh the statuses of the conversion engines.")
   end
 
+  ## This returns a string which has the type of a value and the value.
+  ## The type and the value are separated by "\t".
+  ## For example: "string\tstring_value", "boolean\ttrue", "nil".
+  def combine_return_value (value)
+    if value.kind_of?(String) then
+      output = format("string\t%s", value)
+    elsif value.kind_of?(Array) then
+      output = format("array\t%s", value.join("\t"))
+    elsif value.kind_of?(TrueClass) or value.kind_of?(FalseClass) then
+      output = format("boolean\t%s", value ? "true" : "false")
+    elsif value == nil then
+      output = 'nil'
+    else
+      output = 'unknown'
+    end
+    return output
+  end
+
   def learn_word (key, value, part = nil,
                   context = nil, suffix = nil, rest = nil)
     @prime.learn_word(key, value, part, context, suffix, rest)
@@ -178,19 +196,7 @@
   end
 
   def get_env (key)
-    env =****@prime*****_env(key)
-    if env.kind_of?(String) then
-      output = format("string\t%s", env)
-    elsif env.kind_of?(Array) then
-      output = format("array\t%s", env.join("\t"))
-    elsif env.kind_of?(TrueClass) or env.kind_of?(FalseClass) then
-      output = format("boolean\t%s", env ? "true" : "false")
-    elsif env == nil then
-      output = 'nil'
-    else
-      output = 'unknown'
-    end
-
+    output = combine_return_value( @prime.get_env(key) )
     return reply_successful(output)
   end
 
@@ -269,6 +275,8 @@
                 "start a session and return the session id.", 0)
     add_command(:session_end, [:SESSION],
                 "close the session specified with the session id.")
+    add_command(:session_get_env, [:SESSION, :VARIABLE],
+                "return a value of the variable.")
 #     add_command(:session_language_set, [:SESSION, :LANGUAGE],
 #                 "Set the target language (Japanese or English).")
 #     add_command(:session_language_get, [:SESSION],
@@ -359,6 +367,11 @@
     return reply_successful()
   end
 
+  def session_get_env (session, variable)
+    value =****@prime*****_command(session, :session_get_env, variable)
+    return reply_successful( combine_return_value(value) )
+  end
+
   ## 
   ## Composition methods
   ##
Index: prime/lib/prime2.rb
diff -u prime/lib/prime2.rb:1.1.2.15 prime/lib/prime2.rb:1.1.2.16
--- prime/lib/prime2.rb:1.1.2.15	Mon Jan 31 22:03:36 2005
+++ prime/lib/prime2.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # prime2.rb: Module for PRIME2 protocol.
-# $Id: prime2.rb,v 1.1.2.15 2005/01/31 13:03:36 komatsu Exp $
+# $Id: prime2.rb,v 1.1.2.16 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -9,7 +9,9 @@
 # the GNU General Public License version 2.
 
 require 'suikyo/suikyo-composer'
-require 'prime/session.rb'
+require 'prime/session'
+require 'prime/session-japanese'
+require 'prime/session-english'
 require 'prime/session-prime08'
 
 module Prime2
@@ -21,9 +23,17 @@
   ## 
   ## Session methods
   ##
-  def session_start (language = "Japanese")
-    session_data = PrimeSession.new(language)
-
+  def session_start (name = "Japanese")
+    case name
+    when "Japanese" then
+      session_data = PrimeSessionJapanese.new()
+    when "English" then
+      session_data = PrimeSessionEnglish.new()
+    when "Prime08" then
+      session_data = PrimeSessionPrime08.new()
+    else
+      session_data = PrimeSessionJapanese.new()
+    end
     @session_no += 1
     @sessions[@session_no.to_s] = session_data
 
@@ -150,7 +160,10 @@
 
   def get_literal()
     literal = ""
-    @segments.each { | segment | literal += segment.get_literal() }
+    @segments.each { | segment |
+      literal_segment = segment.get_literal()
+      literal += ( get_separator(literal, literal_segment) + literal_segment )
+    }
     return literal
   end
   
@@ -244,8 +257,23 @@
     if****@segme***** == 1 then
       return @segments[0].to_text_data()  # with annotations
     else
-      texts =****@segme***** { | segment | segment.to_text() }
-      return texts.join()
+      return get_literal()
+    end
+  end
+
+  def get_separator (word1, word2)
+    if  alphabet?( word1[-1] )  and  alphabet?( word2[0] )  then
+      return " "
+    else
+      return ""
+    end
+  end
+
+  def alphabet? (char)
+    if char.nil? then
+      return false
+    else
+      return ( (char >= ?a and char <= ?z) or (char >= ?A and char <= ?Z) )
     end
   end
 end
Index: prime/lib/prime08.rb
diff -u prime/lib/prime08.rb:1.1.2.1 prime/lib/prime08.rb:1.1.2.2
--- prime/lib/prime08.rb:1.1.2.1	Mon Jan 31 22:03:36 2005
+++ prime/lib/prime08.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # prime08.rb: Module for the PRIME 0.8 protocol
-# $Id: prime08.rb,v 1.1.2.1 2005/01/31 13:03:36 komatsu Exp $
+# $Id: prime08.rb,v 1.1.2.2 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -13,6 +13,17 @@
     @session_prime08 = PrimeSessionPrime08.new()
   end
 
+  def close ()
+    @session_prime08.close()
+  end
+  def update ()
+    @session_prime08.update()
+  end
+  def refresh ()
+    initialize_rc()
+    @session_prime08.refresh()
+  end
+
   def get_label (pattern)
     return @session_prime08.get_label(pattern)
   end
Index: prime/lib/prime.rb
diff -u prime/lib/prime.rb:1.7.4.20 prime/lib/prime.rb:1.7.4.21
--- prime/lib/prime.rb:1.7.4.20	Mon Jan 31 22:03:36 2005
+++ prime/lib/prime.rb	Tue Feb  1 08:37:44 2005
@@ -1,5 +1,5 @@
 # prime/prime.rb
-# $Id: prime.rb,v 1.7.4.20 2005/01/31 13:03:36 komatsu Exp $
+# $Id: prime.rb,v 1.7.4.21 2005/01/31 23:37:44 komatsu Exp $
 #
 # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -14,14 +14,6 @@
 require 'prime/prime2'
 require 'prime/prime08'
 
-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'
-
 PRIME_CONFIGFILE_GLOBAL = File::join2(PRIME_CONFIG_DIR,  "Custom_prime.rb")
 PRIME_CONFIGFILE_LOCAL  = (ENV['PRIME_CONFIG'] or 
                              File::join2(PRIME_USER_DIR, "Custom_prime.rb"))
@@ -36,12 +28,8 @@
     Dir::ensure(PRIME_USER_DIR)
     initialize_rc()
 
-    @engines = init_engines(engine_files)
-
     initialize_prime2()
     initialize_prime08()
-
-    @flag_opened = true
   end
 
   def initialize_rc
@@ -80,54 +68,6 @@
     end
   end
 
-  def init_engines(engine_classes = nil)
-    engine_classes = (engine_classes or PRIME_ENV['engines'])
-    engines = engine_classes.map { | engine_class |
-      eval( engine_class.to_s ).new()
-    }
-
-    def engines.command (method, *args)
-      self.map {|engine|
-        engine.send(method, *args)
-      }
-    end
-
-    return engines
-  end
-
-  def add_engine (engine)
-    @engines << engine
-  end
-
-  def init
-    @engines.command(:init)
-  end
-
-  def exit
-    @engines.command(:exit)
-  end
-
-  def open
-    @engines.command(:open)
-  end
-
-  def close
-    if @flag_opened then
-      @engines.command(:close)
-      @flag_opened = false
-    end
-  end
-
-  def update
-    @engines.command(:update)
-    refresh()
-  end
-  def refresh
-    initialize_rc()
-    PrimeTypeConv::refresh()
-    @engines.command(:refresh)
-  end
-
   def get_env (key)
     return PRIME_ENV[key]
   end
Index: prime/lib/Makefile.am
diff -u prime/lib/Makefile.am:1.2.4.4 prime/lib/Makefile.am:1.2.4.5
--- prime/lib/Makefile.am:1.2.4.4	Mon Jan 31 22:03:36 2005
+++ prime/lib/Makefile.am	Tue Feb  1 08:37:45 2005
@@ -1,5 +1,5 @@
 # Makefile.am: Template of Automake for prime/lib.
-# $Id: Makefile.am,v 1.2.4.4 2005/01/31 13:03:36 komatsu Exp $
+# $Id: Makefile.am,v 1.2.4.5 2005/01/31 23:37:45 komatsu Exp $
 #
 # Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -12,7 +12,8 @@
 RUBY_FILES = prime.rb prime2.rb prime-japanese.rb prime-mixed.rb \
              protocol.rb server.rb session.rb \
              taiyaki.rb array-agent.rb \
-	     session-prime08.rb prime08.rb
+             session-japanese.rb session-english.rb \
+             session-prime08.rb prime08.rb composer.rb
 
 EXTRA_DIST = $(RUBY_FILES) prime-config.rb.in
 


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