8 use Text::Unaccent 1.02; # 1.01 won't compile on my platform,
16 $config=XMLin(undef, forcearray => [ 'isis' ], forcecontent => 1);
18 use index_DBI; # there is no other, right now ;-)
20 my $index = new index_DBI(); # open index
26 # -m multiple directories
30 getopts('d:m:qs', \%opts);
32 my $db_dir = $opts{d} || "ps"; # FIX
34 #die "usage: $0 -d [database_dir] -m [database1,database2] " if (! %opts);
36 #print Dumper($config->{indexer});
39 Text::Iconv->raise_error(1); # Conversion errors raise exceptions
41 my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');
42 my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
43 my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');
52 $xml .= xmlify('db_dir',$db_dir); # FIX remove?
57 foreach my $field (keys %{$config->{indexer}}) {
60 my $display_data = "";
63 foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
65 my $format = $x->{content};
66 my ($s,$d,$i) = (1,1,0); # swish, display default
67 $s = 0 if (lc($x->{type}) eq "display");
68 $d = 0 if (lc($x->{type}) eq "swish");
69 ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
70 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";
72 $format = $cludge_codepage->convert($format);
73 my ($swish,$display) = parse_format($format,$row);
74 #print STDERR "s: $swish\nd: $display\n" if ($swish);
76 #print STDERR "swish: $swish<-- display: $display<--\n";
77 # FIX: this is ugly, UGLY, cludge: OpenIsis return
78 # UTF8 encoding of strings, but as if source charset
79 # is ISO8859-1 and not some other. This breaks our
80 # isis character encoding, so we convert it first
81 # back to ISO8859-1 (which can actually be different
84 $swish_data .= $swish if ($s && $swish);
85 $display_data .= $display if ($d && $display);
86 $index_data .= $display if ($i && $display);
89 #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
91 $display_data = $isis_codepage->convert($display_data)."##" || $display_data;
92 $xml .= xmlify($field."_display", $display_data);
95 my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
96 $swish_data = $i->convert($swish_data);
97 $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
98 #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
99 #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
103 if ($index_data && $index_data ne "") {
104 $index_data = $index_codepage->convert($index_data) || $index_data;
105 $index->insert($field, $index_data, $db_dir);
110 #print STDERR "x: $xml\n";
111 return "<xml>\n$xml</xml>\n";
117 ##########################################################################
121 my @isis_dirs = ( '.' ); # use dirname as database name
124 @isis_dirs = split(/,/,$opts{m});
129 foreach (@isis_dirs) {
130 if (-e $config->{isis_data}."/$db_dir/$_/LIBRI") {
131 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/LIBRI/LIBRI";
133 if (-e $config->{isis_data}."/$db_dir/$_/PERI") {
134 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/PERI/PERI";
136 if (-e $config->{isis_data}."/$db_dir/$_/AMS") {
137 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/AMS/AMS";
139 if (-e $config->{isis_data}."/$db_dir/$_/ARTI") {
140 # push @isis_dbs,$config->{isis_data}."/$db_dir/$_/ARTI/ARTI";
144 print STDERR "FATAL: Can't find isis database.\nPerhaps isis_data (".$config->{isis_data}.") has wrong value?\n" if (! @isis_dbs);
148 foreach my $isis_db (@isis_dbs) {
151 my $db = OpenIsis::open( $isis_db );
155 print STDERR "WARNING: can't open '$isis_db'\n";
159 my $max_rowid = OpenIsis::maxRowid( $db );
161 print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
164 $path =~ s#$config->{isis_data}/*##g;
168 # { my $row_id = 4514;
170 for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
171 my $row = OpenIsis::read( $db, $row_id );
172 if ($row && $row->{mfn}) {
173 #print STDERR "mfn: ",$row->{mfn},"\n";
174 # output current process indicator
175 my $p = int($row->{mfn} * 100 / $max_rowid);
177 printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$row->{mfn},$max_rowid,"=" x ($p/2).">", $p ) if (! $opts{q});
181 if (my $xml = isis2xml($row)) {
182 #print STDERR "--ret-->$xml\n";
183 print "Path-Name: $path#".int($row->{mfn})."\n";
184 print "Content-Length: ".(length($xml)+1)."\n";
185 print "Document-Type: XML\n\n$xml\n";
192 # call this to commit index
197 ##########################################################################
201 isis2xml.pl - read isis file and dump XML
205 This command will read ISIS data file using OpenIsis perl module and
206 create XML file for usage with I<SWISH-E>
207 indexer. Dispite it's name, this script B<isn't general xml generator>
208 from isis files (isis allready has something like that). Output of this
209 script is tailor-made for SWISH-E.
213 Dobrica Pavlinusic <dpavlin@rot13.org>
217 GNU Public License (GPL) v2 or later
221 SWISH-E web site at http://www.swish-e.org