From: eto Date: Thu, 10 Jun 2004 11:20:26 +0000 (+0000) Subject: i X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b25cdbb3d6d0d4621f1ecf82a12b4a3a6f8edba;p=chise%2Fruby.git i --- diff --git a/chise/char.rb b/chise/char.rb index f8687e6..2d685be 100755 --- a/chise/char.rb +++ b/chise/char.rb @@ -4,11 +4,5 @@ require "chise/db" require "chise/config" require "chise/iconv" require "chise/uconv" - require "chise/string" require "chise/character" - -$debug = false #これはテスト用 -$debug = true #これはテスト用 -$stdout.binmode if $debug -$stdout.sync = true if $debug diff --git a/chise/character.rb b/chise/character.rb index b2d0972..753089a 100755 --- a/chise/character.rb +++ b/chise/character.rb @@ -20,29 +20,29 @@ module CHISE def get(char_id) check_max - n = @parser.parse(char_id) - @chars[n] = Character.new(n) if @chars[n].nil? - @chars[n] + mcs = @parser.parse(char_id) + @chars[mcs] = Character.new(mcs) if @chars[mcs].nil? + @chars[mcs] end def check_max clear if MAX_CACHE_CHARACTER < @chars.length # clear all caches. end - - def nu_length - @chars.length - end end class Character def initialize(char_id=nil) - @parser = CharacterParser.new - @char_id = @parser.parse(char_id) - @attributes = Hash.new + @char_id = char_id + @attributes = {} @check_all_database = false end attr_reader :char_id + + + + + def to_i() @char_id end def mcs_utf8() Character.u4itou8(@char_id) end def mcs_hex() sprintf("%x", @char_id) end @@ -61,7 +61,7 @@ module CHISE a end - def get_char_attribute(b) # XEmacs UTF-2000ŒÝŠ·APIŒQ + def get_char_attribute(b) # XEmacs CHISE compatible API a = normalize_attribute_name(b) #p [a, b] atr = @attributes[a] @@ -71,7 +71,8 @@ module CHISE @attributes[a] = atr return atr end - return get_char_attribute("="+a) unless a =~ /^=/ #“ª‚É=‚ª‚‚¢‚Ä‚È‚¢ê‡‚Í‚»‚ꂪÈ—ª‚³‚ê‚Ä‚¢‚邱‚Æ‚ð‰¼’è‚µ‚āAÄ‹A‚·‚é + return get_char_attribute("="+a) unless a =~ /^=/ + #“ª‚É=‚ª‚‚¢‚Ä‚È‚¢ê‡‚Í‚»‚ꂪÈ—ª‚³‚ê‚Ä‚¢‚邱‚Æ‚ð‰¼’è‚µ‚āAÄ‹A‚·‚é nil end diff --git a/chise/codeviewer.rb b/chise/codeviewer.rb index 0c70df4..3e8fc57 100755 --- a/chise/codeviewer.rb +++ b/chise/codeviewer.rb @@ -1,11 +1,12 @@ # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -require "stroke" +require "chise/stroke" module StrokeFont class CodeViewer WIDTH, HEIGHT = 256, 256 SCALE = 2 + def initialize(cx=0, cy=0) @cx, @cy = cx, cy @s = SCALE @@ -19,6 +20,7 @@ module StrokeFont calc_code end attr_reader :code + def draw colorHSV(0, 0, 100, 10) #まずは下敷きになる枠を書きます。 rect(@x1, @y1, @x2, @y2) @@ -34,6 +36,7 @@ module StrokeFont line(@px-@pw/2, @py, @px+@pw/2, @py) line(@px, @py-@ph/2, @px, @py+@ph/2) end + def onMouse(x, y) if @onkeydown x, y = @px, @py @@ -50,6 +53,7 @@ module StrokeFont return false end end + def calc_code() x = ((@px - @x1)/@s).to_i y = HEIGHT-1 - ((@py - @y1)/@s).to_i @@ -63,6 +67,7 @@ module StrokeFont return false end end + def show_list(list) colorHSV(0, 100, 100, 100) list.each {|code| @@ -70,6 +75,7 @@ module StrokeFont rect(x, y, x+2, y-2) } end + def code_to_xy(code) cx = code % WIDTH cy = HEIGHT - (code / WIDTH) #intになる? @@ -77,13 +83,17 @@ module StrokeFont y = cy * SCALE + @y1 return x, y end + def length(x, y) Math.sqrt(x*x + y*y) end + def onMouseDown(x, y) if length(@px-x, @py-y) < @pr @dragging = true end end + def onMouseUp(x, y) @dragging = false end + def onKeyDown(key) @onkeydown = true case key diff --git a/chise/config.rb b/chise/config.rb index 52663ee..8944476 100755 --- a/chise/config.rb +++ b/chise/config.rb @@ -17,11 +17,11 @@ module CHISE @csf_dir = @base_dir+"/csf" if CHISE.windows?() - @db_dir = @base_dir+"/char-db" # /sysmtem-char-id/ucs + @db_dir = @base_dir+"/chise-db" # /sysmtem-char-id/=ucs @ids_dir = @base_dir+"/ids" # /IDS-JIS-X0208-1990.txt else - @db_dir = "/usr/local/lib/xemacs-21.4.12/i686-pc-linux/char-db" - @ids_dir = "/home/eto/chise/ids" + @db_dir = "/usr/local/lib/xemacs-21.4.14/i686-pc-linux/chise-db" + @ids_dir = "/home/eto/work/chise/ids" end instance_variables.each {|name| diff --git a/chise/csf.rb b/chise/csf.rb index fd8bf1f..593b495 100755 --- a/chise/csf.rb +++ b/chise/csf.rb @@ -1,8 +1,6 @@ # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. require "sgl" -#require "kconv" -#require "uconv" require "chise/iconv" require "chise/config" @@ -19,14 +17,17 @@ module StrokeFont @strokes = Strokes.new end attr_reader :strokes + def move_to_x(x) @x = x; @nx = x; end def draw_to_x(x) @nx = x; drawline; @x = @nx; @y = @ny; end def next_x_to(x) @nx = x; end def move_to_y(y) @y = y; @ny = y; end def draw_to_y(y) @ny = y; drawline; @x = @nx; @y = @ny; end + def drawline() @strokes.add_line(t(@x), t(@y), t(@nx), t(@ny)) end + def t(a) a*DEST_WIDTH/ORG_WIDTH; end end diff --git a/chise/db.rb b/chise/db.rb index 9785ae2..e5707d4 100755 --- a/chise/db.rb +++ b/chise/db.rb @@ -4,7 +4,6 @@ require "singleton" require "bdb" require "chise/config" require "chise/rbchise" -require "chise/management" require "chise/util" module CHISE diff --git a/chise/kageserver.rb b/chise/kageserver.rb index e01f530..f0ea01d 100755 --- a/chise/kageserver.rb +++ b/chise/kageserver.rb @@ -5,8 +5,7 @@ require "net/http" require "uri" require "chise" require "chise/network" #漢字間接続のネットワークを計算する -#require "chise/kanjilist" -#include CHISE +require "chise/kanjilist" class KageServer include Singleton diff --git a/chise/management.rb b/chise/management.rb deleted file mode 100755 index 38fcfde..0000000 --- a/chise/management.rb +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. - -module CHISE - class DBS_Management # DataBase file management - OBSOLETE_ATTRIBUTES = " -cns-radical -cns-radical? -kangxi-radical -daikanwa-radical -unicode-radical - -cns-strokes -kangxi-strokes -daikanwa-strokes -shinjigen-1-radical -gb-original-radical -japanese-strokes -jis-strokes-a -jis-strokes-b -jisx0208-strokes -jis-x0213-strokes -jisx0213-strokes -unicode-strokes - -totalstrokes -cns-total-strokes -jis-total-strokes-b - -non-morohashi - -=>ucs* -#=>mojikyo -#=mojikyo -->identical - -ancient-ideograph-of -ancient-char-of-shinjigen-1 -original-ideograph-of -original-char-of-shinjigen-1 -simplified-ideograph-of -vulgar-ideograph-of -vulgar-char-of-shinjigen-1 -ideograph= -ideographic-variants -variant-of-shinjigen-1 - -iso-10646-comment -".split - - def initialize - dir = Config.instance.db_dir - @odir = dir+"/system-char-id/obsolete" #’¼‘Å‚¿‚µ‚Ä‚¢‚éB - end - - def move_obsolete_files # move obsolete BDB files - db = CharDB.instance - db.close_all - Dir.mkdir(@odir) unless FileTest.directory? @odir - OBSOLETE_ATTRIBUTES.each {|attr| - next if attr =~ /^#/ - filename = db.get_filename(attr) - move_to_obsolete(filename) - move_to_obsolete(filename+".txt") - } - end - - def move_to_obsolete(file) - cmd = "mv \"#{file}\" #{@odir}" - #p cmd - system cmd - end - end -end diff --git a/chise/parser.rb b/chise/parser.rb index 9b7083c..812b77c 100755 --- a/chise/parser.rb +++ b/chise/parser.rb @@ -63,7 +63,7 @@ module CHISE PRIVATE_USE_AREA = 0xe000 def parse_er(s) # parse a Entity Reference and return a number (MCS) - raise "wrong ER." unless ALL_RE =~ s # I don't use is_er? for getting $1. + raise "wrong ER." unless ALL_RE =~ s # don't use is_er? for getting $1. s = $1 # extract the part of ER diff --git a/chise/rbchise.rb b/chise/rbchise.rb index 99d14d3..789dbe9 100755 --- a/chise/rbchise.rb +++ b/chise/rbchise.rb @@ -12,17 +12,27 @@ module CHISE def initialize(type = Berkeley_DB, location = nil) @type, @location = type, location @location = Config.instance.db_dir if @location.nil? - @dbs = {} + @fnames = {} + @cnames_names = {} at_exit { - @dbs.each {|k, db| - db.close - } + @fnames.each {|k, db| db.close } + @cnames.each {|k, db| db.close } } end - def open_decoding_table(ccs) - db = open(ccs, "system-char-id") - DecodingTable.new(ccs, db) + def get_feature(feature) + @fnames[feature] = open_feature(feature) if @fnames[feature].nil? + @fnames[feature] + end + + def decode_char(name, code_point) + ccs = get_ccs(name) + ccs.decode(code_point) + end + + def get_ccs(name) + db = open(name, "system-char-id") + CCSTable.new(name, db) end def open_feature_table(feature) @@ -41,7 +51,7 @@ module CHISE class AttributeTable # abstract class end - class DecodingTable < AttributeTable + class CCSTable < AttributeTable def initialize(ccs, db) @ccs, @db = ccs, db end diff --git a/chise/uconv.rb b/chise/uconv.rb deleted file mode 100755 index e69de29..0000000 diff --git a/test/common.rb b/test/common.rb index d5bdc43..b06096b 100755 --- a/test/common.rb +++ b/test/common.rb @@ -2,6 +2,11 @@ $VERBOSE = true +$debug = false # for test +$debug = true # for test +$stdout.binmode if $debug +$stdout.sync = true if $debug + $LOAD_PATH.unshift("..") require "test/unit" require "chise/char" diff --git a/test/test-rbchise.rb b/test/test-rbchise.rb index a3d18e3..457a3bb 100755 --- a/test/test-rbchise.rb +++ b/test/test-rbchise.rb @@ -3,8 +3,12 @@ require "common" -class TestRubyChise < Test::Unit::TestCase +class TestRbChise < Test::Unit::TestCase def test_rbchise + + end + + def test_rbchise0 @ds = CHISE::DataSource.new assert_instance_of(CHISE::DataSource, @ds) @dt = @ds.open_decoding_table("=daikanwa") diff --git a/tools/Makefile b/tools/Makefile index 4b2696a..40919c6 100755 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,16 +1,16 @@ # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. #test: ids_db -test: +test: -tarball: - ./mkdbtarball.rb /usr/local/lib/xemacs-21.4.10/i686-pc-linux/ +tarball: + ruby -I make-chisedb-tarball.rb /usr/local/lib/xemacs-21.4.14/i686-pc-linux -dump: +dump: ./dbdumpall.rb -ids_db: +ids_db: ./idsdbdumpall.rb -check: +check: ./idscheckintegrity.rb diff --git a/tools/cp-chisedb b/tools/cp-chisedb new file mode 100755 index 0000000..923fe2e --- /dev/null +++ b/tools/cp-chisedb @@ -0,0 +1,4 @@ +#!/bin/csh -f +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. + +scp aqua.eto.com:work/chise/ruby/tools/chise-db.tar.gz . diff --git a/tools/make-chisedb-tarball.rb b/tools/make-chisedb-tarball.rb index cf95cf1..1fc57cc 100755 --- a/tools/make-chisedb-tarball.rb +++ b/tools/make-chisedb-tarball.rb @@ -11,28 +11,31 @@ def usage() exit end -usage if ARGV.length < 1 -dir = ARGV[0] -unless FileTest.directory?(dir+"/chise-db") - print "no chise-db here. #{dir}\n" - usage -end -tmpdir = ARGV[1] -tmpdir = "/var/tmp" if tmpdir.nil? +def main(argv) + usage if argv.length < 1 + dir = argv.shift + unless FileTest.directory?(dir+"/chise-db") + print "no chise-db here. #{dir}\n" + usage + end + tmpdir = argv.shift + tmpdir = "/var/tmp" if tmpdir.nil? -orgdir = Dir.pwd -Dir.chdir(tmpdir) # “K“–‚Èdir‚Ɉړ®‚µ‚Ä‚©‚ç -system "cp -a #{dir}/chise-db ." # ‚Ü‚¸‚»‚Ìdirectory‚É–â“š–³—p‚Å‘S•”ƒRƒs[‚·‚éB + orgdir = Dir.pwd + Dir.chdir(tmpdir) # “K“–‚Èdir‚Ɉړ®‚µ‚Ä‚©‚ç + system "cp -a #{dir}/chise-db ." # ‚Ü‚¸‚»‚Ìdirectory‚É–â“š–³—p‚Å‘S•”ƒRƒs[‚·‚éB -Find.find("."){|f| - if f =~ /([*?<>])/ # Windows‚É‚¨‚¯‚é‹ÖŽ~•¶Žš‚ªŠÜ‚Ü‚ê‚Ä‚¢‚½‚çA’uŠ·‚·‚é - nf = CHISE.unix_to_win(f) - cmd = "mv '#{f}' '#{nf}'" - #print cmd, "\n" - system cmd - end -} + Find.find("."){|f| + if f =~ /([*?<>])/ # Windows‚É‚¨‚¯‚é‹ÖŽ~•¶Žš‚ªŠÜ‚Ü‚ê‚Ä‚¢‚½‚çA’uŠ·‚·‚é + nf = CHISE.unix_to_win(f) + cmd = "mv '#{f}' '#{nf}'" + #print cmd, "\n" + system cmd + end + } -system "tar czf chise-db.tar.gz chise-db" -system "mv chise-db.tar.gz #{orgdir}" -system "rm -rf #{tmpdir}/chise-db" + system "tar czf chise-db.tar.gz chise-db" + system "mv chise-db.tar.gz #{orgdir}" + system "rm -rf #{tmpdir}/chise-db" +end +main(ARGV) diff --git a/tools/move-obsolete-files.rb b/tools/move-obsolete-files.rb new file mode 100755 index 0000000..9692632 --- /dev/null +++ b/tools/move-obsolete-files.rb @@ -0,0 +1,82 @@ +#!/usr/bin/env ruby +# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. +# move obsolete BDB files. + +$LOAD_PATH.unshift("..") +require "chise/config" +require "chise/util" + +module CHISE + class DBS_Management # DataBase file management + # from specs/char-atr.ja.txt + OBSOLETE_ATTRIBUTES = " +cns-radical +cns-radical? +kangxi-radical +daikanwa-radical + +cns-strokes +kangxi-strokes +daikanwa-strokes +shinjigen-1-radical +gb-original-radical +japanese-strokes +jis-strokes-a +jisx0208-strokes +unicode-strokes + +cns-total-strokes + +non-morohashi + +=>ucs* +#=>mojikyo +#=mojikyo +->identical + +ancient-ideograph-of +ancient-char-of-shinjigen-1 +original-ideograph-of +original-char-of-shinjigen-1 +vulgar-ideograph-of +vulgar-char-of-shinjigen-1 +ideographic-variants +variant-of-shinjigen-1 + +iso-10646-comment +".split + + def initialize + end + + def move_obsolete_files + fdir = Config.instance.db_dir+"/system-char-id" + Dir.chdir(fdir){ + odir = "obsolete" + Dir.mkdir(odir) unless FileTest.directory? odir + + OBSOLETE_ATTRIBUTES.each {|attr| + next if attr =~ /^#/ + f = get_filename(attr) + move(f, odir) if FileTest.exist?(f) + f = f+".txt" + move(f, odir) if FileTest.exist?(f) + } + } + end + + def get_filename(t) + t = CHISE.unix_to_win(t) if CHISE.windows? + t + end + + def move(file, dir) + cmd = "mv './#{file}' #{dir}" + p cmd + system cmd + end + end +end + +man = CHISE::DBS_Management.new +man.move_obsolete_files diff --git a/tools/move_obsolete_files.rb b/tools/move_obsolete_files.rb deleted file mode 100755 index 4b52a8b..0000000 --- a/tools/move_obsolete_files.rb +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env ruby -# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved. -# obsoleteである属性のBDBファイルを移動する - -$LOAD_PATH.unshift("..") -require "chise/char" - -man = DBS_Management.new -man.move_obsolete_files