From: moro Date: Wed, 8 Oct 2003 13:30:29 +0000 (+0000) Subject: add $ X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a59b1c895f9a444eff1f7219d564bf47e7b944f;p=chise%2Fperl.git add $ --- diff --git a/CHISE.pm b/CHISE.pm index 57b5b91..3eec0ee 100644 --- a/CHISE.pm +++ b/CHISE.pm @@ -1,22 +1,13 @@ # # CHISE.pm by Shigeki Moro -# $Id: CHISE.pm,v 1.5 2003-08-10 15:52:15 moro Exp $ +# $Id: CHISE.pm,v 1.6 2003-10-08 13:30:28 moro Exp $ # package CHISE; use strict; use warnings; use utf8; -use BerkeleyDB; -use overload; - -sub import { - overload::constant ( 'qr' => \&ChiseLikeRegex ) -} - -sub unimport { - overload::remove_constant -} +use DB_File; our ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET); ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET) @@ -49,8 +40,6 @@ if (-e '/usr/local/lib/chise/char-db') { exit 1; } -#my $cache_size = 1024 * 1024 * 64; - my %alias = (); my %alias_reverse = (); for (glob "$DB_HOME/system-char-id/*") { @@ -166,6 +155,9 @@ sub compare { $aonly++ if (exists $a->{$i}); $bonly++ if (exists $b->{$i}); } + } else { + $aonly++ if (exists $a->{$i}); + $bonly++ if (exists $b->{$i}); } } if ($common == 0) { @@ -257,31 +249,6 @@ sub ph2char ($) { } } -#--- 正規表現のCHISE的拡張 ------------------------------------# - -sub ChiseLikeRegex ($) { - my ($RegexLiteral) = @_; - #print STDERR "BEFORE: $RegexLiteral\n"; # for debug - $RegexLiteral =~ s/\\same_strokes_(\d)/(??{CHISE->same_strokes(\$$1)})/g; - #$RegexLiteral =~ s/\\same_strokes_(\d)/[川山三]/g; - #print STDERR "AFTER: $RegexLiteral\n"; # for debug - return $RegexLiteral; -} - -sub same_strokes { - my $self = shift; - my $backtrace = shift; - my $db = "$DB_HOME/system-char-id/total-strokes"; - my $temp = &getvalue($db, "?$backtrace"); - my $result = ''; - for my $i (&getkeys($db, $temp)) { - $i =~ s/^\?//; - $result .= $i; - } - #print STDERR $result, "\n"; - return "[$result]"; -} - #--- モジュール内のみでø»‚¢³ã†äºˆø½ŠªŸã®é–¢æ•° ----------------------# sub chars { @@ -318,38 +285,30 @@ sub utf8 { sub getvalue ($$) { # キーから値をø½Šž­ã‚Šå‡ºã™ - my($dbname, $key) = @_; + my ($chise_dbname, $key) = @_; my $value = ''; - my $db = new BerkeleyDB::Hash - #tie my %h, "BerkeleyDB::Hash", - -Filename => $dbname; - #$value = $h{$key}; - #untie %h; - $db->db_get($key, $value); - undef $db; + tie (my %h, "DB_File", $chise_dbname, O_RDWR) + or die "Cannot open file $chise_dbname: $!\n"; + $value = $h{$key}; + untie %h; return $value; } sub getkeys ($$) { # 値からキーの配列をø½Šž­ã‚Šå‡ºã™ - my($dbname, $value) = @_; - my $db = new BerkeleyDB::Hash - #tie my %h, "BerkeleyDB::Hash", - -Filename => $dbname; + my ($chise_dbname, $value) = @_; + tie (my %h, "DB_File", $chise_dbname, O_RDWR, , $DB_BTREE) + or die "Cannot open file $chise_dbname: $!\n"; my @keys = (); - my ($k, $v) = ("", "") ; - my $cursor = $db->db_cursor() ; - #for my $k (keys %h) { - while ($cursor->c_get($k, $v, DB_NEXT) == 0) { - push @keys, $k if ($v eq $value); - #push @keys, $key if ($h{$key} eq $value); + for my $key (keys %h) { + next unless (exists $h{$key}); + push @keys, $key if ($h{$key} eq $value); } - undef $cursor ; - undef $db ; - #untie %h; + untie %h; return @keys; } + sub cap { # 2つの配列の積ø½ŠŸ›åˆã‚’求める my($a, $b) = @_; diff --git a/CHISE_REG.pm b/CHISE_REG.pm index ab97e8e..4a124a7 100644 --- a/CHISE_REG.pm +++ b/CHISE_REG.pm @@ -1,3 +1,8 @@ +# +# CHISE_REG.pm +# $Id: CHISE_REG.pm,v 1.2 2003-10-08 13:30:29 moro Exp $ +# + package CHISE_REG; use strict; @@ -35,8 +40,8 @@ if (-e '/usr/local/lib/chise/char-db') { } elsif (-e 'd:/work/chise/char-db'){ $DB_HOME = 'd:/work/chise/char-db'; } else { - print STDERR "CHISE.pm: No database found.\n"; - print STDERR "CHISE.pm: Please set \$DB_HOME to CHISE.pm.\n"; + print STDERR "CHISE_REG.pm: No database found.\n"; + print STDERR "CHISE_REG.pm: Please set \$DB_HOME to CHISE.pm.\n"; exit 1; } @@ -58,7 +63,7 @@ sub chise_backref { #print STDERR "backreference: $backreference\n"; # for debug #print STDERR "feature name: $feature_name\n"; # for debug my $result = `./chisereg.pl $backreference $DB_HOME $feature_name`; - print STDERR $result, "\n"; # for debug + #print STDERR $result, "\n"; # for debug return "[$result]"; } diff --git a/chisereg.pl b/chisereg.pl index 8d62f02..2c548ae 100755 --- a/chisereg.pl +++ b/chisereg.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -# -# +# chisereg.pl +# $Id: chisereg.pl,v 1.2 2003-10-08 13:30:29 moro Exp $ use strict; use warnings; diff --git a/sample1.pl b/sample1.pl index 70e11fc..e377303 100644 --- a/sample1.pl +++ b/sample1.pl @@ -1,3 +1,6 @@ +# sample1.pl +# $Id: sample1.pl,v 1.3 2003-10-08 13:30:29 moro Exp $ + use CHISE; my $s1 = CHISE->new(daikanwa => 6942); # 「字」 diff --git a/sample2.pl b/sample2.pl index db18f3a..1c18f5f 100644 --- a/sample2.pl +++ b/sample2.pl @@ -1,4 +1,5 @@ -# compareのsample +# sample2.pl (compareのsample) +# $Id: sample2.pl,v 1.3 2003-10-08 13:30:29 moro Exp $ use CHISE; my $s1 = CHISE->define_char(strokes => 12, radical => 9); diff --git a/sample3.pl b/sample3.pl index 1db4b76..e4a276e 100644 --- a/sample3.pl +++ b/sample3.pl @@ -1,4 +1,6 @@ -#!/usr/bin/perl -w +# sample3.pl +# $Id: sample3.pl,v 1.3 2003-10-08 13:30:29 moro Exp $ + use CHISE_REG; use utf8; #use re "debug";