Advertisement
amc

Abbreviated journal names in Mendeley

amc
Feb 9th, 2012
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.09 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. #######################################################
  6. # generate a list of abbreviated journal names
  7. # based on your Mendeley library .bib file(s)
  8. #
  9. # created
  10. # [2012-02-09]  Alex M. Chubaty (alex.chubaty@gmail.com)
  11. #               Charles Stevens
  12. # updated
  13. # [2013-02-27]  Filipe G. Vieira
  14. #######################################################
  15.  
  16. # usage: masterlist.txt *.bib
  17. if($#ARGV <= 0) {
  18.     print("ERROR: No files provided!\nUsage:\n\t./script.pl master_abb.txt lib1.bib lib2.bib ... libN.bib\n");
  19.     exit(1);
  20. }
  21.  
  22. my $master_abbrev = shift(@ARGV);
  23.  
  24. # read all files and store them
  25. my @allJournals;
  26. while(<>){
  27.     my $line = substr($_, 0, 7);
  28.     if ($line eq 'journal') {
  29.     chomp;
  30.     $_ = substr($_, 11, -2);
  31.     push(@allJournals, $_);
  32.     }
  33. }
  34.  
  35. # remove duplicate journal entries and sort alphabetically
  36. @allJournals = sort { $a cmp $b } unique(@allJournals);
  37.  
  38. # Create journal abbrev directory (LINUX only)
  39. unless ( -e $ENV{"HOME"}.'/.local/share/data/Mendeley Ltd./Mendeley Desktop/journalAbbreviations') {
  40.     mkdir($ENV{"HOME"}.'/.local/share/data/Mendeley Ltd./Mendeley Desktop/journalAbbreviations') or die "$!";
  41. }
  42. open (OUTFILE, ">".$ENV{"HOME"}.'/.local/share/data/Mendeley Ltd./Mendeley Desktop/journalAbbreviations/default.txt') || die "$!";
  43.  
  44. # read in the master list of journals
  45. #   (this was taken from the ISI journal list at:
  46. #   http://images.webofknowledge.com/WOK46/help/WOS/A_abrvjt.html
  47. #   accessed Feb 8, 2012)
  48. open (INFILE, "<".$master_abbrev) || die "$!";
  49. while (<INFILE>) {
  50.     chomp;
  51.     my ($jfull, $jabbrev) = split("\t", $_);
  52.  
  53.     foreach my $jtitle (@allJournals) {
  54.         if (lc($jtitle) eq lc($jfull)) {
  55.         print(OUTFILE $jtitle, "\t", title_case($jabbrev), "\n");
  56.         }
  57.     }
  58. }
  59. close(INFILE);
  60. close(OUTFILE);
  61. exit(0);
  62.  
  63.  
  64.  
  65. # subroutines
  66. sub title_case {
  67.     my @title;
  68.  
  69.     foreach my $word (split(/ /,shift)) {
  70.     $word = lc($word);
  71.  
  72.     if($word eq '&') {
  73.         $word = '\&';
  74.     } elsif(
  75.         $word eq 'i' ||
  76.         $word eq 'ii' ||
  77.         $word eq 'iii' ||
  78.         $word eq 'iv' ||
  79.         $word eq 'v' ||
  80.         $word eq 'vi' ||
  81.         $word eq 'vii' ||
  82.         $word eq 'viii' ||
  83.         $word eq 'ix' ||
  84.         $word eq 'x' ||
  85.         $word eq 'xi' ||
  86.         $word eq 'xii' ||
  87.         $word eq 'xiii' ||
  88.         $word eq 'xiv' ||
  89.         $word eq 'xv' ||
  90.         $word eq 'xvi' ||
  91.         $word eq 'xvii' ||
  92.         $word eq 'xviii' ||
  93.         $word eq 'xix' ||
  94.         $word eq 'xx' ||
  95.         $word eq 'xxi' ||
  96.         $word eq 'xxii' ||
  97.         $word eq 'xxiii' ||
  98.         $word eq 'xxiv' ||
  99.         $word eq 'xxv' ||
  100.         $word eq 'xxvi' ||
  101.         $word eq 'xxvii' ||
  102.         $word eq 'xxviii' ||
  103.         $word eq 'xxix' ||
  104.         $word eq 'xxx' ||
  105.         $word eq 'ieee' ||
  106.         $word eq 'bmc'
  107.         ) {
  108.         $word = uc($word);
  109.     } elsif (
  110.         $word eq 'and' ||
  111.         $word eq 'in' ||
  112.         $word eq 'of' ||
  113.         $word eq 'on' ||
  114.         $word eq 'the' ||
  115.         $word eq 'to'
  116.         ) {
  117.         $word = lc($word);
  118.     } else {
  119.         $word =~ s/(\w+)/\u\L$1/g;
  120.     }
  121.     push(@title,$word);
  122.     }
  123.     return join(" ", @title);
  124. }
  125.  
  126. sub unique {
  127.     return keys %{{ map { $_ => 1 } @_ }};
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement