1 |
#!/usr/local/perl5.005_56.Mar06/bin/perl -w |
2 |
######################### -*- Mode: Perl -*- ######################### |
3 |
## |
4 |
## $Basename: bibdb $ |
5 |
## $Revision: 1.6 $ |
6 |
## |
7 |
## Author : Ulrich Pfeifer |
8 |
## Created On : Mon Sep 2 12:57:12 1996 |
9 |
## |
10 |
## Last Modified By : Ulrich Pfeifer |
11 |
## Last Modified On : Sun Nov 22 18:44:36 1998 |
12 |
## |
13 |
## Copyright (c) 1996-1997, Ulrich Pfeifer |
14 |
## |
15 |
## |
16 |
###################################################################### |
17 |
|
18 |
eval 'exec perl -S $0 "$@"' |
19 |
if 0; |
20 |
|
21 |
|
22 |
use strict; |
23 |
|
24 |
use File::Path; |
25 |
use DB_File; |
26 |
use Getopt::Long; |
27 |
use Cwd; |
28 |
|
29 |
require WAIT::Config; |
30 |
require WAIT::Database; |
31 |
require WAIT::Parse::Bibdb; |
32 |
require WAIT::Document::Split; |
33 |
require WAIT::InvertedIndex; |
34 |
|
35 |
|
36 |
$DB_BTREE->{'cachesize'} = 200_000 ; |
37 |
|
38 |
my %OPT = (clean => 0, |
39 |
database => 'DB', |
40 |
dir => $WAIT::Config->{WAIT_home} || '/tmp', |
41 |
table => 'bibdb', |
42 |
); |
43 |
|
44 |
GetOptions(\%OPT, |
45 |
'clean!', |
46 |
'database=s', |
47 |
'dir=s', |
48 |
'table=s', |
49 |
) || die "Usage: ...\n"; |
50 |
|
51 |
if ($OPT{clean} and -d "$OPT{dir}/$OPT{database}") { |
52 |
my $tmp = WAIT::Database->open(name => $OPT{database}, |
53 |
'directory' => $OPT{dir}) |
54 |
or die "Could not open table $OPT{table}: $@\n"; |
55 |
my $tbl = $tmp->table(name => $OPT{table}); |
56 |
$tbl->drop if $tbl; |
57 |
rmtree("$OPT{dir}/$OPT{database}/$OPT{table}", 1, 1) |
58 |
if -d "$OPT{dir}/$OPT{database}/$OPT{table}"; |
59 |
$tmp->close; |
60 |
} |
61 |
|
62 |
my $db; |
63 |
unless (-d "$OPT{dir}/$OPT{database}") { |
64 |
$db = WAIT::Database->create(name => $OPT{database}, |
65 |
'directory' => $OPT{dir}) |
66 |
or die "Could not open database $OPT{database}: $@\n"; |
67 |
} |
68 |
else { |
69 |
$db = WAIT::Database->open(name => $OPT{database}, |
70 |
'directory' => $OPT{dir}) |
71 |
or die "Could not open table $OPT{table}: $@\n"; |
72 |
} |
73 |
|
74 |
my $layout = new WAIT::Parse::Bibdb; |
75 |
|
76 |
my $stem = ['detex', 'isotr', 'isolc', 'split2', 'stop', 'Stem']; |
77 |
my $text = [{ |
78 |
'prefix' => ['detex', 'isotr', 'isolc'], |
79 |
'intervall' => ['detex', 'isotr', 'isolc'], |
80 |
}, |
81 |
'detex', 'isotr', 'isolc', 'split2', 'stop']; |
82 |
my $sound = ['detex', 'isotr', 'isolc', 'split2', 'Soundex'],; |
83 |
|
84 |
my $cwd = cwd; |
85 |
my($file) = grep -e $_, @ARGV, "$cwd/t/test.ste", '/usr/local/ls6/tex/bib/bibdb.ste'; |
86 |
|
87 |
my %D; |
88 |
my $access = tie %D, 'WAIT::Document::Split', 'sep', '\f', $file |
89 |
or die "Couldn't tie to $file: $!\n"; |
90 |
|
91 |
my $tb = $db->create_table(name => $OPT{table}, |
92 |
attr => ['docid', 'headline'], |
93 |
layout => $layout, |
94 |
access => $access, |
95 |
invindex => |
96 |
[ |
97 |
'ti' => $stem, 'ti' => $text, |
98 |
'jt' => $stem, 'jt' => $text, |
99 |
'bt' => $stem, 'bt' => $text, |
100 |
'sd' => $stem, 'sd' => $text, |
101 |
'ft' => $stem, 'ft' => $text, |
102 |
'ab' => $stem, |
103 |
'au' => $text, 'au' => $sound, |
104 |
'pn' => $text, 'pn' => $sound, |
105 |
'cc' => [{'prefix' => ['cctr', 'isolc']}, |
106 |
'cctr', 'isolc', 'split3'], |
107 |
'ed' => [{'intervall' => 1}, 'split6'], |
108 |
'py' => [{'intervall' => 1}, 'split4'], |
109 |
] |
110 |
); |
111 |
die "Couldn't create table $OPT{table}: $@\n" unless $tb; |
112 |
|
113 |
my ($did, $value); |
114 |
while (($did, $value) = each %D) { |
115 |
my $record = $layout->split($value); |
116 |
my $headline = sprintf("%-20s %s", ($record->{ck}||''), $record->{ti}); |
117 |
printf "%s\n", substr($headline,0,80); |
118 |
$tb->insert('docid' => $did, |
119 |
headline => $headline, |
120 |
%{$record}); |
121 |
} |
122 |
|
123 |
$db->close(); |
124 |
|
125 |
$WAIT::Config = $WAIT::Config; # make perl -w happy |
126 |
|
127 |
|
128 |
__END__ |
129 |
## ################################################################### |
130 |
## pod |
131 |
## ################################################################### |
132 |
|
133 |
=head1 NAME |
134 |
|
135 |
bibdb - generate an WAIT index for bibdb records |
136 |
|
137 |
=head1 SYNOPSIS |
138 |
|
139 |
B<bibdb> |
140 |
[B<-clean>] [B<-noclean>] |
141 |
[B<-database> I<dbname>] |
142 |
[B<-dir> I<directory>] |
143 |
[B<-table> I<table name>] |
144 |
|
145 |
=head1 DESCRIPTION |
146 |
|
147 |
Either indexes F<$WAIT/t/test.ste> (if called from directory F<$WAIT>) |
148 |
or F</usr/local/ls6/tex/bib/bibdb.ste>. |
149 |
|
150 |
=head1 OPTIONS |
151 |
|
152 |
=over 5 |
153 |
|
154 |
=item B<-clean> / B<-noclean> |
155 |
|
156 |
Clean the table before indexing. Default is B<off>. |
157 |
|
158 |
=item B<-database> I<dbname> |
159 |
|
160 |
Specify database name. Default is F<DB>. |
161 |
|
162 |
=item B<-dir> I<directory> |
163 |
|
164 |
Alternate directory where databases are located. Default is the |
165 |
directory specified during configuration of WAIT. |
166 |
|
167 |
=item B<-table> I<table name> |
168 |
|
169 |
Specify an alternate table name. Default is C<bibdb>. |
170 |
|
171 |
=head1 AUTHOR |
172 |
|
173 |
Ulrich Pfeifer E<lt>F<pfeifer@ls6.informatik.uni-dortmund.de>E<gt> |