--- trunk/run.pl 2005/12/16 01:04:20 255 +++ trunk/run.pl 2005/12/18 23:10:02 290 @@ -9,7 +9,7 @@ use WebPAC::Common 0.02; use WebPAC::Lookup; -use WebPAC::Input::ISIS; +use WebPAC::Input 0.03; use WebPAC::Store 0.03; use WebPAC::Normalize::XML; use WebPAC::Output::TT; @@ -74,28 +74,32 @@ $log->info("database $database doesn't have inputs defined"); } - foreach my $input (@inputs) { + my @supported_inputs = keys %{ $config->{webpac}->{inputs} }; -print Dumper($input); + foreach my $input (@inputs) { my $type = lc($input->{type}); - die "I know only how to handle input type isis, not '$type'!\n" unless ($type eq 'isis'); + die "I know only how to handle input types ", join(",", @supported_inputs), " not '$type'!\n" unless (grep(/$type/, @supported_inputs)); my $lookup = new WebPAC::Lookup( lookup_file => $input->{lookup}, ); - $log->info("working on input $input->{path} [$input->{type}]"); + my $input_module = $config->{webpac}->{inputs}->{$type}; + + $log->info("working on input $input->{path} [$input->{type}] using $input_module"); - my $isis = new WebPAC::Input::ISIS( + my $input_db = new WebPAC::Input( + module => $input_module, code_page => $config->{webpac}->{webpac_encoding}, - limit_mfn => $input->{limit}, + limit => $input->{limit}, lookup => $lookup, ); + $log->logdie("can't create input using $input_module") unless ($input); - my $maxmfn = $isis->open( - filename => $input->{path}, + my $maxmfn = $input_db->open( + path => $input->{path}, code_page => $input->{encoding}, # database encoding ); @@ -107,16 +111,31 @@ prefix => $input->{name}, ); - $n->open( - tag => $input->{normalize}->{tag}, - xml_file => $input->{normalize}->{path}, - ); - - for ( 0 ... $isis->size ) { - - my $row = $isis->fetch || next; + my $normalize_path = $input->{normalize}->{path}; - my $mfn = $row->{'000'}->[0] || die "can't find MFN"; + if ($normalize_path =~ m/\.xml$/i) { + $n->open( + tag => $input->{normalize}->{tag}, + xml_file => $input->{normalize}->{path}, + ); + } elsif ($normalize_path =~ m/\.(?:yml|yaml)$/i) { + $n->open_yaml( + path => $normalize_path, + tag => $input->{normalize}->{tag}, + ); + } + + foreach my $pos ( 0 ... $input_db->size ) { + + my $row = $input_db->fetch || next; + + my $mfn = $row->{000}->[0] || $row->{000} || die "can't find MFN"; + + if ($mfn =~ m#^\d+$#) { + $log->warn("record $pos doesn't have valid MFN but '$mfn', using $pos"); + $mfn = $pos; + $row->{000}->[0] = $pos; + } my $ds = $n->data_structure($row);