Forked from peci1/Abbreviate Journal Names in Bibtex Database.py
Last active
September 25, 2017 06:11
-
-
Save yoavram/888dee944346f3a26d22fd328db3c868 to your computer and use it in GitHub Desktop.
Revisions
-
Yoav Ram revised this gist
Sep 25, 2017 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,15 @@ import sys, os import re try: bibtexdb = open(sys.argv[1]).read() except IndexError: print("Error: specify the file to be processed!") exit() if not os.path.isfile('journalList.txt'): import urllib.request urllib.request.urlretrieve("https://raw.githubusercontent.com/JabRef/jabref/master/src/main/resources/journals/journalList.txt", filename="journalList.txt") rulesfile = open('journalList.txt') -
Yoav Ram revised this gist
Sep 25, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,8 +20,8 @@ repl = re.compile(re.escape(pattern1), re.IGNORECASE) ## this is more robust, although ca. 10x slower (bibtexdb, num_subs) = repl.subn(pattern2, bibtexdb) if num_subs > 0: print("Replacing '%s' FOR '%s'" % (pattern1, pattern2)) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print("Bibtex database with abbreviated files saved into 'abbreviated.bib'") -
peci1 revised this gist
May 10, 2016 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ #-*- coding: utf-8 -*- import sys, os import re try: bibtexdb = open(sys.argv[1]).read() except: print "Error: specify the file to be processed!" @@ -15,10 +16,12 @@ for rule in rulesfile.readlines()[::-1]: ## reversed alphabetical order matches extended journal names first pattern1, pattern2 = rule.strip().split(" = ") if pattern1 != pattern1.upper() and (' ' in pattern1): ## avoid mere abbreviations #bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) ## problem - this is case sensitive repl = re.compile(re.escape(pattern1), re.IGNORECASE) ## this is more robust, although ca. 10x slower (bibtexdb, num_subs) = repl.subn(pattern2, bibtexdb) if num_subs > 0: print "Replacing '%s' FOR '%s'" % (pattern1, pattern2) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print "Bibtex database with abbreviated files saved into 'abbreviated.bib'" -
FilipDominec revised this gist
Apr 26, 2016 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,8 +14,11 @@ for rule in rulesfile.readlines()[::-1]: ## reversed alphabetical order matches extended journal names first pattern1, pattern2 = rule.strip().split(" = ") if pattern1 != pattern1.upper() and (' ' in pattern1): ## avoid mere abbreviations print "Replacing '%s' FOR '%s'" % (pattern1, pattern2) #bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) ## problem - this is case sensitive repl = re.compile(re.escape(pattern1), re.IGNORECASE) ## this is more robust, although ca. 10x slower bibtexdb = repl.sub(pattern2, bibtexdb) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print "Bibtex database with abbreviated files saved into 'abbreviated.bib'" -
FilipDominec revised this gist
Apr 7, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,4 +18,4 @@ bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print "Bibtex database with abbreviated files saved into 'abbreviated.bib'" -
FilipDominec revised this gist
Apr 7, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,4 +18,4 @@ bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print "Bibtex database with abbreviated files aved into abbreviated.bib" -
FilipDominec revised this gist
Apr 7, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,5 +17,5 @@ print "Replacing '%s' FOR '%s'" % (pattern1, pattern2) bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexdb) print "Bibtex database with abbreviated files aved into abbreviated.bib -
FilipDominec created this gist
Apr 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ #!/usr/bin/env python #-*- coding: utf-8 -*- import sys, os try: bibtexdb = open(sys.argv[1]).read() except: print "Error: specify the file to be processed!" if not os.path.isfile('journalList.txt'): import urllib urllib.urlretrieve("https://raw.githubusercontent.com/JabRef/jabref/master/src/main/resources/journals/journalList.txt", filename="journalList.txt") rulesfile = open('journalList.txt') for rule in rulesfile.readlines()[::-1]: ## reversed alphabetical order matches extended journal names first pattern1, pattern2 = rule.strip().split(" = ") print "Replacing '%s' FOR '%s'" % (pattern1, pattern2) bibtexdb = bibtexdb.replace(pattern1.strip(), pattern2.strip()) with open('abbreviated.bib', 'w') as outfile: outfile.write(bibtexfile) print "Bibtex database with abbreviated files aved into abbreviated.bib