6 use Equinox::Migration::MapDrivenMARCXMLProc;
7 use Equinox::Migration::MARCXMLSampler;
12 # run samples if we've been asked for them
13 run_samples($c) if ($c->{sample} or $c->{samplemap} or $c->{samplestr});
19 if ($c->{samplemap}) {
20 $s = Equinox::Migration::MARCXMLSampler->new( marcfile => $c->{marcfile},
21 mapfile => $c->{samplemap});
22 } elsif ($c->{samplestr}) {
23 $s = Equinox::Migration::MARCXMLSampler->new( marcfile => $c->{marcfile},
24 mapstring => $c->{samplestr});
26 $s = Equinox::Migration::MARCXMLSampler->new( marcfile => $c->{marcfile} );
30 dump_sample_overview($c, $s) if $c->{sample};
31 dump_sample_detail($c, $s) if ($c->{samplemap} or $c->{samplestr});
34 sub dump_sample_detail {
36 my $tags = $s->{data}{samp};
37 my $count = $s->{data}{rcnt};
39 open DETAIL, '>', ($c->{prefix} . "-HOLDINGS-DETAIL.txt");
41 for my $tag (sort keys %{$tags}) {
42 print ">>>>> TAG $tag\n";
43 for my $subkey (sort keys %{$tags->{$tag}}) {
44 my $sub = $tags->{$tag}{$subkey};
45 print " Subfield: $subkey\n";
46 print " Sample: '", $sub->{value}, "'\n\n";
47 print " Count: ", $sub->{count}, " in ", $sub->{rcnt}, " tags\n";
48 #print "(", int($sub->{count} / $sub->{rcnt}), "%)\n";
55 sub dump_sample_overview {
57 my $tags = $s->{data}{tags};
58 my $count = $s->{data}{rcnt};
60 my @tagsbyname = sort keys %{$tags};
61 my @tagsbycount = reverse sort { $tags->{$a} <=> $tags->{$b} } keys %{$tags};
63 open SAMPLE, '>', ($c->{prefix} . "-HOLDINGS-OVERVIEW.txt");
65 print "FOUND TAGS (BY TAG) FOUND TAGS (BY COUNT)\n";
66 print "------------------- ---------------------\n";
67 for my $i (0 .. @tagsbyname - 1) {
68 print $tagsbyname[$i], (" " x (14 - length $tags->{ $tagsbyname[$i] })),
69 $tags->{ $tagsbyname[$i] }, " ";
70 print $tagsbycount[$i], (" " x (16 - length $tags->{ $tagsbycount[$i] })),
71 $tags->{ $tagsbycount[$i] }, "\n";
77 #--------------------------
83 # set mode on existing filehandles
84 binmode(STDIN, ':utf8');
86 my $rc = GetOptions( $c,
96 show_help() unless $rc;
97 show_help() if ($c->{help});
99 my @keys = keys %{$c};
100 for my $key ('prefix', 'ils')
101 { push @missing, $key unless $c->{$key} }
103 print "Required option: ", join(', ', @missing), " missing!\n";
112 Usage is: extract_holdings -p PREFIX -m MAPFILE -i ILS [OPTIONS] <MARCXML>
113 prefix p Prefix string for output filenames
114 map m Subfield map file to use
115 ils i Legacy ILS name (affects SQL generation)
117 sample s Comma-delineated list of datafield tags to be sampled
118 library l Legacy library name (affects SQL generation)