5 # Parse MFHD patterns for http://www.loc.gov/marc/holdings/hd853855.html
8 # Expected input: a chunk of MFHD, a start date, and # of issuances to project
9 # Expected output: a set of issuances projected forward from the start date,
10 # with issue/volume/dates/captions conforming to what the MFHD actually says
12 # The thought had been to use Date::Manip to generate the actual dates for
13 # each issuance, like:
15 # # To find the 2nd Tuesday of every month
16 # @date = ParseRecur("0:1*2:2:0:0:0",$base,$start,$stop);
18 # Secondary goal: generate automatic summary holdings
19 # (a la http://www.loc.gov/marc/holdings/hd863865.html)
21 # Compressability comes from first indicator
22 sub parse_compressability {
23 my $c = shift || return undef;
25 my %compressability = (
26 '0' => 'Cannot compress or expand',
27 '1' => 'Can compress but cannot expand',
28 '2' => 'Can compress or expand',
33 if (exists $compressability{$c}) {
34 return $compressability{$c};
36 # 'Unknown compressability indicator - expected one of (0,1,2,3,#)';
40 # Caption evaluation comes from second indicator
41 sub caption_evaluation {
42 my $ce = shift || return undef;
44 my %caption_evaluation = (
45 '0' => 'Captions verified; all levels present',
46 '1' => 'Captions verified; all levels may not be present',
47 '2' => 'Captions unverified; all levels present',
48 '3' => 'Captions unverified; all levels may not be present',
52 if (exists $caption_evaluation{$ce}) {
53 return $caption_evaluation{$ce};
55 # 'Unknown caption evaluation indicator - expected one of (0,1,2,3,#)';
59 # Start with frequency ($w)
60 # then overlay number of pieces of issuance ($p)
61 # then regularity pattern ($y)
71 'i' => 'three times a week',
72 'j' => 'three times a month',
73 'k' => 'continuously updated',
77 't' => 'three times a year',
79 'x' => 'completely irregular',
83 my $freq = shift || return undef;
85 if ($freq =~ m/^\d+$/) {
86 return "$freq times a year";
87 } elsif (exists $frequency{$freq}) {
88 return $frequency{$freq};
90 # unrecognized frequency specification
94 # $x - Point at which the highest level increments or changes
95 # Interpretation of two-digit numbers in the 01-12 range depends on the publishing frequency
96 # More than one change can be passed in the subfield and are delimited by commas
97 sub chronology_change {
98 my $chronology_change = shift || return undef;
99 my @c_changes = split /,/, $chronology_change;
100 foreach my $change (@c_changes) {
108 # Publication code : first character in regularity pattern ($y)
109 sub parse_publication_code {
110 my $c = shift || return undef;
112 my %publication_code = (
119 if (exists $publication_code{$c}) {
120 return $publication_code{$c};
125 # Chronology code : part of regularity pattern ($y)
126 sub parse_chronology_code {
127 my $c = shift || return undef;
129 my %chronology_code = (
135 'e' => 'Enumeration',
138 if (exists $chronology_code{$c}) {
139 return $chronology_code{$c};
144 sub parse_regularity_pattern {
146 my ($pc, $cc, $cd) = $pattern =~ m{^(\w)(\w)(.+)$};
148 my $pub_code = parse_publication_code($pc);
149 my $chron_code = parse_chronology_code($cc);
150 my $chron_def = parse_chronology_definition($cd);
152 return ($pub_code, $chron_code, $chron_def);
155 sub parse_chronology_definition {
156 my $chron_def = shift || return undef;
157 # Well, this is where it starts to get hard, doesn't it?
161 print parse_regularity_pattern("cddd");
163 print parse_regularity_pattern("38dd");
168 # :vim:noet:ts=4:sw=4: