[prime-dev: 204] Re: PRIME 0.7.6 RC2 and prime-el 1.3.1 RC2

Back to archive index

Hiroyuki Komatsu komat****@taiya*****
2004年 1月 29日 (木) 02:24:05 JST


At Thu, 29 Jan 2004 01:40:45 +0900,
akira yamada wrote:
> > たとえば「沼」は「2.」とタイプしますが、この時
> >
> >   [2.]
> >   (沼)(沼田)(…
> >
> > のような表示になります。
> 
> PrimeTypeConv::convertに
> 数値への対応などが加わったことの副作用のようです。

みたいですね。お手数おかけしてすみません。

修正したファイルを添付します。(src/prime.src, lib/prime-japanese.rb)
また、この修正ファイルを適用すると --typing-method オプションを扱える
ようになります。

% prime --no-save --typing-method kana

デバッグ目的のオプションです。

-- 
                                                            小松弘幸
                                                -----------------------
                                                   http://taiyaki.org/

-------------- next part --------------
#!/usr/bin/env ruby
#
# PRIME: PRedictive Input Method Editor
# $Id: prime.src,v 1.1.2.3 2004/01/28 08:34:57 komatsu Exp $
#
# Copyright (C) 2001 Satoru Takabayashi <sator****@namaz*****>
# Copyright (C) 2002, 2003 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.
#

PRIME_LIBDIR = '%rubydir%'
$LOAD_PATH.unshift(PRIME_LIBDIR) unless $LOAD_PATH.member?(PRIME_LIBDIR)

require 'getoptlong'
require 'prime/prime'
require 'prime/session'
require "jcode"

include PogemoServer

PRIME_VERSION = '%PACKAGE_VERSION%'

class Session < SessionCore
  def initialize (pogemo, inport, outport)
    super
    @name = "prime"
    @version = PRIME_VERSION
    @id = ""

    add_command(:l, [:PATTERN],
		"look up PATTERN", 0)
    add_command(:lookup, [:PATTERN],
		"look up PATTERN", 0)
    add_command(:lookup_direct, [:PATTERN],
		"look up PATTERN for direct typing method", 0)
    add_command(:lookup_hybrid, [:PATTERN],
		"look up PATTERN with hybrid matching", 0)
    add_command(:lookup_prefix, [:PATTERN],
		"look up PATTERN with prefix matching", 0)
    add_command(:lookup_exact, [:PATTERN],
		"look up PATTERN with exact matching", 0)
    add_command(:lookup_expansion, [:PATTERN],
                "look up PATTERN from literal dictionaries", 0)
    add_command(:lookup_mixed, [:PATTERN],
                "look up PATTERN.  PATTERN can be mixed with pron and literal",
                0)
    add_command(:learn_word, [:KEY, :VALUE, :PART, :CONTEXT, :SUFFIX, :REST],
		"learn and record a word to the user dictionary", 2)
    add_command(:reset_context, [], "reset context")
    add_command(:set_context, [:CONTEXT], "set context to CONTEXT")
    add_command(:get_env, [:KEY], "get a variable associated with KEY")
    add_command(:get_label, [:PATTERN],
		"get a label string (e.g. hiragana) from a user input.")
    add_command(:preedit_convert_input, [:PATTERN],
                "convert a PATTERN and return a pair of a converted and a pending string.")
    add_command(:refresh, [],
                "refresh the statuses of the conversion engines.")
  end

  def learn_word (key, value, part = nil,
		  context = nil, suffix = nil, rest = nil)
    reply_successful {
      @pogemo.learn_word(key, value, part, context, suffix, rest)
    }
  end

  def l (pattern = "")
    reply_successful {
      @out.p****@pogem*****(pattern).to_text
    }
  end

  def lookup (pattern = "")
    reply_successful {
      @out.p****@pogem*****(pattern).to_text
    }
  end

  def lookup_direct (pattern = "")
    reply_successful {
      @out.p****@pogem*****_direct(pattern).to_text
    }
  end

  def get_env (key)
    reply_successful {
      env =****@pogem*****_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
      @out.puts output
    }
  end

  def get_label (pattern)
    reply_successful {
      @out.p****@pogem*****_label(pattern)
    }
  end

  def preedit_convert_input (pattern)
    reply_successful {
      @out.p****@pogem*****_convert_input(pattern)
    }
  end

  def set_context (context)
    reply_successful {
      @pogemo.set_context(context)
    }
  end

  def reset_context ()
    reply_successful {
      @pogemo.set_context(nil)
    }
  end
  
  def lookup_hybrid (pattern = "")
    reply_successful {
      @out.p****@pogem*****_hybrid(pattern).to_text
    }
  end

  def lookup_prefix (pattern = "")
    reply_successful {
      @out.p****@pogem*****_prefix(pattern).to_text
    }
  end

  def lookup_exact (pattern = "")
    reply_successful {
      @out.p****@pogem*****_exact(pattern).to_text
    }
  end

  def lookup_expansion (pattern = "")
    reply_successful {
      @out.p****@pogem*****_expansion(pattern).to_text
    }
  end

  def lookup_mixed (pattern = "")
    reply_successful {
      @out.p****@pogem*****_mixed(pattern).to_text
    }
  end

  def refresh ()
    reply_successful {
      @pogemo.refresh()
    }
  end
end

def show_usage
  puts "\
Usage: #{command_name} <options>
  -u, --unix-socket=PATH      run as Unix socket server with socket PATH
  -s, --tcp-server=PORT       run as TCP server with port PORT
  -v, --version               show the version and exit
  -h, --help                  show this help and exit
      --no-save               do not save learning records
      --typing-method=METHOD  run with the specified typing method.
  -d, --debug                 run under debug mode

HomePage: http://taiyaki.org/prime/ (in Japanese)
"
end

def command_name
  $0.split('/').last
end

def parse_options
  options = Hash.new

  parser = GetoptLong.new
  parser.set_options(['--help', '-h',           GetoptLong::NO_ARGUMENT],
		     ['--version','-v',		GetoptLong::NO_ARGUMENT],
		     ['--unix-socket',	'-u',	GetoptLong::REQUIRED_ARGUMENT],
		     ['--tcp-server',	'-s',	GetoptLong::REQUIRED_ARGUMENT],
		     ['--typing-method',        GetoptLong::REQUIRED_ARGUMENT],
		     ['--no-save',              GetoptLong::NO_ARGUMENT],
		     ['--debug', '-d',		GetoptLong::NO_ARGUMENT])

  parser.each_option {|option, arg|
    options[option.sub(/^--/, '')] = arg
  }

  if options['version'] then
    puts "#{command_name} #{PRIME_VERSION}"
    exit 1
  end

  if options['no-save'] then
    $PRIME_NO_SAVE = true
  else
    $PRIME_NO_SAVE = false
  end

  if options['help'] then
    show_usage
    exit 1
  end

  return options
end

def init ()
  @options = parse_options()

  if @options['typing-method'] then
    PrimeTypeConv::destroy_cache()
    PRIME_ENV['typing_method'] = @options['typing-method']
  end

  @prime = Prime.new()

  if @options['typing-method'] then
    PrimeTypeConv::destroy_cache()
  end
end

def main ()
  unless $PRIME_NO_SAVE then
    Thread.new do
      system('prime-userdict-update --auto --quiet')
      @prime.refresh()
    end
  end

  if @options['unix-socket']
    socket_path = @options['unix-socket']
    server = UnixSocketServer.new(@prime, socket_path)
  elsif @options['tcp-server']
    tcp_port = @options['tcp-server']
    server = TaiyakiTCPServer.new(@prime, tcp_port)
  else
    server = StdioServer.new(@prime)
  end

  if @options['debug'] or ENV['PRIME_DEBUG'] then
    Dir::ensure(PRIME_USER_DIR + "/logs")
    logfile = PRIME_USER_DIR + "/logs/debug_" +
              Time::new.strftime("%Y%m%d%H%M") + "_" + $$.to_s + ".log"
    server.set_debug(logfile)
  end

  server.accept()

  @prime.close()
end

init()

trap ("HUP") {
  @prime.refresh()
}

main()
-------------- next part --------------
テキスト形式以外の添付ファイルを保管しました...
ファイル名: prime-japanese.rb
型:         application/octet-stream
サイズ:     12691 バイト
説明:       無し
Download 


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