Hiroyuki Komatsu
komat****@users*****
2005年 1月 31日 (月) 22:03:36 JST
Index: prime/lib/session-prime08.rb diff -u /dev/null prime/lib/session-prime08.rb:1.1.2.1 --- /dev/null Mon Jan 31 22:03:36 2005 +++ prime/lib/session-prime08.rb Mon Jan 31 22:03:36 2005 @@ -0,0 +1,251 @@ +# 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 $ +# +# Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****> +# All rights reserved. +# This is free software with ABSOLUTELY NO WARRANTY. +# +# You can redistribute it and/or modify it under the terms of +# the GNU General Public License version 2. + +require 'prime/session' +require 'prime/prime-japanese' +require 'prime/prime-mixed' + +class PrimeSessionPrime08 < PrimeSession + include PrimeJapanese + include PrimeMixed + + def initialize (language = nil) + super + initialize_prime_japanese() + end + + def get_label (pattern) + return PrimeTypeConv::convert(pattern).join() + end + + def preedit_convert_input (pattern) + return PrimeTypeConv::convert(pattern).join("\t") + end + + def set_context (context) + @context = context + end + + def learn_word (pron, literal, pos = "", + context = "", suffix = "", rest = "") + pron = (pron or "").strip + literal = (literal or "").strip + pos = (pos or "").strip + context = (context or "").strip + suffix = (suffix or "").strip + rest = (rest or "").strip + + @engines.command(:learn_word, pron, literal, pos, context, suffix, rest) + end + + def lookup (string) + if PRIME_ENV['typing_method'] == 'tcode' or + PRIME_ENV['typing_method'] == 'handwrite' then + word_list = lookup_direct(string) + else + word_list = lookup_compact(string) + end + return word_list + end + def lookup_all (string) + if PRIME_ENV['typing_method'] == 'tcode' or + PRIME_ENV['typing_method'] == 'handwrite' then + word_list = lookup_direct_all(string) + else + word_list = lookup_compact_all(string) + end + return word_list + end + + def lookup_hybrid (string) + words = search_hybrid(string, 10) + result = PrimeWordList::merge_with_label(@context, words) + return result + end + def lookup_hybrid_all (string) + words = search_hybrid(string) + result = PrimeWordList::merge_with_label(@context, words) + return result + end + + def lookup_direct (string) + results_expansion = lookup_expansion(string) + results = PrimeWordList::merge_by_literal(@context, results_expansion) + return results[0,3] + end + + def lookup_direct_all (string) + # results_prefix = lookup_prefix(string) + results_expansion = lookup_expansion(string) + results_mixed = lookup_mixed(string) + words_japanese = search_japanese(string) + words_overall = search_overall(string) + + results = PrimeWordList::merge_by_literal(@context, + # results_prefix[0, 3], + results_expansion, + results_mixed, + words_japanese, + words_overall) + return PrimeWordList.new(results_expansion[0,3] | results) + end + + def lookup_compact (string) + words_compact = search_compact(string) + words = PrimeWordList::merge_with_label(@context, words_compact) + return words + end + def lookup_compact_all (string) + words_compact = search_compact(string) + words_overall = search_overall(string) + words_japanese = search_japanese(string) + results_compact = PrimeWordList::merge_with_label(@context, + words_compact) + results_conversion = PrimeWordList::merge_with_label(@context, + words_overall, + words_japanese) + return PrimeWordList::concat(results_compact | results_conversion) + end + + def lookup_prefix (string) + words_prefix = search_prefix(string) + return PrimeWordList::merge_with_label(@context, words_prefix) + end + + def lookup_prefix_ex (string) + words_prefix = search_prefix(string) + results_expansion = lookup_expansion(string) + return PrimeWordList::merge_with_label(@context, + words_prefix, + results_expansion) + end + + def lookup_exact (string) + words_exact = search_exact(string) + return PrimeWordList::merge_with_label(@context, words_exact) + end + + def lookup_overall (string) + words_overall = search_overall(string) + return PrimeWordList::merge_with_label(@context, words_overall) + end + + def lookup_expansion (string) + # 「予→予測」 + expands = PrimeTypeConv::expand(string) + query = PrimeQuery.new(expands, nil, :literal_prefix, @context) + results = lookup_internal(query) + return results + end + + def search (query) + query.input.uniq!() + words_list =****@engin*****(:search, query) + return PrimeWordList::merge(words_list) + end + + def search_prefix (string) + # 「よ→予測」 + expands = PrimeTypeConv::expand(string) + query = PrimeQuery.new(expands, nil, :prefix, @context) + words = search(query) + return words + end + + def search_exact (string) + # 「よそく→予測」 + converted = PrimeTypeConv::convert(string).join() + query = PrimeQuery.new([converted, string], nil, :exact, @context) + words = search(query) + return words + 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 + + def search_compact (string) + words_prefix = search_prefix(string) + + ## If the result of search_prefix is empty, this method stops the following + ## search_japanese_uniclause for the quickness. + if words_prefix.empty? then + ## Ruby 1.6 does not keep the class PrimeWordList word[0,1] if the + ## value of word is [], and the class of the result of word[0,1] + ## becomes Array which is a super class of PrimewordList. + return PrimeWordList.new() + end + + words_japanese = search_japanese_uniclause(string) + words_compact = PrimeWordList::merge(words_prefix, words_japanese)[0,1] + + if words_compact.length > 0 then + predict_with_multi_clauses!(words_compact) + + words_compact[1..-1].each {|word| + word.score = words_compact[0].score + } + end + return words_compact + end + + def search_hybrid (string, max = nil) + words_prefix = search_prefix(string) + words_japanese = search_japanese(string) + words_overall = search_overall(string) + + num_prefix = 3 + num_max_prefix = 10 + if (num_max_prefix - words_japanese.length) > num_prefix then + num_prefix = (num_max_prefix - words_japanese.length) + end + words = PrimeWordList::merge_with_label(@context, + words_prefix[0,num_prefix], + words_overall, + words_japanese) + if max then + words = words[0,max] + end + predict_with_multi_clauses!(words) + + return words + end + + + private + def lookup_internal (query) + query.input.uniq!() + words_list =****@engin*****(:search, query) + return PrimeWordList::merge_with_label(@context, words_list) + end + + def predict_with_multi_clauses!(results) + unless results.empty? then + word1 = results.first + context = (word1.literal + word1.conjugation) + query = PrimeQuery.new([""], nil, :context, context) + word2 = search(query).first + if word2.non_nil? then + results.push(_merge_words(word1, word2)) + end + end + return results + end +end Index: prime/lib/prime2.rb diff -u prime/lib/prime2.rb:1.1.2.14 prime/lib/prime2.rb:1.1.2.15 --- prime/lib/prime2.rb:1.1.2.14 Mon Jan 31 03:30:56 2005 +++ prime/lib/prime2.rb Mon Jan 31 22:03:36 2005 @@ -1,5 +1,5 @@ # prime2.rb: Module for PRIME2 protocol. -# $Id: prime2.rb,v 1.1.2.14 2005/01/30 18:30:56 komatsu Exp $ +# $Id: prime2.rb,v 1.1.2.15 2005/01/31 13:03:36 komatsu Exp $ # # Copyright (C) 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -10,6 +10,7 @@ require 'suikyo/suikyo-composer' require 'prime/session.rb' +require 'prime/session-prime08' module Prime2 def initialize_prime2 () Index: prime/lib/prime08.rb diff -u /dev/null prime/lib/prime08.rb:1.1.2.1 --- /dev/null Mon Jan 31 22:03:36 2005 +++ prime/lib/prime08.rb Mon Jan 31 22:03:36 2005 @@ -0,0 +1,79 @@ +# 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 $ +# +# Copyright (C) 2005 Hiroyuki Komatsu <komat****@taiya*****> +# All rights reserved. +# This is free software with ABSOLUTELY NO WARRANTY. +# +# You can redistribute it and/or modify it under the terms of +# the GNU General Public License version 2. + +module Prime08 + def initialize_prime08 () + @session_prime08 = PrimeSessionPrime08.new() + end + + def get_label (pattern) + return @session_prime08.get_label(pattern) + end + + def preedit_convert_input (pattern) + return @session_prime08.preedit_convert_input(pattern) + end + + def set_context (context) + @session_prime08.set_context(context) + end + + def learn_word (pron, literal, pos = "", + context = "", suffix = "", rest = "") + @session_prime08.learn_word(pron, literal, pos, context, suffix, rest) + end + + def lookup (string) + return @session_prime08.lookup(string) + end + def lookup_all (string) + return @session_prime08.lookup_all(string) + end + + def lookup_hybrid (string) + return @session_prime08.lookup_hybrid(string) + end + def lookup_hybrid_all (string) + return @session_prime08.lookup_hybrid_all(string) + end + + def lookup_direct (string) + return @session_prime08.lookup_direct(string) + end + def lookup_direct_all (string) + return @session_prime08.lookup_direct_all(string) + end + + def lookup_compact (string) + return @session_prime08.lookup_compact(string) + end + def lookup_compact_all (string) + return @session_prime08.lookup_compact_all(string) + end + + def lookup_prefix (string) + return @session_prime08.lookup_prefix(string) + end + def lookup_prefix_ex (string) + return @session_prime08.lookup_prefix_ex(string) + end + + def lookup_exact (string) + return @session_prime08.lookup_exact(string) + end + + def lookup_overall (string) + return @session_prime08.lookup_overall(string) + end + + def lookup_expansion (string) + return @session_prime08.lookup_expansion(string) + end +end Index: prime/lib/prime.rb diff -u prime/lib/prime.rb:1.7.4.19 prime/lib/prime.rb:1.7.4.20 --- prime/lib/prime.rb:1.7.4.19 Mon Jan 31 04:45:48 2005 +++ prime/lib/prime.rb Mon Jan 31 22:03:36 2005 @@ -1,5 +1,5 @@ # prime/prime.rb -# $Id: prime.rb,v 1.7.4.19 2005/01/30 19:45:48 komatsu Exp $ +# $Id: prime.rb,v 1.7.4.20 2005/01/31 13:03:36 komatsu Exp $ # # Copyright (C) 2002, 2003, 2004 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -12,8 +12,7 @@ require 'prime/prime-config' require 'prime/taiyaki' require 'prime/prime2' -require 'prime/prime-japanese' -require 'prime/prime-mixed' +require 'prime/prime08' require 'prime/engine/engine-basic' require 'prime/engine/engine-english' @@ -30,8 +29,7 @@ class Prime include Debug include Prime2 - include PrimeJapanese - include PrimeMixed + include Prime08 def initialize (engine_files = nil) @debug_mode = false @@ -39,10 +37,9 @@ initialize_rc() @engines = init_engines(engine_files) - @context = nil - initialize_prime_japanese() initialize_prime2() + initialize_prime08() @flag_opened = true end @@ -135,130 +132,6 @@ return PRIME_ENV[key] end - def get_label (pattern) - return PrimeTypeConv::convert(pattern).join() - end - - def preedit_convert_input (pattern) - return PrimeTypeConv::convert(pattern).join("\t") - end - - def set_context (context) - @context = context - end - - def learn_word (pron, literal, pos = "", - context = "", suffix = "", rest = "") - pron = (pron or "").strip - literal = (literal or "").strip - pos = (pos or "").strip - context = (context or "").strip - suffix = (suffix or "").strip - rest = (rest or "").strip - - @engines.command(:learn_word, pron, literal, pos, context, suffix, rest) - end - - def lookup (string) - if PRIME_ENV['typing_method'] == 'tcode' or - PRIME_ENV['typing_method'] == 'handwrite' then - word_list = lookup_direct(string) - else - word_list = lookup_compact(string) - end - return word_list - end - def lookup_all (string) - if PRIME_ENV['typing_method'] == 'tcode' or - PRIME_ENV['typing_method'] == 'handwrite' then - word_list = lookup_direct_all(string) - else - word_list = lookup_compact_all(string) - end - return word_list - end - - def lookup_hybrid (string) - words = search_hybrid(string, 10) - result = PrimeWordList::merge_with_label(@context, words) - return result - end - def lookup_hybrid_all (string) - words = search_hybrid(string) - result = PrimeWordList::merge_with_label(@context, words) - return result - end - - def lookup_direct (string) - results_expansion = lookup_expansion(string) - results = PrimeWordList::merge_by_literal(@context, results_expansion) - return results[0,3] - end - - def lookup_direct_all (string) - # results_prefix = lookup_prefix(string) - results_expansion = lookup_expansion(string) - results_mixed = lookup_mixed(string) - words_japanese = search_japanese(string) - words_overall = search_overall(string) - - results = PrimeWordList::merge_by_literal(@context, - # results_prefix[0, 3], - results_expansion, - results_mixed, - words_japanese, - words_overall) - return PrimeWordList.new(results_expansion[0,3] | results) - end - - def lookup_compact (string) - words_compact = search_compact(string) - words = PrimeWordList::merge_with_label(@context, words_compact) - return words - end - def lookup_compact_all (string) - words_compact = search_compact(string) - words_overall = search_overall(string) - words_japanese = search_japanese(string) - results_compact = PrimeWordList::merge_with_label(@context, - words_compact) - results_conversion = PrimeWordList::merge_with_label(@context, - words_overall, - words_japanese) - return PrimeWordList::concat(results_compact | results_conversion) - end - - def lookup_prefix (string) - words_prefix = search_prefix(string) - return PrimeWordList::merge_with_label(@context, words_prefix) - end - - def lookup_prefix_ex (string) - words_prefix = search_prefix(string) - results_expansion = lookup_expansion(string) - return PrimeWordList::merge_with_label(@context, - words_prefix, - results_expansion) - end - - def lookup_exact (string) - words_exact = search_exact(string) - return PrimeWordList::merge_with_label(@context, words_exact) - end - - def lookup_overall (string) - words_overall = search_overall(string) - return PrimeWordList::merge_with_label(@context, words_overall) - end - - def lookup_expansion (string) - # 「予→予測」 - expands = PrimeTypeConv::expand(string) - query = PrimeQuery.new(expands, nil, :literal_prefix, @context) - results = lookup_internal(query) - return results - end - def check_existence (pron, pos, literal) results =****@engin*****(:check_existence, pron, literal, pos) results.each {|result| @@ -267,112 +140,6 @@ return false end - - def search (query) - query.input.uniq!() - p query - words_list =****@engin*****(:search, query) - return PrimeWordList::merge(words_list) - end - - def search_prefix (string) - # 「よ→予測」 - expands = PrimeTypeConv::expand(string) - query = PrimeQuery.new(expands, nil, :prefix, @context) - words = search(query) - return words - end - - def search_exact (string) - # 「よそく→予測」 - converted = PrimeTypeConv::convert(string).join() - query = PrimeQuery.new([converted, string], nil, :exact, @context) - words = search(query) - return words - 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 - - def search_compact (string) - words_prefix = search_prefix(string) - - ## If the result of search_prefix is empty, this method stops the following - ## search_japanese_uniclause for the quickness. - if words_prefix.empty? then - ## Ruby 1.6 does not keep the class PrimeWordList word[0,1] if the - ## value of word is [], and the class of the result of word[0,1] - ## becomes Array which is a super class of PrimewordList. - return PrimeWordList.new() - end - - words_japanese = search_japanese_uniclause(string) - words_compact = PrimeWordList::merge(words_prefix, words_japanese)[0,1] - - if words_compact.length > 0 then - predict_with_multi_clauses!(words_compact) - - words_compact[1..-1].each {|word| - word.score = words_compact[0].score - } - end - return words_compact - end - - def search_hybrid (string, max = nil) - words_prefix = search_prefix(string) - words_japanese = search_japanese(string) - words_overall = search_overall(string) - - num_prefix = 3 - num_max_prefix = 10 - if (num_max_prefix - words_japanese.length) > num_prefix then - num_prefix = (num_max_prefix - words_japanese.length) - end - words = PrimeWordList::merge_with_label(@context, - words_prefix[0,num_prefix], - words_overall, - words_japanese) - if max then - words = words[0,max] - end - predict_with_multi_clauses!(words) - - return words - end - - - private - def lookup_internal (query) - query.input.uniq!() - words_list =****@engin*****(:search, query) - return PrimeWordList::merge_with_label(@context, words_list) - end - - def predict_with_multi_clauses!(results) - unless results.empty? then - word1 = results.first - context = (word1.literal + word1.conjugation) - query = PrimeQuery.new([""], nil, :context, context) - word2 = search(query).first - if word2.non_nil? then - results.push(_merge_words(word1, word2)) - end - end - return results - end - public ## This returns an avairable prefix string for the literal. ## ex). get_prefix("This", "is") => " " Index: prime/lib/Makefile.am diff -u prime/lib/Makefile.am:1.2.4.3 prime/lib/Makefile.am:1.2.4.4 --- prime/lib/Makefile.am:1.2.4.3 Mon Jan 31 03:30:56 2005 +++ prime/lib/Makefile.am Mon Jan 31 22:03:36 2005 @@ -1,5 +1,5 @@ # Makefile.am: Template of Automake for prime/lib. -# $Id: Makefile.am,v 1.2.4.3 2005/01/30 18:30:56 komatsu Exp $ +# $Id: Makefile.am,v 1.2.4.4 2005/01/31 13:03:36 komatsu Exp $ # # Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****> # All rights reserved. @@ -11,7 +11,8 @@ SUBDIRS = engine grammar makedict RUBY_FILES = prime.rb prime2.rb prime-japanese.rb prime-mixed.rb \ protocol.rb server.rb session.rb \ - taiyaki.rb array-agent.rb + taiyaki.rb array-agent.rb \ + session-prime08.rb prime08.rb EXTRA_DIST = $(RUBY_FILES) prime-config.rb.in