PageRenderTime 65ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/old2/vtls/biblio_masher.pl

https://bitbucket.org/jcamins/migration-toolbox
Perl | 188 lines | 132 code | 36 blank | 20 comment | 26 complexity | bcc939000dd2dda8b95368bda82e966f MD5 | raw file
Possible License(s): GPL-3.0
  1. #!/usr/bin/perl
  2. #---------------------------------
  3. # Copyright 2010 ByWater Solutions
  4. #
  5. #---------------------------------
  6. #
  7. # This script is intended to ingest a MARC-formatted bib/item file from
  8. # VTLS Virtua, and write an output file in a form that can be
  9. # fed to ByWater's General Purpose Database Table Loader script, for items,
  10. # and a MARC file for bulkmarcimport, cleaned up, for the MARCs.
  11. #
  12. # -D Ruth Bavousett
  13. #
  14. #---------------------------------
  15. use strict;
  16. use Getopt::Long;
  17. use MARC::File::USMARC;
  18. use MARC::Record;
  19. use MARC::Batch;
  20. use MARC::Charset;
  21. my $infile_name = "";
  22. my $outfile_name = "";
  23. my $marcfile_name = "";
  24. GetOptions(
  25. 'in=s' => \$infile_name,
  26. 'out=s' => \$outfile_name,
  27. );
  28. if (($infile_name eq '') || ($outfile_name eq '')){
  29. print << 'ENDUSAGE';
  30. Usage: biblio_masher --in=<infile> --out=<outfile>
  31. <infile> A MARC-formatted data file, from which you wish to extract data.
  32. <outfile> A MARC-formatted output file, for cleaned MARC records.
  33. ENDUSAGE
  34. exit;
  35. }
  36. open MARCFL,">:utf8", $outfile_name;
  37. my $fh = IO::File->new($infile_name);
  38. my $batch = MARC::Batch->new('USMARC',$fh);
  39. $batch->warnings_off();
  40. $batch->strict_off();
  41. my $iggy = MARC::Charset::ignore_errors(1);
  42. my $setting = MARC::Charset::assume_encoding('marc8');
  43. my $i=0;
  44. my $ebrary_skip=0;
  45. my $westbook=0;
  46. my %types;
  47. my %types_noitem;
  48. while () {
  49. my $record = $batch->next();
  50. $i++;
  51. print ".";
  52. print "\r$i" unless $i % 100;
  53. if ($@){
  54. print "Bogusness skipped\n";
  55. next;
  56. }
  57. last unless ($record);
  58. if ($record->subfield("710","a")){
  59. if ($record->subfield("710","a") =~ /ebrary/){
  60. $ebrary_skip++;
  61. next;
  62. }}
  63. my $price = 0;
  64. if ($record->subfield("350","a")){
  65. $price = $record->subfield("350","a");
  66. #$price =~ s/\D\.]//;
  67. $price =~ s/(\d+(\.[0-9]{2}))/$1/;
  68. $price =~ s/\$//g;
  69. }
  70. my $repl_price = ($price < 60.00 ? 60 : $price);
  71. my $bibcall = $record->subfield("090","a")." ".$record->subfield("090","b");
  72. my %homebranch;
  73. my %itype;
  74. my %itemcall;
  75. my %itemnote;
  76. my $deftype="";
  77. foreach my $field ($record->field("949")){
  78. # BARCODE
  79. my $barcode=$field->subfield("6");
  80. # HOMEBRANCH/HOLDINGBRANCH
  81. if ($field->subfield("D") eq "10009"){
  82. $homebranch{$barcode} = "WEST";
  83. $westbook++;
  84. }
  85. else {
  86. $homebranch{$barcode} = "MAIN";
  87. }
  88. # ITEM CALL
  89. if ($field->subfield("a")){
  90. $itemcall{$barcode} = $field->subfield("a");
  91. }
  92. else {
  93. $itemcall{$barcode} = $bibcall;
  94. }
  95. # ITYPE
  96. $itype{$barcode} = "BOOK";
  97. my $locn = $field->subfield("D");
  98. $itype{$barcode} = "SPCOLL" if ($locn eq "10004");
  99. $itype{$barcode} = "ILL" if ($locn eq "10010");
  100. $itype{$barcode} = "ARCHIVE" if ($locn eq "10003");
  101. $itype{$barcode} = "REF" if ($locn eq "10002");
  102. $itype{$barcode} = "CDROM" if ($itemcall{$barcode} =~ "^CD-ROM");
  103. $itype{$barcode} = "KIT" if ($itemcall{$barcode} =~ "^KIT");
  104. $itype{$barcode} = "PASS" if ($itemcall{$barcode} =~ "^PASS");
  105. $itype{$barcode} = "VHS" if ($itemcall{$barcode} =~ "^VHS");
  106. $itype{$barcode} = "DVD" if ($itemcall{$barcode} =~ "^DVD");
  107. $itype{$barcode} = "MUSIC" if ($itemcall{$barcode} =~ "^CD");
  108. $itype{$barcode} = "CASSBOOK" if ($itemcall{$barcode} =~ "^CASS");
  109. $itype{$barcode} = "CDBOOK" if (substr($record->leader(),6,1) eq "i");
  110. $types{$itype{$barcode}}++;
  111. $deftype = $itype{$barcode};
  112. #NOTE
  113. $itemnote{$barcode} = $field->subfield("9");
  114. }
  115. foreach my $dumpfield($record->field('9..')){
  116. $record->delete_field($dumpfield);
  117. }
  118. if ($deftype eq ""){
  119. $deftype = $bibcall =~ "^Per" ? "PERIOD" : "BOOK";
  120. if ($record->subfield("710","a") =~ /NetLibrary/){
  121. $deftype = "EBOOK";
  122. }
  123. $types_noitem{$deftype}++;
  124. }
  125. my $deffield=MARC::Field->new("942"," "," ","c" => $deftype);
  126. $record->insert_grouped_field($deffield);
  127. foreach my $key (sort keys %homebranch){
  128. my $itmtag=MARC::Field->new("952"," "," ",
  129. "p" => $key,
  130. "a" => $homebranch{$key},
  131. "b" => $homebranch{$key},
  132. "o" => $itemcall{$key},
  133. "y" => $itype{$key},
  134. "g" => $price,
  135. "z" => $itemnote{$key},
  136. "2" => "lcc",
  137. "v" => $repl_price);
  138. $record->insert_grouped_field($itmtag);
  139. }
  140. print MARCFL $record->as_usmarc();
  141. }
  142. close MARCFL;
  143. print "\n\nRESULTS BY CATEGORYCODE\n";
  144. foreach my $kee (sort keys %types){
  145. print $kee.": ".$types{$kee}."\n";
  146. }
  147. print "COUNTS OF NO-ITEMS TYPES:\n";
  148. foreach my $kee (sort keys %types_noitem){
  149. print $kee.": ".$types_noitem{$kee}."\n";
  150. }
  151. print "\nWEST BOOKS: $westbook\n\n";
  152. print "Ebrary skipped: $ebrary_skip\n";