2 # script that rebuild thesaurus from biblio table.
7 use MARC::File::USMARC;
13 use Time::HiRes qw(gettimeofday);
16 my ( $input_marc_file, $number) = ('',0);
17 my ($version, $verbose, $test_parameter, $field,$delete,$category,$subfields);
21 't' => \$test_parameter,
27 if ($version || ($category eq '')) {
29 small script to recreate a authority table into Koha.
31 \th : this version/help screen
32 \tc : thesaurus category
34 \tt : test mode : parses the file, saying what he would do, but doing nothing.
36 \d : delete every entry of the selected category before doing work.
39 ./rebuildthesaurus.pl -c NP -s "##700#a, ##700#b (##700#c ; ##700#d)" => will build authority file NP with value constructed with 700 field \$a, \$b, \$c & \$d subfields In UNIMARC this rebuild author authority file.
40 ./rebuildthesaurus.pl -c EDITORS -s "##210#c -- ##225#a" => will build authority for editor and collection. The EDITORS authority category is used with plugins for 210 & 225 in UNIMARC.
46 my $dbh = C4::Context->dbh;
47 my @subf = $subfields =~ /(##\d\d\d##.)/g;
49 print "deleting thesaurus\n";
50 my $sth = $dbh->prepare("delete from bibliothesaurus where category=?");
51 $sth->execute($category);
53 if ($test_parameter) {
54 print "TESTING MODE ONLY\n DOING NOTHING\n===============\n";
56 $|=1; # flushes output
58 my $starttime = gettimeofday;
59 my $sth = $dbh->prepare("select bibid from marc_biblio");
62 while (my ($bibid) = $sth->fetchrow) {
63 my $record = GetMarcBiblio($bibid);
65 my $timeneeded = gettimeofday - $starttime;
66 print "$i in $timeneeded s\n" unless ($i % 50);
68 # warn $record->as_formatted;
69 my $resultstring = $subfields;
70 foreach my $fieldwanted ($record->fields) {
71 next if $fieldwanted->tag()<=10;
72 foreach my $pair ( $fieldwanted->subfields() ) {
73 my $fieldvalue = $fieldwanted->tag();
74 # warn "$fieldvalue ==> #$fieldvalue#$pair->[0]/$pair->[1]";
75 $resultstring =~ s/##$fieldvalue##$pair->[0]/$pair->[1]/g;
78 # deals empty subfields
79 foreach my $empty (@subf) {
80 $resultstring =~ s/$empty//g;
82 if ($resultstring ne $subfields && $resultstring) {
83 &newauthority($dbh,$category,$resultstring);
87 my $timeneeded = gettimeofday - $starttime;
88 print "$i entries done in $timeneeded seconds (".($i/$timeneeded)." per second)\n";