[Prime-cvs] CVS update: prime/src

Back to archive index

Hiroyuki Komatsu komat****@users*****
2005年 3月 7日 (月) 16:51:34 JST


Index: prime/src/prime-dict-convert.src
diff -u prime/src/prime-dict-convert.src:1.3 prime/src/prime-dict-convert.src:1.4
--- prime/src/prime-dict-convert.src:1.3	Mon May 31 14:27:33 2004
+++ prime/src/prime-dict-convert.src	Mon Mar  7 16:51:34 2005
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 # prime-dict-convert: A dictionary converter from a dictionary of another IME
-# $Id: prime-dict-convert.src,v 1.3 2004/05/31 05:27:33 komatsu Exp $
+# $Id: prime-dict-convert.src,v 1.4 2005/03/07 07:51:34 komatsu Exp $
 #
 # Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
@@ -9,10 +9,6 @@
 # You can redistribute it and/or modify it under the terms of 
 # the GNU General Public License version 2.
 
-trap ("HUP") {
-  $stderr.puts "prime-dict-convert:SIGHUP #{$$}"
-}
-
 PRIME_LIBDIR = '%rubydir%'
 $LOAD_PATH.unshift(PRIME_LIBDIR) unless $LOAD_PATH.member?(PRIME_LIBDIR)
 
@@ -21,8 +17,21 @@
 require 'prime/makedict/dictformat-skkdic'
 require 'prime/makedict/dictformat-pubdic'
 require 'prime/makedict/dictformat-cannadic'
+require 'prime/makedict/dictformat-adambnc'
+require 'prime/makedict/dictformat-wordnet'
+require 'prime/makedict/dictformat-usage'
 require 'prime/makedict/basicdict'
 
+begin
+  ## The following files require MeCab.
+  Kernel::require('prime/makedict/dictformat-wordlist')
+  Kernel::require('prime/makedict/dictformat-text')
+rescue LoadError
+  FLAG_MECAB = false
+else
+  FLAG_MECAB = true
+end
+
 class PrimeDictConvertCommand
   include Debug
 
@@ -35,6 +44,20 @@
     @output_dictname = nil
     @input_dictnames = []
 
+    @formats = {:prime    => [DictFormat],
+                :pubdic   => [DictFormatPubdic],
+                :canna    => [DictFormatCannadic],
+                :skk      => [DictFormatSkkdic],
+                :usage    => [DictFormatUsage],
+                :adambnc  => [DictFormatAdamBNC],
+                :wordnet  => [DictFormatWordNet],
+    }
+    if FLAG_MECAB then
+      @formats[:wordlist] = DictFormatWordlist
+      @formats[:text]     = DictFormatText
+      @formats[:gaim]     = DictFormatGaim
+    end
+
     @command_name = command_name
     @version = '%PACKAGE_VERSION%'
     @usage = <<"EOF"
@@ -44,11 +67,19 @@
        --append    : append words to the existent output dictionary. (default)
        --overwrite : delete the existent output dictionary and make new dict.
 
-       --prime  :  merge the input_dict with the output_dict
-       --canna  :  convert from the canna dict
-       --skk    :  convert from the skk dict
-       --pubdic :  convert from the pubdic dict
+       --prime    :  merge the input_dict with the output_dict
+       --canna    :  convert from the canna dict
+       --skk      :  convert from the skk dict
+       --pubdic   :  convert from the pubdic dict
+       --usage    :  convert from the usage dict (beta)
+       --adambnc  :  convert from the Adam\'s BNC word frequency list (beta)
+       --wordnet  :  convert from the WordNet cntlist
+       --wordlist :  convert from the wordlist without the readings and POSes
+                     (beta)
+       --text     :  convert from the plain text file (beta)
+       --gaim     :  convert from the Gaim log (beta)
 
+       --no-index :  convert only without indexing
   -q,  --quiet    :  run this command and show nothing.
   -v,  --version  :  show the version and exit
   -h,  --help     :  show this help and exit
@@ -56,7 +87,7 @@
 EOF
   end
 
-  def main ()
+  def main ()  
     parse_options()
 
     if @output_dictname.nil? or @input_dictnames.empty? then
@@ -77,18 +108,13 @@
 
     converter = nil
     @input_dictnames.each {|(type, filename)|
-      if type == :prime then
-	converter = DictFormat.new(@is_interactive)
-      elsif type == :skk then
-	converter = DictFormatSkkdic.new(@is_interactive)
-      elsif type == :canna then
-	converter = DictFormatCannadic.new(@is_interactive)
-      elsif type == :pubdic then
-	converter = DictFormatPubdic.new(@is_interactive)
+      if****@forma*****_key?(type) then
+        converter = @formats[type][0].new(@is_interactive)
       else
 	puts "Invalid format option..."
 	exit()
       end
+
       converter.dict = dict
       converter.load_external_dict(filename)
       dict = converter.dict
@@ -96,7 +122,10 @@
     converter.save_dict(@output_dictname)
   end
 
-  def index_dict
+  def index_dict ()
+    if @flag_index == false then
+      return
+    end
     indexer = PrimeBasicdict.new(@output_dictname, @is_interactive)
     indexer.make_pos_table()
     indexer.make_basicdict_indexes()
@@ -114,17 +143,19 @@
   def parse_options ()
     options = {}
     parser = GetoptLong.new()
-    parser.set_options(['--help',       '-h',   GetoptLong::NO_ARGUMENT],
-		       ['--version',    '-v',   GetoptLong::NO_ARGUMENT],
-		       ['--debug',      '-d',   GetoptLong::NO_ARGUMENT],
-                       ['--quiet',      '-q',   GetoptLong::NO_ARGUMENT],
-		       ['--append',             GetoptLong::NO_ARGUMENT],
-		       ['--overwrite',          GetoptLong::NO_ARGUMENT],
-		       ['--prime',              GetoptLong::REQUIRED_ARGUMENT],
-		       ['--canna',              GetoptLong::REQUIRED_ARGUMENT],
-		       ['--skk',                GetoptLong::REQUIRED_ARGUMENT],
-		       ['--pubdic',             GetoptLong::REQUIRED_ARGUMENT]
-		       )
+    option_list = [
+      ['--help',       '-h',   GetoptLong::NO_ARGUMENT],
+      ['--version',    '-v',   GetoptLong::NO_ARGUMENT],
+      ['--debug',      '-d',   GetoptLong::NO_ARGUMENT],
+      ['--quiet',      '-q',   GetoptLong::NO_ARGUMENT],
+      ['--append',             GetoptLong::NO_ARGUMENT],
+      ['--overwrite',          GetoptLong::NO_ARGUMENT],
+      ['--no-index',           GetoptLong::NO_ARGUMENT],
+    ]
+    @formats.keys.each { | key |
+      option_list.push( ['--' + key.to_s(), GetoptLong::REQUIRED_ARGUMENT] )
+    }
+    parser.set_options(*option_list)
 
     parser.each_option {|option, arg|
       options[option.sub(/^--/, '')] = arg
@@ -154,18 +185,19 @@
       @flag_append = false
     end
 
-    if options['prime'] then
-      @input_dictnames.push([:prime, options['prime']])
-    end
-    if options['pubdic'] then
-      @input_dictnames.push([:pubdic, options['pubdic']])
-    end
-    if options['canna'] then
-      @input_dictnames.push([:canna, options['canna']])
-    end
-    if options['skk'] then
-      @input_dictnames.push([:skk, options['skk']])
+    if options['no-index'] then
+      @flag_index = false
+    else
+      @flag_index = true
     end
+
+    @formats.keys.each { | format |
+      argument = options[format.to_s]
+      if argument then
+        @input_dictnames.push([format, argument])
+      end
+    }
+        
   end
 end
 
@@ -175,3 +207,9 @@
   conv_command = PrimeDictConvertCommand.new(File::basename($0))
   conv_command.main()
 end
+
+
+# --- Text properties for Emacs. ---
+# Local variables:
+# mode: ruby
+# End:
Index: prime/src/prime-refresh.src
diff -u prime/src/prime-refresh.src:1.3 prime/src/prime-refresh.src:1.4
--- prime/src/prime-refresh.src:1.3	Mon May 31 14:27:33 2004
+++ prime/src/prime-refresh.src	Mon Mar  7 16:51:34 2005
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 #### prime-userdict-update: Command to update a userdict of PRIME.
-#### $Id: prime-refresh.src,v 1.3 2004/05/31 05:27:33 komatsu Exp $
+#### $Id: prime-refresh.src,v 1.4 2005/03/07 07:51:34 komatsu Exp $
 ####
 #### Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****>
 ####     All rights reserved.
@@ -9,11 +9,6 @@
 #### You can redistribute it and/or modify it under the terms of 
 #### the GNU General Public License version 2.
 
-trap ("HUP") {
-#  $stderr.puts "prime-refresh:SIGHUP #{$$}"
-  exit()
-}
-
 PRIME_LIBDIR = '%rubydir%'
 $LOAD_PATH.unshift(PRIME_LIBDIR) unless $LOAD_PATH.member?(PRIME_LIBDIR)
 
@@ -23,7 +18,6 @@
   IO::popen('ps ax').readlines.each {|line|
     (pid, tty, stat, time, *command) = line.chomp.split(/ +/)
     if command[0] =~ /ruby/ and command[1] =~ /prime$/ then
-#      $stderr.puts "#{$$}: #{line}"
       system('kill', '-HUP', pid)
     end
   }
Index: prime/src/prime-userdict-convert.src
diff -u prime/src/prime-userdict-convert.src:1.2 prime/src/prime-userdict-convert.src:1.3
--- prime/src/prime-userdict-convert.src:1.2	Fri Mar 26 02:19:51 2004
+++ prime/src/prime-userdict-convert.src	Mon Mar  7 16:51:34 2005
@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
-# prime-convert-userdict: A command to convert from userdict2 to <new user dict?> for PRIME.
-# $Id: prime-userdict-convert.src,v 1.2 2004/03/25 17:19:51 komatsu Exp $
+# prime-userdict-convert: A command to convert from userdict2 to
+#                         <new user dict?> for PRIME.
+# $Id: prime-userdict-convert.src,v 1.3 2005/03/07 07:51:34 komatsu Exp $
 
 # Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****>
 #     All rights reserved.
Index: prime/src/prime-userdict-update.src
diff -u prime/src/prime-userdict-update.src:1.4 prime/src/prime-userdict-update.src:1.5
--- prime/src/prime-userdict-update.src:1.4	Thu Jun 24 16:28:44 2004
+++ prime/src/prime-userdict-update.src	Mon Mar  7 16:51:34 2005
@@ -1,6 +1,6 @@
 #!/usr/bin/env ruby
 #### prime-userdict-update: Command to update a userdict of PRIME.
-#### $Id: prime-userdict-update.src,v 1.4 2004/06/24 07:28:44 komatsu Exp $
+#### $Id: prime-userdict-update.src,v 1.5 2005/03/07 07:51:34 komatsu Exp $
 ####
 #### Copyright (C) 2003 Hiroyuki Komatsu <komat****@taiya*****>
 ####     All rights reserved.
@@ -9,14 +9,9 @@
 #### You can redistribute it and/or modify it under the terms of 
 #### the GNU General Public License version 2.
 
-trap ("HUP") {
-#  $stderr.puts "prime-userdict-update:SIGHUP #{$$}"
-}
-
 PRIME_LIBDIR = '%rubydir%'
 $LOAD_PATH.unshift(PRIME_LIBDIR) unless $LOAD_PATH.member?(PRIME_LIBDIR)
 
-require 'ftools'
 require 'prime/prime-config'
 require 'prime/makedict/userdict'
 require 'getoptlong'
@@ -51,32 +46,6 @@
 EOF
   end
 
-  def create_tmpfilename (filepath, unique_key = "__tmp__")
-    path = File::dirname(filepath) + "/" +
-           unique_key + File::basename(filepath)
-    return path
-  end
-
-  def protect_userdict (output_dictname = @output_dictname,
-                        input_dictname  = @input_dictname)
-    tmp_keyword    = "__tmp__"
-    tmp_dictname   = create_tmpfilename(output_dictname, tmp_keyword)
-    input_dictname = File::expand_path(input_dictname)
-
-    Dir::glob(output_dictname + "*") {|filename|
-      if input_dictname.nil? or
-          File::expand_path(filename).index(input_dictname) != 0 then
-        File::copy(filename, create_tmpfilename(filename))
-      end
-    }
-
-    yield(tmp_dictname)
-
-    Dir::glob(tmp_dictname + "*") {|filename|
-      File::rename(filename, filename.sub(tmp_keyword, ""))
-    }
-  end
-
   def main ()
     parse_options()
 
@@ -85,34 +54,29 @@
 	print_usage()
 	exit()
       end
-
-      protect_userdict(@output_dictname, @input_dictname) {|tmp_dictname|
-        prime_update = PrimeUserdictUpdate.new(tmp_dictname, @is_interactive)
-        if prime_update.check_necessity(@input_dictname) then
-          prime_update.update(@input_dictname)
-          prime_update.delete_files(@input_dictname)
-        end
-
-        if @indexing then # with --conversion and --indexing
-          prime_makeindex =
-               PrimeUserdictMakeIndex.new(tmp_dictname, @is_interactive)
-          prime_makeindex.make_indexes()
-        end
-      }
-    elsif @indexing then # with --indexing
-      if @output_dictname.nil? then
-        print_usage()
-        exit()
+      prime_update = PrimeUserdictUpdate.new(@output_dictname, @is_interactive)
+      if prime_update.check_necessity(@input_dictname) then
+	prime_update.update(@input_dictname)
+	prime_update.delete_files(@input_dictname)
       end
 
-      protect_userdict(@output_dictname, @input_dictname) {|tmp_dictname|
+      if @indexing then # with --conversion and --indexing
         prime_makeindex =
-          PrimeUserdictMakeIndex.new(tmp_dictname, @is_interactive)
+             PrimeUserdictMakeIndex.new(@output_dictname, @is_interactive)
         prime_makeindex.make_indexes()
-      }
+      end
+    elsif @indexing then # with --indexing
+      if @output_dictname.nil? then
+	print_usage()
+	exit()
+      end
+      prime_makeindex =
+	PrimeUserdictMakeIndex.new(@output_dictname, @is_interactive)
+      prime_makeindex.make_indexes()
     end
 
     system('%bindir%/%PRIME_COMMAND%-refresh')
+
     $stderr.puts "Done." if @is_interactive
   end
 
Index: prime/src/prime.src
diff -u prime/src/prime.src:1.6 prime/src/prime.src:1.7
--- prime/src/prime.src:1.6	Thu Dec  9 23:51:59 2004
+++ prime/src/prime.src	Mon Mar  7 16:51:34 2005
@@ -1,7 +1,7 @@
 #!/usr/bin/env ruby
 #
 # PRIME: PRedictive Input Method Editor
-# $Id: prime.src,v 1.6 2004/12/09 14:51:59 komatsu Exp $
+# $Id: prime.src,v 1.7 2005/03/07 07:51:34 komatsu Exp $
 #
 # Copyright (C) 2001 Satoru Takabayashi <sator****@namaz*****>
 # Copyright (C) 2002, 2003 Hiroyuki Komatsu <komat****@taiya*****>
@@ -12,17 +12,13 @@
 # the GNU General Public License version 2.
 #
 
-trap ("HUP") {
-#  $stderr.puts "SIGHUP #{$$}"
-}
-
 PRIME_BINDIR = '%bindir%'
 PRIME_LIBDIR = '%rubydir%'
 $LOAD_PATH.unshift(PRIME_LIBDIR) unless $LOAD_PATH.member?(PRIME_LIBDIR)
 
 require 'getoptlong'
 require 'prime/prime'
-require 'prime/session'
+require 'prime/protocol'
 require 'prime/server'
 require "jcode"
 
@@ -72,12 +68,14 @@
     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],
+                       ['--tcp-server',	'-s',	GetoptLong::OPTIONAL_ARGUMENT],
                        ['--typing-method',      GetoptLong::REQUIRED_ARGUMENT],
+                       ['--char-encoding',      GetoptLong::REQUIRED_ARGUMENT],
                        ['--no-save',            GetoptLong::NO_ARGUMENT],
                        ['--debug', '-d',	GetoptLong::NO_ARGUMENT],
                        ['--skk',	        GetoptLong::OPTIONAL_ARGUMENT],
-                       ['--pobox',	        GetoptLong::OPTIONAL_ARGUMENT])
+                       ['--pobox',	        GetoptLong::OPTIONAL_ARGUMENT],
+                       ['--network-dict',       GetoptLong::REQUIRED_ARGUMENT])
 
     parser.each_option {|option, arg|
       options[option.sub(/^--/, '')] = arg
@@ -110,6 +108,22 @@
                      PRIME_ENV['typing_method'] )
     PRIME_ENV['typing_method'] = typing_method
 
+    char_encoding = (options['char-encoding']   || \
+                     ENV['PRIME_CHAR_ENCODING'] || \
+                     PRIME_ENV['char_encoding'] )
+    PRIME_ENV['char_encoding'] = char_encoding
+
+    ## Configurating a network-dict (Experimental)
+    network_dict = options['network-dict']
+    if network_dict then
+      unless PRIME_ENV['engines'].member?(:PrimeEngineNetwork) then
+        PRIME_ENV['engines'].push(:PrimeEngineNetwork)
+      end
+      unless PRIME_ENV['engine_network_servers'].member?(network_dict) then
+        PRIME_ENV['engine_network_servers'].push(network_dict)
+      end
+    end
+
     return options
   end
 
@@ -119,29 +133,33 @@
     if @options['skk'] then
       tcp_port = @options['skk'].empty?() ? "1178" : @options['skk']
       @options['tcp-server'] = tcp_port
-      session = SessionSKK.new(@prime, PRIME_VERSION)
+      protocol = PrimeProtocolSKK.new(@prime, PRIME_VERSION)
     elsif @options['pobox'] then
       tcp_port = @options['pobox'].empty?() ? "1179" : @options['pobox']
       @options['tcp-server'] = tcp_port
-      session = SessionPOBox.new(@prime, PRIME_VERSION)
+      protocol = PrimeProtocolPOBox.new(@prime, PRIME_VERSION)
     else
-#      session = SessionPrime.new(@prime, PRIME_VERSION)
-      session = SessionPrime2.new(@prime, PRIME_VERSION)
+#      protocol = ProtocolPrime.new(@prime, PRIME_VERSION)
+      protocol = PrimeProtocolPrime2.new(@prime, PRIME_VERSION)
     end
 
-    if @options['unix-socket']
+    if @options['unix-socket'] then
       socket_path = @options['unix-socket']
-      server = UnixSocketServer.new(session, socket_path)
-    elsif @options['tcp-server']
-      tcp_port = @options['tcp-server']
-      server = TaiyakiTCPServer.new(session, tcp_port)
+      server = UnixSocketServer.new(protocol, socket_path)
+    elsif @options['tcp-server'] then
+      tcp_port = (@options['tcp-server'].empty?() ?
+		  "1180" : @options['tcp-server'])
+      server = TaiyakiTCPServer.new(protocol, tcp_port)
     else
-      server = StdioServer.new(session)
+      server = StdioServer.new(protocol)
     end
 
     if PRIME_ENV['debug'] then
       server.set_debug()
     end
+    if PRIME_ENV['char_encoding'] then
+      server.set_encoding(PRIME_ENV['char_encoding'])
+    end
 
     server.start()
 
@@ -157,11 +175,9 @@
   $stderr.puts "Interrupted."
   exit()
 }
-
 prime = PrimeCommand.new()
 
 trap ("HUP") {
-#  $stderr.puts "SIGHUP2 #{$$}"
   prime.refresh()
 }
 


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