update.
authoreto <eto>
Mon, 5 Jul 2004 12:37:38 +0000 (12:37 +0000)
committereto <eto>
Mon, 5 Jul 2004 12:37:38 +0000 (12:37 +0000)
.cvsignore [new file with mode: 0755]
chise/db.rb
chise/kageserver.rb
chise/network.rb
ext/sample.rb
ext/test.rb
test/common.rb
test/test-chisedb.rb [new file with mode: 0755]
test/test-libchise.rb
test/test-libchise_c.rb [new file with mode: 0755]
test/test-libchise_r.rb [new file with mode: 0755]

diff --git a/.cvsignore b/.cvsignore
new file mode 100755 (executable)
index 0000000..c50c96e
--- /dev/null
@@ -0,0 +1 @@
+memo.txt
index 2371a61..f5081f2 100755 (executable)
@@ -28,7 +28,7 @@ module CHISE
     def self.open_create(filename)
       ADB.open(filename, nil, BDB::CREATE | BDB::EXCL) #上書きはしない
     end
-
+a
     def mykey(key)
       if key.is_a?(String)
        if key.char_length == 1
index f0ea01d..5b0224f 100755 (executable)
@@ -4,7 +4,7 @@ require "singleton"
 require "net/http"
 require "uri"
 require "chise"
-require "chise/network" #漢字間接続のネットワークを計算する
+require "chise/network"
 require "chise/kanjilist"
 
 class KageServer
@@ -19,9 +19,9 @@ class KageServer
   def initialize(url=URL)
     @url = url
     @glyphs = []
-    @use_cache = true #デフォルト: cacheに存在する場合はcacheから引き出す。
-    @offline = false #テスト用
-    @offline = true #テスト用
+    @use_cache = true # retriev from cache.  default.
+    # @offline = false
+    @offline = true # for test
     c = Config.instance
     @cache_dir = c.base_dir+"/cache_kage"
     Dir.mkdir(@cache_dir) unless FileTest.directory?(@cache_dir)
index ed0d679..59612d9 100755 (executable)
@@ -34,7 +34,8 @@ module CHISE
       
       char = ch.char
       ids = char.decompose
-      if ids.char_length == 1 #分割できない文字は、リンクを探す。
+#     if ids.char_length == 1 #分割できない文字は、リンクを探す。
+      if ids.is_a_utf8? #分割できない文字は、リンクを探す。
        link = char.ids_represent if char.ids_represent
        link = char.ids_link if char.ids_link
        return if link.nil?
index dd5bf40..56c4ada 100755 (executable)
@@ -1,7 +1,13 @@
 #!/usr/bin/env ruby
 # Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
 
-require "libchise"
+require "libchise_c.so"
+module CHISE
+  DataSource = DataSource_C
+  Feature = Feature_C
+  CCS = CCS_C
+end
+
 $LOAD_PATH.unshift("..")
 require "chise/qp"
 
index 5abd33b..e69de29 100755 (executable)
@@ -1,59 +0,0 @@
-#!/usr/bin/env ruby
-# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
-
-$VERBOSE = true
-$LOAD_PATH.unshift("..")
-require "test/unit"
-require "libchise_c"
-require "chise/qp"
-
-class TestLibChise < Test::Unit::TestCase
-  def test_libchise
-    db_dir = CHISE::DB_DIR
-    assert_equal("/cygdrive/c/chise/chise-db", db_dir)
-
-    @ds = CHISE::DataSource.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755)
-    assert_instance_of(CHISE::DataSource, @ds)
-
-    char_id = @ds.decode_char("=daikanwa", 364)
-    assert_equal(0x4ECF, char_id)
-
-    ccs = @ds.get_ccs("=daikanwa")
-    assert_instance_of(CHISE::CCS, ccs)
-    char_id = ccs.decode(364)
-    assert_equal(0x4ECF, char_id)
-
-    feature = @ds.get_feature("ideographic-structure")
-    assert_instance_of(CHISE::Feature, feature)
-    value = feature.get_value(char_id)
-    assert_instance_of(CHISE::Value, value)
-    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value.to_s)
-
-    @ds.each_feature_name {|name|
-      assert_instance_of(String, name)
-    }
-
-    feature = @ds.get_feature("numeric-value")
-    feature.each_char {|cid, valdatum|
-      assert_kind_of(Numeric, cid)
-      assert_instance_of(CHISE::Value, valdatum)
-
-      ucs = @ds.get_feature("=ucs").get_value(cid)
-      if ucs
-       assert_instance_of(CHISE::Value, ucs)
-      else
-       ucs = @ds.get_feature("=>ucs").get_value(cid)
-       if ucs
-         assert_instance_of(CHISE::Value, ucs)
-       end
-      end
-
-      name = @ds.get_feature("name").get_value(cid)
-      if name
-       assert_instance_of(CHISE::Value, name)
-      end
-    }
-
-    @ds.close
-  end
-end
index 0f75a3c..6555878 100755 (executable)
@@ -9,7 +9,9 @@ $KCODE = "u"
 # $stdout.sync = true if $debug
 
 $LOAD_PATH.unshift("..")
+$LOAD_PATH.unshift("../ext")
 require "test/unit"
+require "chise/libchise"
 require "chise/char"
 require "chise/qp"
 
diff --git a/test/test-chisedb.rb b/test/test-chisedb.rb
new file mode 100755 (executable)
index 0000000..f52547a
--- /dev/null
@@ -0,0 +1,122 @@
+#!/usr/bin/env ruby
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+
+require "common"
+
+class TestChiseDB < Test::Unit::TestCase
+  def test_libchise_r
+    db_dir = CHISE::DataSource::DB_DIR
+    assert_match(/chise-db\Z/, db_dir)
+
+    @ds = CHISE::DataSource.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755)
+    assert_instance_of(CHISE::DataSource, @ds)
+
+    @ct = @ds.get_ccs("=daikanwa")
+    assert_instance_of(CHISE::CCS, @ct)
+    char_id = @ct.decode(364) # get a character by Daikanwa number 364.
+    assert_equal(20175, char_id)
+    #str = format_char_id(20175)
+    #assert_equal("?\344\273\217", str)
+
+    char_id = @ds.decode_char("=daikanwa", 364)
+    assert_equal(20175, char_id)
+
+    @ft = @ds.get_feature("ideographic-structure")
+    assert_instance_of(CHISE::Feature, @ft)
+    value = @ft.get_value(char_id)
+    assert_instance_of(String, value)
+    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
+
+    value = @ds.load_feature(char_id, "ideographic-structure")
+    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
+    return
+
+    @ds.each_feature_name {|f|
+      assert_instance_of(String, f)
+      ft = @ds.get_feature(f)
+      v = ft.get_value(23383)
+      #ft.close
+    }
+
+    @ft.each_char {|k, v|
+      assert_kind_of(Integer, k)
+      assert_instance_of(String, v)
+    }
+
+    ft = @ds.get_feature("numeric-value")
+    ft.each {|k, v|
+      assert_kind_of(Integer, k)
+      assert_instance_of(String, v)
+    }
+  end
+
+  def nu_test_each_ccs
+    @ds = CHISE::DataSource.new
+    @ds.each_ccs {|ccs|
+      assert_instance_of(String, ccs)
+      ct = @ds.get_ccs(ccs)
+      assert_instance_of(CHISE::CCSTable, ct)
+    }
+
+    ct = @ds.get_ccs("=ucs")
+    ct.each {|k, v|
+      assert_kind_of(Integer, k)
+      assert_kind_of(Integer, v)
+    }
+    #ct.close
+  end
+
+  def test_error
+    db_dir = CHISE::DataSource::DB_DIR
+    @ds = CHISE::DataSource.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755)
+    @ft = @ds.get_feature("nosuchfeature")
+    v = @ft.get_value(20175)
+    assert_equal(nil, v)
+  end
+
+  def test_chisedb
+    @cd = CHISE::ChiseDB.instance
+
+    char_id = @cd.decode_char("=daikanwa", 364)
+    assert_equal(20175, char_id)
+
+    value = @cd.load_feature(char_id, "ideographic-structure")
+    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
+
+    value = @cd.load_feature(char_id, "=ucs")
+    assert_equal("20175", value)
+
+    @cd.each_feature_name {|f|
+      assert_instance_of(String, f)
+    }
+
+    ft = @cd.get_feature("numeric-value")
+    ft.each_char {|k, v|
+      assert_kind_of(Integer, k)
+      assert_instance_of(String, v)
+    }
+  end
+
+  def test_ascii
+    @cd = CHISE::ChiseDB.instance
+    ct = @cd.get_ccs("ascii")
+    char_id = ct.decode(65)
+    assert_equal(65, char_id)
+    assert_equal("A", CHISE::Character.get(char_id).to_s)
+#   assert_equal("A", char.to_s)
+  end
+
+  def test_put
+    @cd = CHISE::ChiseDB.instance
+    char_id = "字".char.char_id
+    ft = @cd.get_feature("test")
+    ft.setup_db(1)
+    ft.set_value(char_id, "test1")
+    assert_equal("test1", ft.get_value(char_id))
+    ft.sync
+
+    ds = @cd.instance_eval { @ds }
+    path = CHISE::DataSource::DB_DIR.path+"character/feature/test"
+    assert_equal(true, path.exist?)
+  end
+end
index 9d4d88c..ae9776d 100755 (executable)
 
 require "common"
 
-class TestRbChise < Test::Unit::TestCase
-  include CHISE::ChiseValue
+class TestLibChise < Test::Unit::TestCase
+  def test_libchise
+    db_dir = CHISE::DataSource::DB_DIR
+    assert_match(/chise-db\Z/, db_dir)
 
-  def test_rbchise
-    @ds = CHISE::DataSource.new
+    @ds = CHISE::DataSource.new(CHISE::DataSource::Berkeley_DB, db_dir, 0, 0755)
     assert_instance_of(CHISE::DataSource, @ds)
-    assert_match(/chise-db\Z/, @ds.location.to_s)
 
-    @ct = @ds.get_ccs("=daikanwa")
-    assert_instance_of(CHISE::CCSTable, @ct)
-    char_id = @ct.decode(364) # get a character by Daikanwa number 364.
-    assert_equal(20175, char_id)
-    str = format_char_id(20175)
-    assert_equal("?\344\273\217", str)
-
-    char_id = @ds.decode_char("=daikanwa", 364)
-    assert_equal(20175, char_id)
-
-    @ft = @ds.get_feature("ideographic-structure")
-    assert_instance_of(CHISE::FeatureTable, @ft)
-    value = @ft.get_value(char_id)
-    assert_instance_of(String, value)
-    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
-
-    value = @ds.load_feature("ideographic-structure", char_id)
-    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
-
-    @ds.each_feature {|f|
-      assert_instance_of(String, f)
-      ft = @ds.get_feature(f)
-      v = ft.get_value(23383)
-      ft.close
-    }
-
-    @ft.each {|k, v|
-      assert_kind_of(Integer, k)
-      assert_instance_of(String, v)
-    }
-
-    ft = @ds.get_feature("numeric-value")
-    ft.each {|k, v|
-      assert_kind_of(Integer, k)
-      assert_instance_of(String, v)
-    }
-  end
-
-  def test_each_ccs
-    @ds = CHISE::DataSource.new
-    @ds.each_ccs {|ccs|
-      assert_instance_of(String, ccs)
-      ct = @ds.get_ccs(ccs)
-      assert_instance_of(CHISE::CCSTable, ct)
-    }
-
-    ct = @ds.get_ccs("=ucs")
-    ct.each {|k, v|
-      assert_kind_of(Integer, k)
-      assert_kind_of(Integer, v)
+    @ds.each_feature_name {|name|
+      assert_instance_of(String, name)
     }
-    ct.close
-  end
-
-  def test_error
-    @ds = CHISE::DataSource.new
-    @ft = @ds.get_feature("nosuchfeature")
-    v = @ft.get_value(20175)
-    assert_equal(nil, v)
-  end
 
-  def test_chisedb
-    @cd = CHISE::ChiseDB.instance
-
-    char_id = @cd.decode_char("=daikanwa", 364)
-    assert_equal(20175, char_id)
-
-    value = @cd.load_feature("ideographic-structure", char_id)
+    # get a feature value
+    char_id = 0x4ECF
+    feature = @ds.get_feature("ideographic-structure")
+    assert_instance_of(CHISE::Feature, feature)
+    assert_equal(true, feature.setup_db(0))
+    assert_equal(true, feature.sync)
+    value = feature.get_value(char_id)
     assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
 
-    value = @cd.load_feature("=ucs", char_id)
-    assert_equal(20175, value)
-
-    @cd.each_feature {|f|
-      assert_instance_of(String, f)
-    }
+    # shortcut
+    value = @ds.load_feature(char_id, "ideographic-structure")
+    assert_equal("(?\342\277\260 ?\344\272\273 ?\345\216\266)", value)
 
-    ft = @cd.get_feature("numeric-value")
-    ft.each {|k, v|
-      assert_kind_of(Integer, k)
-      assert_instance_of(String, v)
+    # set a value
+    feature = @ds.get_feature("test-libchise")
+    assert_instance_of(CHISE::Feature, feature)
+    v = "testvalue"+$$.to_s
+    assert_equal(true, feature.set_value(char_id, v))
+    assert_equal(v, feature.get_value(char_id))
+
+    # each char
+    feature = @ds.get_feature("numeric-value")
+    feature.each_char {|cid, valdatum|
+      assert_kind_of(Numeric, cid)
+      assert_instance_of(String, valdatum)
+
+      ucs = @ds.get_feature("=ucs").get_value(cid)
+      if ucs
+       assert_instance_of(String, ucs)
+      else
+       ucs = @ds.get_feature("=>ucs").get_value(cid)
+       if ucs
+         assert_instance_of(String, ucs)
+       end
+      end
+
+      name = @ds.get_feature("name").get_value(cid)
+      if name
+       assert_instance_of(String, name)
+      end
     }
-  end
-
-  def test_ascii
-    @cd = CHISE::ChiseDB.instance
-    ct = @cd.get_ccs("ascii")
-    char_id = ct.decode(65)
-    assert_equal(65, char_id)
-    assert_equal("A", CHISE::Character.get(char_id).to_s)
-#   assert_equal("A", char.to_s)
-  end
 
-  def test_put
-    @cd = CHISE::ChiseDB.instance
-    char_id = "字".char.char_id
-    ft = @cd.get_feature("test")
-    #assert_equal(nil, ft.get_value(char_id))
-    ft.set_value(char_id, "test1")
-    assert_equal("test1", ft.get_value(char_id))
-    ft.sync
+    # get a character by Daikanwa number 364.
+    ccs = @ds.get_ccs("=daikanwa")
+    assert_instance_of(CHISE::CCS, ccs)
+    assert_equal(true, ccs.setup_db(0))
+    assert_equal(true, ccs.sync)
+    char_id = ccs.decode(364)
+    assert_equal(0x4ECF, char_id)
 
-    ds = @cd.instance_eval { @ds }
-    path = ds.location+"character/feature/test"
-    assert_equal(true, path.exist?)
-  end
+    # shortcut
+    char_id = @ds.decode_char("=daikanwa", 364)
+    assert_equal(0x4ECF, char_id)
 
-  def test_parse_c_string
-    u8 = "字"
-#    assert_equal(23383, u8.u8to_i)
-    assert_equal(23383,        parse_c_string("?"+u8))
-    assert_equal(0,    parse_c_string("?\\^@"))
-    assert_equal(9,    parse_c_string("?\t"))
-    assert_equal(10,   parse_c_string("?\n"))
-    assert_equal(13,   parse_c_string("?\r"))
-    assert_equal(94,   parse_c_string("?^\\"))
-    assert_equal(31,   parse_c_string("?\\^_"))
-    assert_equal(32,   parse_c_string("?\\ "))
-    assert_equal(34,   parse_c_string("?\\\""))
-    assert_equal(126,  parse_c_string("?~"))
-    assert_equal(127,  parse_c_string("?\\^?\000"))
-    assert_equal(131,  parse_c_string("?\\^\303\237"))
-    assert_equal(0x7FF,        parse_c_string("?\337\277"))
-    assert_equal(0xFFFF,       parse_c_string("?\357\277\277"))
-    assert_equal(0x1FFFFF,     parse_c_string("?\367\277\277\277"))
-    assert_equal(0x3FFFFFF,    parse_c_string("?\373\277\277\277\277"))
-    assert_equal(0xFFFFFFF,    parse_c_string("?\374\217\277\277\277\277"))
-    assert_raise(RuntimeError) { parse_c_string("nosuch") }
-  end
+    # set a code_point
+    ccs = @ds.get_ccs("test-ccs")
+    assert_instance_of(CHISE::CCS, ccs)
+    assert_equal(true, ccs.set($$, 0x4ECF))
+    assert_equal(0x4ECF, ccs.decode($$))
 
-  def test_format_char_id
-    u8 = "字"
-#    assert_equal(u8, CHISE.i_tou8(23383))
-    assert_equal("?\345\255\227",      format_char_id(23383))
-    assert_equal("?"+u8,               format_char_id(23383))
-    assert_equal("?\\^@",      format_char_id(0))
-    assert_equal("?\t",                format_char_id(?\t))
-    assert_equal("?\n",                format_char_id(?\n))
-    assert_equal("?\r",                format_char_id(?\r))
-    assert_equal("?^\\",       format_char_id(0x1C))
-    assert_equal("?\\^_",      format_char_id(0x1F))
-    assert_equal("?\\ ",       format_char_id(?\s))
-    assert_equal("?\\\"",      format_char_id(?\"))
-    assert_equal("?~",         format_char_id(0x7E))
-    assert_equal("?\\^?\000",  format_char_id(0x7F))
-    assert_equal("?\\^\303\237",       format_char_id(0x9F))
-    assert_equal("?\337\277",  format_char_id(0x7FF))
-    assert_equal("?\357\277\277",      format_char_id(0xFFFF))
-    assert_equal("?\367\277\277\277",  format_char_id(0x1FFFFF))
-    assert_equal("?\373\277\277\277\277",      format_char_id(0x3FFFFFF))
-    assert_equal("?\374\217\277\277\277\277",  format_char_id(0xFFFFFFF))
+    @ds.close
   end
 end
diff --git a/test/test-libchise_c.rb b/test/test-libchise_c.rb
new file mode 100755 (executable)
index 0000000..e69de29
diff --git a/test/test-libchise_r.rb b/test/test-libchise_r.rb
new file mode 100755 (executable)
index 0000000..cfe10ba
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env ruby
+# Copyright (C) 2002-2004 Kouichirou Eto, All rights reserved.
+
+require "common"
+
+class TestLibChise_R < Test::Unit::TestCase
+  include CHISE::ChiseValue
+
+  def test_parse_c_string
+    u8 = "字"
+    assert_equal(23383,        parse_c_string("?"+u8))
+    assert_equal(0,    parse_c_string("?\\^@"))
+    assert_equal(9,    parse_c_string("?\t"))
+    assert_equal(10,   parse_c_string("?\n"))
+    assert_equal(13,   parse_c_string("?\r"))
+    assert_equal(94,   parse_c_string("?^\\"))
+    assert_equal(31,   parse_c_string("?\\^_"))
+    assert_equal(32,   parse_c_string("?\\ "))
+    assert_equal(34,   parse_c_string("?\\\""))
+    assert_equal(126,  parse_c_string("?~"))
+    assert_equal(127,  parse_c_string("?\\^?\000"))
+    assert_equal(131,  parse_c_string("?\\^\303\237"))
+    assert_equal(0x7FF,        parse_c_string("?\337\277"))
+    assert_equal(0xFFFF,       parse_c_string("?\357\277\277"))
+    assert_equal(0x1FFFFF,     parse_c_string("?\367\277\277\277"))
+    assert_equal(0x3FFFFFF,    parse_c_string("?\373\277\277\277\277"))
+    assert_equal(0xFFFFFFF,    parse_c_string("?\374\217\277\277\277\277"))
+    assert_raise(RuntimeError) { parse_c_string("nosuch") }
+  end
+
+  def test_format_char_id
+    u8 = "字"
+    assert_equal("?\345\255\227",      format_char_id(23383))
+    assert_equal("?"+u8,               format_char_id(23383))
+    assert_equal("?\\^@",      format_char_id(0))
+    assert_equal("?\t",                format_char_id(?\t))
+    assert_equal("?\n",                format_char_id(?\n))
+    assert_equal("?\r",                format_char_id(?\r))
+    assert_equal("?^\\",       format_char_id(0x1C))
+    assert_equal("?\\^_",      format_char_id(0x1F))
+    assert_equal("?\\ ",       format_char_id(?\s))
+    assert_equal("?\\\"",      format_char_id(?\"))
+    assert_equal("?~",         format_char_id(0x7E))
+    assert_equal("?\\^?\000",  format_char_id(0x7F))
+    assert_equal("?\\^\303\237",       format_char_id(0x9F))
+    assert_equal("?\337\277",  format_char_id(0x7FF))
+    assert_equal("?\357\277\277",      format_char_id(0xFFFF))
+    assert_equal("?\367\277\277\277",  format_char_id(0x1FFFFF))
+    assert_equal("?\373\277\277\277\277",      format_char_id(0x3FFFFFF))
+    assert_equal("?\374\217\277\277\277\277",  format_char_id(0xFFFFFFF))
+  end
+end