/[webpac]/trunk/all2xml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/all2xml.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by dpavlin, Sat Jan 11 16:44:03 2003 UTC revision 9 by dpavlin, Sat Jan 11 19:55:30 2003 UTC
# Line 7  use Data::Dumper; Line 7  use Data::Dumper;
7  use XML::Simple;  use XML::Simple;
8  use Text::Unaccent 1.02;        # 1.01 won't compile on my platform,  use Text::Unaccent 1.02;        # 1.01 won't compile on my platform,
9  require Unicode::Map8;  require Unicode::Map8;
10    use DBI;
11    
12  my $config=XMLin(undef, forcearray => [ 'isis' ], forcecontent => 1);  my $config=XMLin(undef, forcearray => [ 'isis' ], forcecontent => 1);
13    my $dbh = DBI->connect("DBI:Pg:dbname=webpac","","") || die $DBI::errstr; # FIX
14    # FIX; select relname from pg_class where relname like 'index_%' ;
15    $dbh->begin_work || die $dbh->errstr();
16    
17    $dbh->do("delete from index_author") || die $dbh->errstr();
18    $dbh->do("delete from index_title") || die $dbh->errstr();
19    
20  my %opts;  my %opts;
21    
# Line 57  sub isis2xml { Line 64  sub isis2xml {
64          foreach my $field (keys %{$config->{indexer}}) {          foreach my $field (keys %{$config->{indexer}}) {
65    
66                  my $display_data = "";                  my $display_data = "";
67                    my $swish_data = "";
68                  my $index_data = "";                  my $index_data = "";
69    
70                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
71    
72                          my $display_tmp = "";                          my $display_tmp = "";
73                            my $swish_tmp = "";
74                          my $index_tmp = "";                          my $index_tmp = "";
75    
76                          my $format = $x->{content};                          my $format = $x->{content};
77                          my $i = 1;      # index only                          my $s = 1;      # swish only
78                          my $d = 1;      # display only                          my $d = 1;      # display only
79                          $i = 0 if (lc($x->{type}) eq "display");                          my $i = 0;      # index only
80                          $d = 0 if (lc($x->{type}) eq "index");                          $s = 0 if (lc($x->{type}) eq "display");
81  #print "## i: $i d: $d ## $format ##";                            $d = 0 if (lc($x->{type}) eq "swish");
82                            ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
83    #print STDERR "## s: $s d: $d i: $i ## $format ##\n";  
84                          # parse format                          # parse format
85                          my $prefix = "";                          my $prefix = "";
86                          if ($format =~ s/^([^\d]+)//) {                          if ($format =~ s/^([^\d]+)//) {
# Line 81  sub isis2xml { Line 92  sub isis2xml {
92                                          if ($isis_tmp) {                                          if ($isis_tmp) {
93  #                                               $display_tmp .= $prefix . "/$1/$2/".$isis_tmp if ($d);  #                                               $display_tmp .= $prefix . "/$1/$2/".$isis_tmp if ($d);
94                                                  $display_tmp .= $prefix . $isis_tmp if ($d);                                                  $display_tmp .= $prefix . $isis_tmp if ($d);
95                                                  $index_tmp .= $isis_tmp." " if ($i);                                                  $swish_tmp .= $isis_tmp." " if ($s);
96  #print " $isis_tmp <--\n";                                                  $index_tmp .= $prefix . $isis_tmp if ($i);
97    #print STDERR " $isis_tmp <--\n";
98                                          }                                          }
99                                          $prefix = "";                                          $prefix = "";
100                                  } elsif ($format =~ s/^([^\d]+)//) {                                  } elsif ($format =~ s/^([^\d]+)//) {
# Line 94  sub isis2xml { Line 106  sub isis2xml {
106                          }                          }
107                          # add suffix                          # add suffix
108                          $display_tmp .= $prefix if ($display_tmp);                          $display_tmp .= $prefix if ($display_tmp);
109                            $index_tmp .= $prefix if ($index_tmp);
110    
111  #                       $display_data .= $display_tmp if ($display_tmp ne "");  #                       $display_data .= $display_tmp if ($display_tmp ne "");
112  #                       $index_data .= $index_tmp if ($index_tmp ne "");  #                       $swish_data .= $swish_tmp if ($swish_tmp ne "");
113                          $display_data .= $display_tmp;                          $display_data .= $display_tmp;
114                            $swish_data .= $swish_tmp;
115                          $index_data .= $index_tmp;                          $index_data .= $index_tmp;
116    
117                  }                  }
118  #print "--display:$display_data\n--index:$index_data\n";  #print "--display:$display_data\n--swish:$swish_data\n";
119                  #$xml->{$field."_display"} = $isis_map->tou($display_data)->utf8 if ($display_data);                  #$xml->{$field."_display"} = $isis_map->tou($display_data)->utf8 if ($display_data);
120                  #$xml->{$field."_index"} = unac_string($config->{isis_codepage},$index_data) if ($index_data);                  #$xml->{$field."_swish"} = unac_string($config->{isis_codepage},$swish_data) if ($swish_data);
121                  $xml->{$field."_display" } = [ $isis_map->tou($display_data)->utf8 ] if ($display_data);                  $xml->{$field."_display" } = [ $isis_map->tou($display_data)->utf8 ] if ($display_data);
122                  $xml->{$field."_index"} = [ unac_string($config->{isis_codepage},$index_data)." jabuka" ] if ($index_data);                  $xml->{$field."_swish"} = [ unac_string($config->{isis_codepage},$swish_data) ] if ($swish_data);
123            
124                    # index
125                    if ($index_data && $index_data ne "") {
126                            my $sql = "select $field from index_$field where upper($field)=upper(?)";
127                            my $sth = $dbh->prepare($sql) || die $dbh->errstr();
128                            $sth->execute($index_data) || die "SQL: $sql; ".$dbh->errstr();
129    #print STDERR "--->$index_data<---\n";
130                            if (! $sth->fetchrow_hashref) {
131                                    my $sql = "insert into index_$field values (?)";
132                                    my $sth = $dbh->prepare($sql) || die $dbh->errstr();
133    #print STDERR "$sql: $index_data<!----\n";
134                                    $sth->execute($index_data) || die "SQL: $sql; ".$dbh->errstr();
135                            }
136                    }
137    
138          }          }
139          if ($xml) {          if ($xml) {
140                  return XMLout($xml, rootname => 'xml', keeproot => 0, noattr => 0 );                  return XMLout($xml, rootname => 'xml', keeproot => 0, noattr => 0 );
# Line 189  foreach my $isis_db (@isis_dbs) { Line 217  foreach my $isis_db (@isis_dbs) {
217          print STDERR "\n";          print STDERR "\n";
218  }  }
219    
220    $dbh->commit || die $dbh->errstr();
221    
222  1;  1;
223  __END__  __END__

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26