Hiroyuki Komatsu
komat****@users*****
2004年 12月 22日 (水) 03:23:34 JST
Index: prime/lib/session.rb diff -u prime/lib/session.rb:1.4.4.14 prime/lib/session.rb:1.4.4.15 --- prime/lib/session.rb:1.4.4.14 Tue Dec 21 00:16:51 2004 +++ prime/lib/session.rb Wed Dec 22 03:23:34 2004 @@ -1,5 +1,5 @@ # session.rb -# $Id: session.rb,v 1.4.4.14 2004/12/20 15:16:51 komatsu Exp $ +# $Id: session.rb,v 1.4.4.15 2004/12/21 18:23:34 komatsu Exp $ # # Copyright (C) 2001 Satoru Takabayashi <sator****@namaz*****> # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****> @@ -299,6 +299,8 @@ "set display mode of the preedition.\n" + " MODE = [default, katakana, half_katakana, \n" + " wide_ascii, raw]") + add_command(:edit_commit, [:SESSION], + "commit the current preediting string") add_command(:context_reset, [:SESSION], "reset the context.") @@ -412,6 +414,11 @@ end end + def edit_commit (session) + commited_string =****@prime*****_commit(session) + return reply_successful(commited_string) + end + ## ## Context methods ## @@ -444,8 +451,8 @@ end def conv_commit (session) - @prime.conv_commit(session) - return reply_successful() + commited_string =****@prime*****_commit(session) + return reply_successful(commited_string) end ## Index: prime/lib/prime2.rb diff -u prime/lib/prime2.rb:1.1.2.7 prime/lib/prime2.rb:1.1.2.8 --- prime/lib/prime2.rb:1.1.2.7 Tue Dec 21 00:16:51 2004 +++ prime/lib/prime2.rb Wed Dec 22 03:23:34 2004 @@ -1,5 +1,5 @@ # prime2.rb: Module for PRIME2 protocol. -# $Id: prime2.rb,v 1.1.2.7 2004/12/20 15:16:51 komatsu Exp $ +# $Id: prime2.rb,v 1.1.2.8 2004/12/21 18:23:34 komatsu Exp $ # # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -84,10 +84,14 @@ composer.cursor_left_edge() return true end + + ## This returns a list of the preediting string divided by the cursor + ## position. def edit_get_preedition (session) composer = session_get_composer(session) return composer.edit_get_preediting_string() end + def edit_get_query_string (session) composer = session_get_composer(session) return composer.edit_get_query_string() @@ -114,6 +118,29 @@ return true end + def edit_commit (session) + reading = edit_get_preedition(session).join() + + ## Commit the current conversion + base = reading + base_reading = reading + pos = nil + context = session_get_context(session) + adjunct = "" + rest = "" + @engines.command(:learn_word, + base_reading, base, pos, context, adjunct, rest) + + ## Set next context + context_reset(session) + context_set_previous_word(session, reading) + + ## Reset the conversion. + edit_erase(session) + + return reading + end + ## ## Context methods ## @@ -144,11 +171,12 @@ context = session_get_context(session) conversions_compact = convert_compact( composer, context) + ## FIXME: Delete the magic number. + ## FIXME: (2004-12-22) <Hiro> + conversions_compact.add_score( 50000 ) conversions_japanese = convert_japanese(composer, context) conversions_overall = convert_overall( composer, context) - ## FIXME: Shrink verbose candidates. - ## FIXME: (2004-12-19) <Hiro> conversions = PrimeConversionList::merge( conversions_compact, conversions_japanese, conversions_overall ) @@ -174,19 +202,26 @@ end def conv_select (session, index) - selected_candidate = session_set_selection(session, index) - return selected_candidate + conversion = session_set_selection(session, index) + return conversion end def conv_commit (session) conversion = session_get_selection(session) + ## Commit the current conversion conversion.segments.each { | segment | learn_segment( segment, session_get_context(session) ) context_reset(session) context_set_previous_segment(session, segment) } + commited_string = conversion.get_literal() + + ## Reset the conversion. + edit_erase(session) + + return commited_string end def learn_segment (segment, context) @@ -630,6 +665,17 @@ @index_no = -1 end + ## This adds a score to each conversion. The first conversion increases + ## the base_score and the length of conversions, and the last conversion + ## increases the base_score. + def add_score (base_score) + base_score += ( self.length() - 1 ) + self.each { | conversion | + conversion.set_score( conversion.score + base_score ) + base_score -= 1 + } + end + def set_conversion_index (index_no) @index_no = index_no end @@ -695,6 +741,10 @@ return PrimeConversion.new(@segments.dup, @score, @position) end + def set_score (score) + @score = score + end + def get_segment () return @segments[@position] end