-
Notifications
You must be signed in to change notification settings - Fork 23
Bibliography Details
codeZeilen edited this page Jun 30, 2015
·
2 revisions
IF YOU DO WANT TO ADD YOUR PUBLICATION TO THE SITE, EDIT THE REFERENCES.BIB!
This page is for documentation purposes only, in case we need to redo any work with the raw data. The original references.bib was generated from a mendeley group and transformed using the following scripts:
import re
import sys
author_line_re = re.compile("author = \{")
file_line_re = re.compile("file = \{")
authors_re = re.compile("((?!,)(?!\{)\S+),((?:\s*(?!and)\S+)+)")
def is_author_line(line):
return len(author_line_re.findall(line)) > 0
def sanitize_line(line):
if is_author_line(line):
return sanitize_authors(line)
else:
return line
def sanitize_authors(authors_line):
authors_line = authors_line[:-3]
r = authors_re.findall(authors_line)
r = map(lambda e: map(str.strip, e), r)
return "author = {" \
+ reduce(lambda result,item: result + " and " + item[1] + " " + item[0], r[1:], r[0][1] + " " + r[0][0]) \
+ "},\n"
def no_file_line(line):
return file_line_re.match(line) == None
result_bib = ""
with open(sys.argv[1]) as f:
regex = re.compile("(\w+),((?:\s*(?!and)\w+)+)")
lines = f.readlines() # Assumes author is on a separate line
lines = filter(no_file_line, lines)
result_bib = "".join(map(sanitize_line, lines))
with open(sys.argv[2], "w") as f:
f.write(result_bib)
import re
import sys
title_line_re = re.compile("^\s*title = \{(.+)\}")
def is_title_line(line):
return len(title_line_re.findall(line)) > 0
def sanitize_line(line):
if is_title_line(line):
return capitalize_title(line)
else:
return line
def capitalize_title(title_line):
title = title_line_re.findall(title_line)[0]
title_elements = title.split()
return "title = {" \
+ " ".join(map(captialize_title_word, title_elements)) \
+ "},\n"
def captialize_title_word(word):
small_words = ("in", "to", "of", "with", "on", "order", "for", "through", "and", "or", "that")
if not (word in small_words):
return word.title()
else:
return word[0].lower()+word[1:]
result_bib = ""
with open(sys.argv[1]) as f:
regex = re.compile("(\w+),((?:\s*(?!and)\w+)+)")
lines = f.readlines() # Assumes title is on a separate line
result_bib = "".join(map(sanitize_line, lines))
with open(sys.argv[2], "w") as f:
f.write(result_bib)