From 28ce07061ebc5c4769908853934784ed526be387 Mon Sep 17 00:00:00 2001 From: moro Date: Wed, 12 Mar 2003 16:53:59 +0000 Subject: [PATCH] add set operations. --- CHISE.pm | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/CHISE.pm b/CHISE.pm index cff017e..8eebbda 100644 --- a/CHISE.pm +++ b/CHISE.pm @@ -1,12 +1,16 @@ # # CHISE.pm by Shigeki Moro -# $Id: CHISE.pm,v 1.2 2003-02-23 09:17:19 moro Exp $ +# $Id: CHISE.pm,v 1.3 2003-03-12 16:53:59 moro Exp $ # package CHISE; use strict; use BerkeleyDB; +our ($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET); +($EXCLUSIVE, $HAVE_INTERSECTION, $PROPER_SUBSET, $PROPER_SUPERSET, $EQSET) + = (1, 2, 3, 4, 5); + my $DB_HOME = '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db'; my %alias = (); @@ -111,7 +115,33 @@ for my $attrname (keys %alias) { #} sub compare { - # ø½Š²¡å­—オブジェクトと比ø½Š‘Š + # ø½Š²¡å­—オブジェクトどうしを比ø½Š‘Šã—て、 + # ø½ŠŸ›åˆã®é‡ãªã‚Šð¯ ‘合をø½Š²¿ã™ã€‚ + my($a, $b) = @_; + my($aonly, $bonly, $common) = (0, 0, 0); + for my $i (&cup(keys %$a, keys %$b)) { + if ($a->{$i} eq $b->{$i}) { + $common++; + } else { + $aonly++ if (exists $a->{$i}); + $bonly++ if (exists $b->{$i}); + } + } + if ($common == 0) { + return $EXCLUSIVE; # ø»‚´¦ä»– + } elsif ($aonly == 0 and $bonly == 0) { + return $EQSET; # ø½Š’…全一致 + } elsif ($aonly == 0) { + return $PROPER_SUBSET; # $aは$bのø½Š¢žø½Š±¿ø»‚¸™ø½ŠŸ›åˆ + } elsif ($bonly == 0) { + return $PROPER_SUPERSET; # $bは$aのø½Š¢žø½Š±¿ø»‚¸™ø½ŠŸ›åˆ + } else { + return $HAVE_INTERSECTION; + } +} + +sub rate_of_coincidence { + # ø½Š²¡å­—オブジェクトどうしの属性の一致ø½Š¸‰ã‚’出す。 my($a, $b) = @_; my($all_attr, $common_attr) = (0, 0); for my $i (&cup(keys %$a, keys %$b)) { -- 1.7.10.4