-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized into a module with separate scripts.
- Loading branch information
1 parent
c7b6476
commit f05e0ed
Showing
8 changed files
with
225 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*__pycache__/ | ||
prereqs.txt | ||
tags |
Empty file.
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#/usr/env python | ||
|
||
import cProfile | ||
import pstats | ||
import searchRefs | ||
import pyximport | ||
pyximport.install() | ||
import searchRefs_cython | ||
import sys | ||
|
||
# Command line arguments | ||
input_string = ['field:keywords', 'review'] | ||
terms = ['title'] | ||
|
||
# Setup objects | ||
bibliography = searchRefs.Bibliography(searchRefs.BIB_DIRECTORY) | ||
bibliography_cython = searchRefs_cython.Bibliography(searchRefs_cython.BIB_DIRECTORY) | ||
search_string = searchRefs.SearchString(input_string) | ||
search_string_cython = searchRefs_cython.SearchString(input_string) | ||
command_string = 'bibliography.match_and_print_fields(search_string, terms)' | ||
command_string_cython = 'bibliography_cython.match_and_print_fields(search_string_cython, terms)' | ||
|
||
# Profile | ||
profile_file = 'python_profile.stats' | ||
profile_file_cython = 'cython_profile.stats' | ||
output_dump = '/tmp/searcRefs.txt' | ||
sys.stdout = open(output_dump, 'w') | ||
cProfile.run(command_string, profile_file) | ||
cProfile.run(command_string_cython, profile_file_cython) | ||
|
||
# Customize and write statistics | ||
stats_output = 'python_profile.txt' | ||
sys.stdout = open(stats_output, 'w') | ||
python_profile_stats = pstats.Stats(profile_file) | ||
python_profile_stats.strip_dirs() | ||
python_profile_stats.sort_stats('cumtime') | ||
python_profile_stats.print_stats() |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python3 | ||
|
||
"""Parse bib files and output in standard format; warn if missing information""" | ||
|
||
# For now assumes bib file is article | ||
|
||
import argparse | ||
|
||
|
||
FIELDS = ['title', 'author', 'journal', 'volume', 'number', 'pages', 'year', 'issn', 'doi', 'url', 'abstract'] | ||
|
||
|
||
def find_entry(line, field_dic): | ||
field_entry = line.split('=') | ||
field = field_entry[0].split()[0].lower() | ||
if field in FIELDS: | ||
entry = field_entry[1] | ||
while entry[0] in [' ', '{', '"']: | ||
entry = entry[1:] | ||
|
||
while entry[-1] in [' ', '}', '"', ',', '\n']: | ||
entry = entry[:-1] | ||
|
||
field_dic[field] = entry | ||
|
||
return field_dic | ||
|
||
|
||
def output_standard_bib(filebase, field_dic): | ||
print('@article{{{},'.format(filebase)) | ||
for field, entry in field_dic.items(): | ||
print(' {} = {{{}}},'.format(field, entry)) | ||
|
||
print(' keywords = {},') | ||
print(' annote = {}') | ||
print('}') | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filebase', help='Filebase of bib file') | ||
args = parser.parse_args() | ||
filebase = args.filebase | ||
|
||
filename = filebase + '.bib' | ||
|
||
|
||
with open(filename) as inp: | ||
lines = inp.readlines() | ||
|
||
field_dic = {} | ||
for line in lines[1:]: | ||
if line == '\n': | ||
continue | ||
else: | ||
field_dic = find_entry(line, field_dic) | ||
|
||
#modify field contents (capitilization, brackets, etc.) | ||
output_standard_bib(filebase, field_dic) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/env python | ||
|
||
#import pyximport | ||
#pyximport.install() | ||
|
||
from searchRefs_cython import * | ||
|
||
def main(): | ||
argument_parser = argparse.ArgumentParser() | ||
argument_parser.add_argument('-s', type=str, nargs='+', dest='search_string', help='Search string') | ||
argument_parser.add_argument('-t', type=str, nargs='+', dest='terms', help='Terms to print') | ||
arguments = argument_parser.parse_args() | ||
|
||
bibliography = Bibliography(BIB_DIRECTORY) | ||
search_string = SearchString(arguments.search_string) | ||
bibliography.match_and_print_fields(search_string, arguments.terms) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import glob | ||
from setuptools import setup | ||
|
||
setup( | ||
name='mybiblib', | ||
packages=['mybiblib'], | ||
scripts=glob.glob('scripts/*.py') | ||
) |
File renamed without changes.