/[webpac2]/trunk/lib/WebPAC/Normalize/MARC.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Normalize/MARC.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1021 by dpavlin, Sat Nov 10 11:11:16 2007 UTC revision 1024 by dpavlin, Sat Nov 10 11:37:47 2007 UTC
# Line 80  sub marc_template { Line 80  sub marc_template {
80    
81          my $fields_re = join('|', keys %$to_subfields );          my $fields_re = join('|', keys %$to_subfields );
82    
         my $pos_templates;  
         my $fill_in;  
83          my @marc_out;          my @marc_out;
84            
85            our $_template;
86    
87          my ( $marc_template_order, @marc_order ); # = _parse_template( $args->{marc_template} );          sub _parse_template {
88                    my ( $name, $templates ) = @_;
89    
90          my $templates = $args->{marc_template};                  foreach my $template ( @{ $templates } ) {
91                            our $count = {};
92          foreach my $template ( @{ $templates } ) {                          our @marc_order = ();
93                  my $count;                          sub my_count {
94                  my @marc_order;                                  my $sf = shift;
95                  sub my_count {                                  my $nr = $count->{$sf}++;
96                          my $sf = shift;                                  push @marc_order, [ $sf, $nr ];
97                          my $nr = $count->{$sf}++;                                  return $sf . $nr;
98                          push @marc_order, [ $sf, $nr ];                          }
99                          return $sf . $nr;                          my $pos_template = $template;
100                            $pos_template =~ s/($fields_re)/my_count($1)/ge;
101                            my $count_key = dump( $count );
102                            warn "### template: |$template| -> |$pos_template| count = $count_key marc_order = ",dump( @marc_order ),$/;
103                            $_template->{$name}->{pos}->{ $count_key } = $pos_template;
104                            $_template->{$name}->{order}->{ $pos_template } = [ @marc_order ];
105                  }                  }
106                  my $pos_template = $template;                  warn "### from ",dump( $templates ), " created ", dump( $_template );
                 $pos_template =~ s/($fields_re)/my_count($1)/ge;  
                 my $count_key = dump( $count );  
                 warn "### template: |$template| -> |$pos_template| count = $count_key marc_order = ",dump( @marc_order ),$/;  
                 $pos_templates->{ $count_key } = $pos_template;  
                 $marc_template_order->{ $pos_template } = [ @marc_order ];  
107          }          }
108          warn "### from ",dump( $templates ), " created ", dump( $pos_templates ), " and ", dump( $marc_template_order );  
109            _parse_template( 'marc', $args->{marc_template} );
110            _parse_template( 'isis', $args->{isis_template} );
111            warn "### _template = ",dump( $_template );
112    
113          my $m;          my $m;
114    
# Line 137  sub marc_template { Line 141  sub marc_template {
141                  warn "### from_count = ",dump( $from_count ), $/;                  warn "### from_count = ",dump( $from_count ), $/;
142                  warn "### to_count   = ",dump( $to_count ), $/;                  warn "### to_count   = ",dump( $to_count ), $/;
143    
144                  my $template = $pos_templates->{ $from_count_key } ||                  my $template = $_template->{marc}->{pos}->{ $from_count_key } ||
145                          die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $pos_templates );                          die "I don't have template for:\n$from_count_key\n## available templates\n", dump( $_template );
146    
147                  warn "### selected template: |$template|\n";                  warn "### selected template: |$template|\n";
148    
149                  $fill_in = {};                  our $fill_in = {};
150    
151                  my @templates = split(/\|/, $template );                  my @templates = split(/\|/, $template );
152                  @templates = ( $template );                  @templates = ( $template );
# Line 168  sub marc_template { Line 172  sub marc_template {
172                          warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/;                          warn "#### >>>> $sf with fill_in = ",dump( $fill_in ),$/;
173                  }                  }
174    
175                  warn "## template: |$template|\n## marc_template_order = ",dump( $marc_template_order );                  warn "## template: |$template|\n## _template->marc = ",dump( $_template->{marc} );
176    
177                  foreach my $sf ( @{ $marc_template_order->{$template} } ) {                  foreach my $sf ( @{ $_template->{marc}->{order}->{$template} } ) {
178                          my ( $sf, $nr ) = @$sf;                          my ( $sf, $nr ) = @$sf;
179                          my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr";                          my $v = $fill_in->{$sf}->[$nr] || die "can't find fill_in $sf/$nr";
180                          warn "++ $sf/$nr |$v|\n";                          warn "++ $sf/$nr |$v|\n";

Legend:
Removed from v.1021  
changed lines
  Added in v.1024

  ViewVC Help
Powered by ViewVC 1.1.26