#!/usr/local/bin/perl # log2bib2: Converts ISI bibliographic database (www.bids.ac.uk) # format to BibTeX format # Copyright (C) 2000 Ramin Nakisa # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $/ = ""; $* = 1; $FieldDelimiter = '^\s*([A-Z]{2})-\s'; @ClosedClass = ('an','and','of','in','for','a','the'); sub capitalise { local( $inputstring ) = @_; local( $string ); local( $ThisIsClosedClass ); $inputstring =~ tr/A-Z/a-z/; for ( $i = 0; $i < length( $inputstring ); $i++ ) { # if ( substr( $inputstring, $i ) =~ /^\W(\w+)\W/ ) if ( substr( $inputstring, $i ) =~ /^\W(\w+)/ ) { $ThisIsClosedClass = 0; foreach $string (@ClosedClass) { if ( $1 eq $string ) { $ThisIsClosedClass = 1; } } if ( $ThisIsClosedClass ) { substr( $inputstring, $i+1, 1 ) =~ tr/A-Z/a-z/; } else { substr( $inputstring, $i+1, 1 ) =~ tr/a-z/A-Z/; } } } $i = 0; substr( $inputstring, $i, 1 ) =~ tr/a-z/A-Z/; return( $inputstring ); } sub parseauthors { local( $authorstring ) = @_; local( $surname ); local( $initials ); local( $i ); local( $outputstring ); local( @author ) = split( /;/, $authorstring ); for ( $i = 0; $i < scalar( @author ); $i++ ) { ( $surname, $initials ) = split( /,\s*/, $author[$i] ); $surname =~ s/\s*$//g; $surname =~ tr/A-Z/a-z/; substr( $surname, 0, 1 ) =~ tr/a-z/A-Z/; $initials =~ s/\s*$//g; $initials =~ s/(.)/$1./g; # print "surname : $surname\n"; # print "initials: $initials\n"; $outputstring .= $surname . ", " . $initials; if ( $i != scalar( @author ) - 1 ) { $outputstring .= " and "; } } return( $outputstring ); } sub createauthoryearkey { local( $authorstring, $year ) = @_; local( @author ) = split( /;/, $authorstring ); local( $surname, $initials ) = split( /,\s*/, $author[0] ); $surname =~ s/\s*$//g; $initials =~ s/\s*$//g; $initials =~ s/(.)/$1./g; local( $key ) = $surname; local( $endofyear ) = substr( $year, 2, 2 ); $key .= $endofyear; return( $key ); } sub bibtexformat { local( $title, $authors, $journal, $year, $volume, $number, $pages, $notes ) = @_; local( $qtitle, $qauthors, $qjournal, $qyear, $qvolume, $qnumber, $qpages, $qnotes ); $key = &createauthoryearkey( $authors, $year ); $qtitle = "\"" . &capitalise( $title ) . "\","; $qauthors = "\"" . &parseauthors( $authors ) . "\","; $qjournal = "\"" . &capitalise( $journal ) . "\","; $qyear = "\"" . $year . "\","; $qvolume = "\"" . $volume . "\","; $qnumber = "\"" . $number . "\","; $qpages = "\"" . $pages . "\","; $qpages =~ s/-/--/; $notes =~ s/\"/\'/g; $notes =~ s/\&/and/g; $qnotes = "\"" . $notes . "\""; print "\@Article{", $key, ",\n"; format STDOUT = author = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $qauthors ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qauthors; title = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $qtitle ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qtitle; journal = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qjournal year = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qyear volume = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qvolume number = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qnumber pages = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qpages notes = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $qnotes; ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~ $qnotes; . write; print "}\n\n"; } # perl -pe 's/\cM//g;s/\cH//g;s/\c[[\[\d\;HJK]{1,6}//g;' MMN.raw > MMN2.raw open( TEMP, ">/tmp/temp.txt" ); while ( <> ) { s/\cM//g; s/\cH//g; s/\c[[\[\d\;HJK]{1,6}//g; print TEMP $_; } open( TEMP, "/tmp/temp.txt" ); while ( ) { s/\cM//g; s/\cH//g; s/\c[[\[\d\;HJK]{1,6}//g; s/\*\*\*\* End of Data \*\*\*\*//; s/Press RETURN to continue//; @Fields = split( /^\s*([A-Z]{2})-\s/ ); if ( scalar( @Fields ) <= 1 ) { next; } $abstract = ""; for ( $i = 1; $i < scalar( @Fields ); $i += 2 ) { $Fields[$i+1] =~ s/-\n/\n/g; $Fields[$i+1] =~ s/\s*\n\s*/ /g; $Fields[$i+1] =~ s/\s*$//g; if ( $Fields[$i] =~ /TI/ ) { $title = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /AU/ ) { $authors = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /NA/ ) { $address = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /JN/ ) { $journal = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /PY/ ) { $year = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /VO/ ) { $volume = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /NO/ ) { $number = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /PG/ ) { $pages = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /IS/ ) { $strangenumber = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /AB/ ) { $abstract = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /CR/ ) { $references = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /KP/ ) { $keywordsplus = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /WA/ ) { $keywords = $Fields[$i+1]; } elsif ( $Fields[$i] =~ /DT/ ) { $documenttype = $Fields[$i+1]; } } # print "Title : ", &capitalise( $title ), "\n"; # print "Authors : $authors\n"; # print "Address : $address\n"; # print "Journal : ", &capitalise( $journal), "\n"; # print "Year : $year\n"; # print "Volume : $volume\n"; # print "Number : $number\n"; # print "Pages : $pages\n"; # print "Abstract : $abstract\n"; # print "References : $references\n"; # print "Keywords : $keywords\n"; # print "Keywords+ : $keywordsplus\n"; # print "Document type : $documenttype\n"; &bibtexformat( $title, $authors, $journal, $year, $volume, $number, $pages, $abstract ); # print "----------------------------------------------\n\n"; }