Lines 58-63
use vars qw(@ISA @EXPORT);
Link Here
|
58 |
marc2madsxml |
58 |
marc2madsxml |
59 |
marc2bibtex |
59 |
marc2bibtex |
60 |
marc2csv |
60 |
marc2csv |
|
|
61 |
marc2cites |
61 |
marcrecord2csv |
62 |
marcrecord2csv |
62 |
changeEncoding |
63 |
changeEncoding |
63 |
); |
64 |
); |
Lines 855-860
sub marc2bibtex {
Link Here
|
855 |
return $tex; |
856 |
return $tex; |
856 |
} |
857 |
} |
857 |
|
858 |
|
|
|
859 |
=head2 marc2cites - Convert from MARC21 and UNIMARC to citations |
860 |
|
861 |
my $cites = marc2cites($record); |
862 |
|
863 |
Returns hashref of citation from MARC data, suitable to pass to templates. |
864 |
Hash keys store citation system names, hash values citation string. |
865 |
|
866 |
C<$record> - a MARC::Record object |
867 |
|
868 |
=cut |
869 |
|
870 |
sub marc2cites { |
871 |
my $record = shift; |
872 |
my $marcflavour = C4::Context->preference("marcflavour"); |
873 |
my %cites = (); |
874 |
my @authors = (); |
875 |
my $re_clean = qr/(^[\.,:;\/\-\s]+|[\.,:;\/\-\s]+$)/; |
876 |
|
877 |
my @authors; |
878 |
my @authorFields = ('100','110','111','700','710','711'); |
879 |
@authorFields = ('700','701','702','710','711','721') if ( $marcflavour eq "UNIMARC" ); |
880 |
|
881 |
foreach my $ftag ( @authorFields ) { |
882 |
foreach my $field ($record->field($ftag)) { |
883 |
my $author = ''; |
884 |
if ( $marcflavour eq "UNIMARC" ) { |
885 |
$author = join ', ', |
886 |
( $field->subfield("a"), $field->subfield("b") ); |
887 |
} else { |
888 |
$author = $field->subfield("a"); |
889 |
} |
890 |
if($author =~ /([^,]+),?(.*)/) { |
891 |
my %a; |
892 |
($a{'surname'} = $1) =~ s/$re_clean//g; |
893 |
$a{'forenames'} = [map {s/$re_clean//g;$_} split ' ', $2]; |
894 |
push(@authors, \%a); |
895 |
} |
896 |
} |
897 |
} |
898 |
|
899 |
my %publication; |
900 |
if ( $marcflavour eq "UNIMARC" ) { |
901 |
%publication = ( |
902 |
title => $record->subfield("200", "a") || "", |
903 |
place => $record->subfield("210", "a") || "", |
904 |
publisher => $record->subfield("210", "c") || "", |
905 |
date => $record->subfield("210", "d") || $record->subfield("210", "h") || "" |
906 |
); |
907 |
} else { |
908 |
%publication = ( |
909 |
title => $record->subfield("245", "a") || "", |
910 |
place => $record->subfield("260", "a") || "", |
911 |
publisher => $record->subfield("264", "b") || $record->subfield("260", "b") || "", |
912 |
date => $record->subfield("264", "c") || $record->subfield("260", "c") || $record->subfield("260", "g") || "" |
913 |
); |
914 |
} |
915 |
|
916 |
$publication{$_} =~ s/$re_clean//g for keys %publication; |
917 |
$publication{'date'} =~ s/[\D-]//g; |
918 |
|
919 |
my $i = $#authors; |
920 |
my $last = 0; |
921 |
my $seclast = 0; |
922 |
for my $author (@authors) { |
923 |
$cites{'Harvard'} .= $author->{'surname'} . ' '; |
924 |
$cites{'Harvard'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; |
925 |
$cites{'Harvard'} =~ s/\s+$//; |
926 |
$cites{'Harvard'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
927 |
$cites{'Chicago'} .= $author->{'surname'} . ' '; |
928 |
$cites{'Chicago'} .= $_ . ' ' for @{$author->{'forenames'}}; |
929 |
$cites{'Chicago'} =~ s/\s+$//; |
930 |
$cites{'Chicago'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
931 |
$cites{'MLA'} .= $author->{'surname'} . ' '; |
932 |
$cites{'MLA'} .= $_ . ' ' for @{$author->{'forenames'}}; |
933 |
$cites{'MLA'} =~ s/\s+$//; |
934 |
$cites{'MLA'} .= $last ? '' : ($seclast ? ' and ' : ', '); |
935 |
$cites{'APA'} .= $author->{'surname'} . ' '; |
936 |
$cites{'APA'} .= substr($_, 0, 1) . '. ' for @{$author->{'forenames'}}; |
937 |
$cites{'APA'} =~ s/\s+$//; |
938 |
$cites{'APA'} .= $last ? '' : ($seclast ? ' & ' : ', '); |
939 |
$seclast = $#authors > 1 && $i-- == 2; |
940 |
$last = $i == 0; |
941 |
} |
942 |
$cites{$_} =~ s/([^\.])$/$1./ for keys %cites; |
943 |
|
944 |
$cites{'Harvard'} .= ' (' . $publication{'date'} . '). '; |
945 |
$cites{'Chicago'} .= ' ' . $publication{'date'} . '. '; |
946 |
$cites{'MLA'} .= ' ' . $publication{'title'} . '. '; |
947 |
$cites{'APA'} .= ' (' . $publication{'date'} . '). '; |
948 |
$cites{'Harvard'} .= $publication{'title'} . '. '; |
949 |
$cites{'Chicago'} .= $publication{'title'} . '. '; |
950 |
$cites{'MLA'} .= $publication{'place'} . ': '; |
951 |
$cites{'APA'} .= $publication{'title'} . '. '; |
952 |
$cites{'Harvard'} .= $publication{'place'} . ': '; |
953 |
$cites{'Chicago'} .= $publication{'place'} . ': '; |
954 |
$cites{'MLA'} .= $publication{'publisher'} . '. '; |
955 |
$cites{'APA'} .= $publication{'place'} . ': '; |
956 |
$cites{'Harvard'} .= $publication{'publisher'}; |
957 |
$cites{'Chicago'} .= $publication{'publisher'}; |
958 |
$cites{'MLA'} .= $publication{'date'}; |
959 |
$cites{'APA'} .= $publication{'publisher'}; |
960 |
$cites{$_} =~ s/ +/ / for keys %cites; |
961 |
$cites{$_} =~ s/([^\.])$/$1./ for keys %cites; |
962 |
|
963 |
return \%cites; |
964 |
} |
965 |
|
858 |
|
966 |
|
859 |
=head1 INTERNAL FUNCTIONS |
967 |
=head1 INTERNAL FUNCTIONS |
860 |
|
968 |
|