freeWAIS-sf-2.1.2 で作成する転置インデックスファイルをダンプする
ツールに inverted_file (perl script) がありますが、以下は、これを
little endian で機能するようにしたものです。(inverted_file.le)
keyword, weight, occurrence を表示しますが、keyword の出現位置は
表示しません。
inverted_file.le により、FreeBSD など pentium 系で作成した転置
インデックスを閲覧することができます。なお、SPARC など big endian
系で作成したものも表示できます。
== ここより ===================================================================
#!/usr/local/bin/perl
#
# inverted_file.le
#
# This program is based on inverted_file in freeWAIS-sf-2.1.2/bin
# to be available on little endian.
#
$db = $ARGV[0];
open(INV, "<$db.inv") || die "Could not open $db.inv: $!\n";
if ($#ARGV > $[) {
seek(INV,$ARGV[1],0);
&entry;
} else {
read(INV,$head,4);
($nib) = unpack('N', $head);
print "$db.inv contains $nib terms\n";
$terms=0;
while (!eof(INV)) {
&header();
&entry();
$terms++;
}
}
sub entry {
my($np, $i);
$np = &header_rest();
for($i=0;$i<$np;$i++) {
&posting($np);
}
}
sub header {
my($entry, $df, $x, $y, $next_1, $size_1, $postings,
$occ, $term);
read(INV,$entry,13);
($df, $x, $y, $next_1, $size_1, $occ) = unpack('CCCNnN', $entry);
#^^^ 00 00 0000 ^^^^^^^ ^^^^
die "Dictionary flag not valid" if $df != 123;
read(INV,$term,$size_1-13); chomp($term);
printf ("%-20s %6d\n", $term, $occ);
}
sub header_rest {
my($full,$postings,$size_2);
read(INV,$entry,9);
($full,$postings,$size_2,) = unpack('aNL', $entry);
#^^^^^ ^^^^^^^ 0000 ^^^^^^^
#print "$size_2)\n";
die "invalid full flag: $full" if $full ne 'E';
die if $x;
die if $y;
die if $next_1;
return($postings);
}
sub posting {
my($ints) = @_;
my($docid, $size_3, $weight, $p1, $p2, $p3);
read(INV,$entry,15);
($docid,$size_3,$weight, $p1,$p2,$p3) = unpack('NLfCCC', $entry);
printf ("\t\t(%6d, %7.5f)\n", $docid,$weight);
read(INV,$entry,$size_3-3);
}
== ここまで ===================================================================