/[wait]/cvs-head/script/index_fortune
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /cvs-head/script/index_fortune

Parent Directory Parent Directory | Revision Log Revision Log


Revision 17 - (show annotations)
Tue May 9 11:29:44 2000 UTC (23 years, 11 months ago) by ulpfr
File size: 4015 byte(s)
Initial revision

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

Properties

Name Value
cvs2svn:cvs-rev 1.1

  ViewVC Help
Powered by ViewVC 1.1.26