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