#!/usr/bin/perl
use strict;
use warnings;
my %cnt;
my $pair_num;
while (<>) {
chomp;
next if /^\s*$/;
my @list = sort split(/,/, $_);
for (my $i = 0; $i < @list; $i++) {
for (my $j = $i + 1; $j < @list; $j++) {
next if $list[$i] eq $list[$j];
$cnt{word}{$list[$i]}++;
$cnt{word}{$list[$j]}++;
$cnt{pair}{join("\t", sort $list[$i], $list[$j])}++;
$pair_num++;
}
}
}
my %chi_square_value;
foreach my $p (keys %{$cnt{pair}}) {
my ($w1, $w2) = split(/\t/, $p);
my $o11 = $cnt{pair}{$p};
my $o12 = $cnt{word}{$w2} - $o11;
my $o21 = $cnt{word}{$w1} - $o11;
my $o22 = $pair_num - $cnt{word}{$w1} - $cnt{word}{$w2} + $o11;
my $n = $pair_num;
$chi_square_value{$p} = ($n * ($o11*$o22 - $o12*$o21)**2) /
(($o11+$o12)*($o11+$o21)*($o12+$o22)*($o21+$o22));
}
foreach (sort {$chi_square_value{$b} <=> $chi_square_value{$a}}
keys %chi_square_value) {
print "$chi_square_value{$_}\t$_\n";
}

| cow | !cow | |
| vache | 59 | 6 |
| !vache | 8 | 570934 |
hello,this,is,a,pen i,love,a,pen i,have,the,pen,with,love the,cat,with,love this,pen,is,hello this,pen,is,mine a,pen,is,love
% ./chiword.pl chiword-samp.txt 2.83051588365177 is love 2.61597458132189 pen the 2.61597458132189 pen with 2.23322255731561 love pen 0.901101336606656 cat with 0.901101336606656 cat the 0.823194884563151 the with 0.7703081232493 have pen 0.689179927290065 i pen 0.582010582010582 hello this 0.55 a this 0.489672364672365 mine this 0.396299545459209 is pen 0.346638655462185 a pen 0.346638655462185 pen this 0.313854708550087 hello pen 0.274216524216524 is this 0.203161938534279 a i 0.191637630662021 a love 0.165304780689396 is mine 0.131648936170213 have i 0.131648936170213 have the 0.131648936170213 have with 0.108227585906157 hello is 0.103803716608595 cat love 0.0895400895400895 a is 0.0862369337979094 have love 0.0818452380952381 a hello 0.031602384543561 mine pen 0.0315117134449977 i the 0.0315117134449977 i with 0.00101934909926607 love the 0.00101934909926607 i love 0.00101934909926607 love with
[2006-04-11-2]

【会場】
東京ミッドタウン ミッドタウン・ガーデン 芝生広場
【主催】
産経新聞社
【特別協賛】
東京ミッドタウン
【日時】
第一夜 9月19日(水) 19:00開演(18:00開場)
大蔵流狂言「三番三」(さんばそう) 茂山正邦/茂山 茂 ほか
大蔵流狂言「仁王」(におう) 茂山千五郎/茂山千三郎 ほか
和泉流狂言「蝸牛」(かぎゅう) 野村 萬斎/石田 幸雄
第二夜 9月20日(木) 19:00開演(18:00開場)
能囃子の世界『雪月花』 一噌幸弘/大倉源次郎/亀井広忠/金春國和
大蔵流狂言「二人大名」(ふたりだいみょう) 山本 則直/山本泰太郎/
山本 則孝
観世流能「葵上 古式」(あおいのうえ こしき) 観世銕之丞/
宝生 欣哉/山本順之 ほか





