Hiroyuki Komatsu
komat****@users*****
2005年 1月 11日 (火) 04:20:09 JST
Index: suikyo/ruby/src/suikyo.rb diff -u suikyo/ruby/src/suikyo.rb:1.16 suikyo/ruby/src/suikyo.rb:1.17 --- suikyo/ruby/src/suikyo.rb:1.16 Mon Dec 13 18:06:02 2004 +++ suikyo/ruby/src/suikyo.rb Tue Jan 11 04:20:09 2005 @@ -1,5 +1,5 @@ # suikyo.rb: Romaji-Hiragana conversion library for Ruby -# $Id: suikyo.rb,v 1.16 2004/12/13 09:06:02 komatsu Exp $ +# $Id: suikyo.rb,v 1.17 2005/01/10 19:20:09 komatsu Exp $ # # Copyright (C) 2002 - 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -169,6 +169,33 @@ end end + ## This removes the string entry from the Suikyo table tree. + ## If a child tree does not exist it returns ture. + def unset (string) + head = string.split(//)[0] + rest = string.split(//)[1..-1].join() + + if @word[head].nil? then + return true + end + + if rest == "" then + if @word[head].subtable.nil? or @word[head].subtable.allword.empty? then + @word.delete(head) + return true + end + + @word[head].result = nil + @word[head].cont = nil + else + if @word[head].subtable.unset(rest) then + @word.delete(head) + return true + end + end + return false + end + def loadfile (filename, tablepath = nil) filepath = SuikyoTable::loadpath(filename, tablepath) if FileTest::exist?(filepath) then @@ -188,7 +215,11 @@ end unless line =~ /^\#|^\s*$/ or comment_flag then (string, result, cont) = line.sub(/^ /, "").split(/\t/) - self.set(string, result, cont) + if result.nil? then + self.unset(string) + else + self.set(string, result, cont) + end end if line =~ /\*\// then comment_flag = false Index: suikyo/ruby/src/suikyo-composer.rb diff -u suikyo/ruby/src/suikyo-composer.rb:1.9 suikyo/ruby/src/suikyo-composer.rb:1.10 --- suikyo/ruby/src/suikyo-composer.rb:1.9 Thu Dec 23 16:37:25 2004 +++ suikyo/ruby/src/suikyo-composer.rb Tue Jan 11 04:20:09 2005 @@ -1,6 +1,6 @@ # suikyo-composer.rb: Preedition composer using Suikyo. # This library is for input methods such as PRIME. -# $Id: suikyo-composer.rb,v 1.9 2004/12/23 07:37:25 komatsu Exp $ +# $Id: suikyo-composer.rb,v 1.10 2005/01/10 19:20:09 komatsu Exp $ # # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -35,6 +35,33 @@ @conversion = [] end + ## It returns a duplicated value of pending. + def pending_copy () + if****@pendi*****? then + return nil + else + retur****@pendi*****() + end + end + + ## It returns a duplicated value of original. + def original_copy () + if****@origi*****? then + return nil + else + retur****@origi*****() + end + end + + ## It returns a duplicated value of conversion. + def conversion_copy () + if****@conve*****? then + return nil + else + retur****@conve*****() + end + end + def length () return (@pending.length() +****@conve*****()) end @@ -103,13 +130,14 @@ until orig_chunk.chunk_next == @tail_chunk do orig_chunk = orig_chunk.chunk_next new_chunk = SuikyoCharChunk.new_next(new_chunk) - new_chunk.conversion = orig_chunk.conversion.dup() - new_chunk.original = orig_chunk.original.dup() - new_chunk.pending = orig_chunk.pending.dup() + new_chunk.conversion = orig_chunk.conversion_copy() + new_chunk.original = orig_chunk.original_copy() + new_chunk.pending = orig_chunk.pending_copy() end return [new_head_chunk, new_tail_chunk] end + private :chunk_copy # def set_composer (head_chunk, tail_chunk, position = 0) # @position = position @@ -162,25 +190,6 @@ end private :undo_set - ## This copys its chunks and returns a pair of the head and the tail. - def chunk_copy () - new_head_chunk = SuikyoCharChunk.new() - new_tail_chunk = SuikyoCharChunk.new_next(new_head_chunk) - new_chunk = new_head_chunk - - orig_chunk = @head_chunk - until orig_chunk.chunk_next == @tail_chunk do - orig_chunk = orig_chunk.chunk_next - new_chunk = SuikyoCharChunk.new_next(new_chunk) - new_chunk.conversion = orig_chunk.conversion.dup() - new_chunk.original = orig_chunk.original.dup() - new_chunk.pending = orig_chunk.pending.dup() - end - - return [new_head_chunk, new_tail_chunk] - end - private :chunk_copy - ## This method reads the @undo_data and sets them to the current status. ## If @undo_data contains no data this return false. def undo () @@ -663,7 +672,7 @@ else pending_chunk = chunk pending_chunk.conversion = [] - pending_chunk.pending = pending_chunk.original.dup + pending_chunk.pending = pending_chunk.original_copy() end end end @@ -902,11 +911,11 @@ chunk.conversion = [] chunk.pending = left_original - chunk.original = left_original.dup + chunk.original = left_original.dup() right_chunk = SuikyoCharChunk.new_next(chunk) right_chunk.conversion = [] right_chunk.pending = right_original - right_chunk.original = right_original.dup + right_chunk.original = right_original.dup() return true end