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