|
Lines 485-534
sub _process_mappings {
Link Here
|
| 485 |
$data_copy = length($data) > $start ? substr $data_copy, $start, $length : ''; |
485 |
$data_copy = length($data) > $start ? substr $data_copy, $start, $length : ''; |
| 486 |
} |
486 |
} |
| 487 |
|
487 |
|
| 488 |
# Add data to tokens array for callbacks processing |
488 |
# Add data to values array for callbacks processing |
| 489 |
my $tokens = [$data_copy]; |
489 |
my $values = [$data_copy]; |
| 490 |
|
490 |
|
| 491 |
# Tokenize callbacks takes as token (possibly tokenized subfield data) |
491 |
# Value callbacks takes subfield data (or values from previous |
| 492 |
# as argument, and returns a possibly different list of tokens. |
492 |
# callbacks) as argument, and returns a possibly different list of values. |
| 493 |
# Note that this list also might be empty. |
493 |
# Note that the returned list may also be empty. |
| 494 |
if (defined $options->{tokenize_callbacks}) { |
494 |
if (defined $options->{value_callbacks}) { |
| 495 |
foreach my $callback (@{$options->{tokenize_callbacks}}) { |
495 |
foreach my $callback (@{$options->{value_callbacks}}) { |
| 496 |
# Pass each token to current callback which returns a list |
496 |
# Pass each value to current callback which returns a list |
| 497 |
# (scalar is fine too) resulting either in a list or |
497 |
# (scalar is fine too) resulting either in a list or |
| 498 |
# a list of lists that will be flattened by perl. |
498 |
# a list of lists that will be flattened by perl. |
| 499 |
# The next callback will recieve the possibly expanded list of tokens. |
499 |
# The next callback will recieve the possibly expanded list of values. |
| 500 |
$tokens = [ map { $callback->($_) } @{$tokens} ]; |
500 |
$values = [ map { $callback->($_) } @{$values} ]; |
| 501 |
} |
|
|
| 502 |
} |
| 503 |
if (defined $options->{value_callbacks}) { |
| 504 |
$tokens = [ map { reduce { $b->($a) } ($_, @{$options->{value_callbacks}}) } @{$tokens} ]; |
| 505 |
} |
| 506 |
if (defined $options->{filter_callbacks}) { |
| 507 |
my @tokens_filtered; |
| 508 |
foreach my $_data (@{$tokens}) { |
| 509 |
if ( all { $_->($_data) } @{$options->{filter_callbacks}} ) { |
| 510 |
push @tokens_filtered, $_data; |
| 511 |
} |
| 512 |
} |
501 |
} |
| 513 |
# Overwrite $tokens with filtered values |
|
|
| 514 |
$tokens = \@tokens_filtered; |
| 515 |
} |
502 |
} |
|
|
503 |
|
| 516 |
# Skip mapping if all values has been removed |
504 |
# Skip mapping if all values has been removed |
| 517 |
next unless @{$tokens}; |
505 |
next unless @{$values}; |
| 518 |
|
506 |
|
| 519 |
if (defined $options->{property}) { |
507 |
if (defined $options->{property}) { |
| 520 |
$tokens = [ map { { $options->{property} => $_ } } @{$tokens} ]; |
508 |
$values = [ map { { $options->{property} => $_ } } @{$values} ]; |
| 521 |
} |
509 |
} |
| 522 |
if (defined $options->{nonfiling_characters_indicator}) { |
510 |
if (defined $options->{nonfiling_characters_indicator}) { |
| 523 |
my $nonfiling_chars = $meta->{field}->indicator($options->{nonfiling_characters_indicator}); |
511 |
my $nonfiling_chars = $meta->{field}->indicator($options->{nonfiling_characters_indicator}); |
| 524 |
$nonfiling_chars = looks_like_number($nonfiling_chars) ? int($nonfiling_chars) : 0; |
512 |
$nonfiling_chars = looks_like_number($nonfiling_chars) ? int($nonfiling_chars) : 0; |
| 525 |
# Nonfiling chars does not make sense for multiple tokens |
513 |
# Nonfiling chars does not make sense for multiple values |
| 526 |
# Only apply on first element |
514 |
# Only apply on first element |
| 527 |
$tokens->[0] = substr $tokens->[0], $nonfiling_chars; |
515 |
$values->[0] = substr $values->[0], $nonfiling_chars; |
| 528 |
} |
516 |
} |
| 529 |
|
517 |
|
| 530 |
$record_document->{$target} //= []; |
518 |
$record_document->{$target} //= []; |
| 531 |
push @{$record_document->{$target}}, @{$tokens}; |
519 |
push @{$record_document->{$target}}, @{$values}; |
| 532 |
} |
520 |
} |
| 533 |
} |
521 |
} |
| 534 |
|
522 |
|
|
Lines 920-939
sub _field_mappings {
Link Here
|
| 920 |
}; |
908 |
}; |
| 921 |
} |
909 |
} |
| 922 |
elsif ($target_type eq 'year') { |
910 |
elsif ($target_type eq 'year') { |
| 923 |
$default_options->{tokenize_callbacks} //= []; |
|
|
| 924 |
# Only accept years containing digits and "u" |
| 925 |
push @{$default_options->{tokenize_callbacks}}, sub { |
| 926 |
my ($value) = @_; |
| 927 |
my @years = ( $value =~ /[0-9u]{4}/g ); |
| 928 |
return @years; |
| 929 |
}; |
| 930 |
|
| 931 |
$default_options->{value_callbacks} //= []; |
911 |
$default_options->{value_callbacks} //= []; |
| 932 |
# Replace "u" with "0" for sorting |
912 |
# Only accept years containing digits and "u" |
| 933 |
push @{$default_options->{value_callbacks}}, sub { |
913 |
push @{$default_options->{value_callbacks}}, sub { |
| 934 |
my ($value) = @_; |
914 |
my ($value) = @_; |
| 935 |
$value =~ s/[u]/0/g; |
915 |
# Replace "u" with "0" for sorting |
| 936 |
return $value; |
916 |
return map { s/[u]/0/gr } ( $value =~ /[0-9u]{4}/g ); |
| 937 |
}; |
917 |
}; |
| 938 |
} |
918 |
} |
| 939 |
|
919 |
|
| 940 |
- |
|
|