/[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 678 by dpavlin, Sun Feb 27 23:07:35 2005 UTC revision 730 by dpavlin, Thu Apr 13 19:44:51 2006 UTC
# Line 64  my %type2tag = ( Line 64  my %type2tag = (
64          'excel' => 'column',          'excel' => 'column',
65          'marc' => 'marc',          'marc' => 'marc',
66          'feed' => 'feed',          'feed' => 'feed',
         'dbf' => 'isis',        # special case, re-use isis import_xml  
67  );  );
68    
69  my $cache;      # for cacheing  my $cache;      # for cacheing
# Line 127  sub data2xml { Line 126  sub data2xml {
126          delete $cache->{swish_exact_data};          delete $cache->{swish_exact_data};
127          delete $cache->{index_data};          delete $cache->{index_data};
128          delete $cache->{index_delimiter};          delete $cache->{index_delimiter};
129            delete $cache->{distinct};
130          my @page_fields;        # names of fields          my @page_fields;        # names of fields
131    
132    
# Line 226  sub data2xml { Line 226  sub data2xml {
226    
227                  my ($swish,$display);                  my ($swish,$display);
228    
229                  my $tag = $type2tag{$type} || die "can't find which tag to use for type $type";                  my $tag = $cfg->val($database, 'import_xml_tag') || $type2tag{$type} || die "can't find which tag to use for type $type";
230    
231                  # is this field page-by-page?                  # is this field page-by-page?
232                  my $iterate_by_page = $config->{indexer}->{$field}->{iterate_by_page};                  my $iterate_by_page = $config->{indexer}->{$field}->{iterate_by_page};
# Line 235  sub data2xml { Line 235  sub data2xml {
235                  # default line_delimiter if using                  # default line_delimiter if using
236                  my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '<br/>';                  my $page_line_delimiter = $config->{indexer}->{$field}->{page_line_delimiter} || '<br/>';
237                  $cache->{index_delimiter}->{$field} = $config->{indexer}->{$field}->{index_delimiter};                  $cache->{index_delimiter}->{$field} = $config->{indexer}->{$field}->{index_delimiter};
238                    my $distinct = $config->{indexer}->{$field}->{distinct};
239                    if ($distinct && !$iterate_by_page) {
240                            warn "WARNING: distinct is currently not supported without iterate_by_page!\n";
241                            $distinct = 0;
242                    }
243    
244                  my $format_name = $config->{indexer}->{$field}->{format_name};                  my $format_name = $config->{indexer}->{$field}->{format_name};
245                  my $format_delimiter = $config->{indexer}->{$field}->{format_delimiter};                  my $format_delimiter = $config->{indexer}->{$field}->{format_delimiter};
# Line 413  sub data2xml { Line 418  sub data2xml {
418                                                  $ldel = " " if ($append);                                                  $ldel = " " if ($append);
419  #print STDERR "line delimiter: ",Dumper($ldel) if ($ldel);  #print STDERR "line delimiter: ",Dumper($ldel) if ($ldel);
420                                                  if (! $cache->{$what}->{$field}->[$page]) {                                                  if (! $cache->{$what}->{$field}->[$page]) {
421                                                          $cache->{$what}->{$field}->[$page] = $data;                                                          push @{$cache->{$what}->{$field}->[$page]}, {
422                                                  } else {                                                                  data => $data,
423                                                          $cache->{$what}->{$field}->[$page] .= $ldel.$data;                                                                  delimiter => $ldel,
424                                                            };
425                                                  }                                                  }
426                                          }                                          }
427    
# Line 490  sub data2xml { Line 496  sub data2xml {
496                                  # on first page!!!                                  # on first page!!!
497                                  my $page = 0;                                  my $page = 0;
498                                  if ($display_data) {                                  if ($display_data) {
499                                          $cache->{display_data}->{$field}->[$page] = $display_data;                                          push @{$cache->{display_data}->{$field}->[$page]}, { data => $display_data };
500                                          $display_data = "";                                          $display_data = "";
501                                  }                                  }
502                                  if ($swish_data) {                                  if ($swish_data) {
503                                          $cache->{swish_data}->{$field}->[$page] = $swish_data;                                          push @{$cache->{swish_data}->{$field}->[$page]}, { data => $swish_data };
504                                          $swish_data = "";                                          $swish_data = "";
505                                  }                                  }
506                                  if ($swish_exact_data) {                                  if ($swish_exact_data) {
507                                          $cache->{swish_exact_data}->{$field}->[$page] = $swish_exact_data;                                          push @{$cache->{swish_exact_data}->{$field}->[$page]}, { data => $swish_exact_data };
508                                          $swish_exact_data = "";                                          $swish_exact_data = "";
509                                  }                                  }
510                          }                          }
# Line 509  sub data2xml { Line 515  sub data2xml {
515                          my $nr_pages = $page_max{$field} || next;                          my $nr_pages = $page_max{$field} || next;
516  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";  #print STDERR "field '$field' iterate over ",($nr_pages || 0)," pages...\n";
517  #print STDERR Dumper($cache->{display_data});  #print STDERR Dumper($cache->{display_data});
518                            my $seen;       # used for distinct
519                          for (my $page=0; $page <= $nr_pages; $page++) {                          for (my $page=0; $page <= $nr_pages; $page++) {
520                                  my $display_data;                                  my $display_data;
521                                  if ($cache->{format}->{$field}) {                                  my $delimiter = '';
522                                          my $tmp = mkformat($cache->{format}->{$field},$cache->{display_data}->{$field}->[$page]);                                  foreach my $element (@{ $cache->{display_data}->{$field}->[$page] }) {
523                                          $display_data=$tmp if ($tmp);                                          my $data = $element->{data};
524                                  } else {                                          die "BUG! no data in element?" unless ($data);
525                                          $display_data = $cache->{display_data}->{$field}->[$page];  
526                                            if ($distinct) {
527                                                    next if ($cache->{distinct}->{$field}->{ $data });
528                                                    $cache->{distinct}->{$field}->{ $data } = 1;
529                                            }
530    
531                                            if ($cache->{format}->{$field}) {
532                                                    my $tmp = mkformat($cache->{format}->{$field},$data);
533                                                    $display_data .= $delimiter . $tmp if ($tmp);
534                                            } else {
535                                                    $display_data .= $delimiter . $data;
536                                            }
537                                            $delimiter = $element->{delimiter} if ($element->{delimiter});
538                                  }                                  }
539    
540                                  if ($display_data) { # default                                  if ($display_data) { # default
541                                          if ($field eq "headline") {                                          if ($field eq "headline") {
542                                                  $xml .= xmlify("headline", $display_data);                                                  $xml .= xmlify("headline", $display_data);
# Line 528  sub data2xml { Line 548  sub data2xml {
548                                          }                                          }
549                                  }                                  }
550                                                                    
551                                  my $swish_data = $cache->{swish_data}->{$field}->[$page];                                  my $swish_data = join(" ",map { $_->{data} } @{ $cache->{swish_data}->{$field}->[$page] });
552                                  if ($swish_data) {                                  if ($swish_data) {
553                                          # remove extra spaces                                          # remove extra spaces
554                                          $swish_data =~ s/ +/ /g;                                          $swish_data =~ s/ +/ /g;
# Line 537  sub data2xml { Line 557  sub data2xml {
557                                          $xml .= xmlify($field."_swish", my_unac_string($codepage,$swish_data));                                          $xml .= xmlify($field."_swish", my_unac_string($codepage,$swish_data));
558                                  }                                  }
559    
560                                  my $swish_exact_data = $cache->{swish_exact_data}->{$field}->[$page];                                  my $swish_exact_data = join(" ", map { $_->{data} } @{ $cache->{swish_exact_data}->{$field}->[$page] });
561                                  if ($swish_exact_data) {                                  if ($swish_exact_data) {
562                                          $swish_exact_data =~ s/ +/ /g;                                          $swish_exact_data =~ s/ +/ /g;
563                                          $swish_exact_data =~ s/ +$//g;                                          $swish_exact_data =~ s/ +$//g;
# Line 668  foreach my $database ($cfg->Sections) { Line 688  foreach my $database ($cfg->Sections) {
688                  print STDERR "opening lookup file '$lookup_file'\n";                  print STDERR "opening lookup file '$lookup_file'\n";
689          }          }
690    
691          my $import_xml_file = "./import_xml/$type.xml";          my $import_xml_type = $cfg->val($database, 'import_xml_file') || $type;
692            my $import_xml_file = "./import_xml/$import_xml_type.xml";
693    
694          if (! -r $import_xml_file) {          if (! -r $import_xml_file) {
695                  print STDERR "ERROR: file $import_xml_file not readable skipping!\n";                  print STDERR "ERROR: file $import_xml_file not readable skipping!\n";
# Line 681  foreach my $database ($cfg->Sections) { Line 702  foreach my $database ($cfg->Sections) {
702          my $type_base = $type;          my $type_base = $type;
703          $type_base =~ s/_.+$//g;          $type_base =~ s/_.+$//g;
704    
705          $config=XMLin($import_xml_file, ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 );          my $tag = $cfg->val($database, 'import_xml_tag') || $type2tag{$type_base} || die "can't find which tag to use for type $type";
706            $config=XMLin($import_xml_file, ForceArray => [ $tag, 'config', 'format' ], ForceContent => 1 );
707    
708          # helper for progress bar          # helper for progress bar
709          sub fmt_time {          sub fmt_time {
# Line 743  foreach my $database ($cfg->Sections) { Line 765  foreach my $database ($cfg->Sections) {
765          }          }
766    
767          # now read database          # now read database
 print STDERR "using: $type...\n";  
768    
769          # erase cache for tags by order in this database          # erase cache for tags by order in this database
770          delete $cache->{tags_by_order};          delete $cache->{tags_by_order};
# Line 795  print STDERR "using: $type...\n"; Line 816  print STDERR "using: $type...\n";
816                  my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!";                  my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!";
817    
818                  my $sheet = x($config->{sheet}) || die "no sheet in $type.xml";                  my $sheet = x($config->{sheet}) || die "no sheet in $type.xml";
819                  my $start_row = x($config->{start_row}) - 1 || die "no start_row in $type.xml";                  my $start_row = x($config->{start_row}) || die "no start_row in $type.xml";
820                    $start_row--;
821    
822                  my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($excel_file) || die "can't open Excel file '$excel_file'";                  my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($excel_file) || die "can't open Excel file '$excel_file'";
823    

Legend:
Removed from v.678  
changed lines
  Added in v.730

  ViewVC Help
Powered by ViewVC 1.1.26