2011年3月3日 星期四

[python]pybtex example


之前想解析bitext 找了找一些作法找到python example
 
Pybtex!
http://pybtex.sourceforge.net/

from pybtex.database.input import bibtex
from operator import itemgetter, attrgetter
import pprint
parser = bibtex.Parser()
bib_data = parser.parse_file('ref.bib')

def sort_by_year(y, x):
return int(x[1].fields['year']) - int(y[1].fields['year'])

bib_sorted = sorted(bib_data.entries.items(), cmp=sort_by_year)

for key, value in bib_sorted:
print key
print value.fields['year']
print value.fields['author']
print value.fields['title']

peicheng@PCsNB ~/project/python/pybitex $ python bitex.py
wu1992fast
1992
Wu, S. and Manber, U.
{Fast text searching: allowing errors}
peicheng@PCsNB ~/project/python/pybitex $ cat ref.bib
@article{wu1992fast,
title={{Fast text searching: allowing errors}},
author={Wu, S. and Manber, U.},
journal={Communications of the ACM},
volume={35},
number={10},
pages={83--91},
issn={0001-0782},
year={1992},
publisher={ACM}
}


  
 


沒有留言:

張貼留言