本文整理汇总了Python中bibtexparser.bwriter.BibTexWriter.order_entries_by方法的典型用法代码示例。如果您正苦于以下问题:Python BibTexWriter.order_entries_by方法的具体用法?Python BibTexWriter.order_entries_by怎么用?Python BibTexWriter.order_entries_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bibtexparser.bwriter.BibTexWriter
的用法示例。
在下文中一共展示了BibTexWriter.order_entries_by方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sort_missing_field
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
def test_sort_missing_field(self):
bib_database = BibDatabase()
bib_database.entries = [{'ID': 'b',
'ENTRYTYPE': 'article',
'year': '2000'},
{'ID': 'c',
'ENTRYTYPE': 'book',
'year': '2010'},
{'ID': 'a',
'ENTRYTYPE': 'book'}]
writer = BibTexWriter()
writer.order_entries_by = ('year', )
result = bibtexparser.dumps(bib_database, writer)
expected = "@book{a\n}\n\[email protected]{b,\n year = {2000}\n}\n\[email protected]{c,\n year = {2010}\n}\n\n"
self.assertEqual(result, expected)
示例2: _cleanupBibTex
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
def _cleanupBibTex(self, count):
""" Clean up bibtex and ensure uniform look. """
import bibtexparser
from bibtexparser.bparser import BibTexParser
parser = BibTexParser()
parser.customization = homogeneize_latex_encoding
bib = bibtexparser.loads(self.refs, parser=parser)
# save results
from bibtexparser.bwriter import BibTexWriter
writer = BibTexWriter()
writer.contents = ['entries']
writer.indent = ' '
writer.order_entries_by = ('id')
self.number = len(bib.entries)
self.refs = bibtexparser.dumps(bib, writer)
示例3: write_bib
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
def write_bib(db, order=False):
"""
Write bibtex string.
Args:
db (BibDatabase): database object to dump..
order (bool): whether to reorder entries upon writing.
Returns:
The dumped string.
"""
# Custom writer
writer = BibTexWriter()
writer.indent = '\t'
writer.order_entries_by = None
# Replace month by numeric value
for entry in db.entries:
if 'month' in entry and entry['month'] in MONTHS:
entry['month'] = '{:02d}'.format(MONTHS.index(entry['month']) + 1)
if order:
# Manual sort
order_entries_by = ('year', 'author', 'ID')
sort_entries(db, order_entries_by)
if not config.use_utf8_characters:
db.entries = [nomenclature.encode_ascii_latex(entry) for entry in db.entries]
if config.protect_uppercase:
for entry in db.entries:
entry["title"] = latex.protect_uppercase(entry["title"])
# Write bib string
return writer.write(db)
示例4: test_sort_type_id
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
def test_sort_type_id(self):
writer = BibTexWriter()
writer.order_entries_by = ('ENTRYTYPE', 'ID')
result = bibtexparser.dumps(self.bib_database, writer)
expected = "@article{b\n}\n\[email protected]{a\n}\n\[email protected]{c\n}\n\n"
self.assertEqual(result, expected)
示例5: test_sort_none
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
def test_sort_none(self):
writer = BibTexWriter()
writer.order_entries_by = None
result = bibtexparser.dumps(self.bib_database, writer)
expected = "@article{b\n}\n\[email protected]{c\n}\n\[email protected]{a\n}\n\n"
self.assertEqual(result, expected)
示例6: BibTexWriter
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
},
},
'loggers': {
'': {
'handlers': ['default'],
'level': 'ERROR',
'formatter': 'standard',
'propagate': True
}
}
})
writer = BibTexWriter()
writer.contents = ['comments', 'entries']
writer.indent = ' '
writer.order_entries_by = ('ENTRYTYPE', 'author', 'year')
def create_id(t, year, title):
return str(t) + "_" + str(year) + "_" + str(space_to_underscore(title))
def pdf(pdf_files, shared_pdf, bibtex_folder, bibtex_files, gscholar):
for pdf in pdf_files:
txt = re.sub("\W", " ", gs.convert_pdf_to_txt(pdf)).lower()
#Research determined that the cutting of 35 words gives the
#highest accuracy
words = txt.strip().split()[:35]
words = " ".join(words)
print words
if gscholar == True:
bib = load(gs.pdflookup(pdf, all, gs.FORMAT_BIBTEX)[0])
keys = bib.entries[0].keys()
示例7: len
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import order_entries_by [as 别名]
bib_database = bibtexparser.load(bibtex_file, parser=parser)
if bib_database :
now = datetime.datetime.now()
success = "{0} Loaded {1} found {2} entries".format(now, input_b, len(bib_database.entries))
print(success)
else :
now = datetime.datetime.now()
errs = "{0} Failed to read {1}".format(now, input_b)
print(errs)
sys.exit(errs)
bibtex_str = None
if bib_database:
writer = BibTexWriter()
writer.order_entries_by = ('author', 'year', 'type')
bibtex_str = bibtexparser.dumps(bib_database, writer)
#print(str(bibtex_str))
with open(output_b, "w") as text_file:
#print >> text_file, bibtex_str
print(bibtex_str, file=text_file)
if bibtex_str:
now = datetime.datetime.now()
success = "{0} Wrote to {1} with len {2}".format(now, output_b, len(bibtex_str))
print(success)
else:
now = datetime.datetime.now()
errs = "{0} Failed to write {1}".format(now, output_b)
print(errs)
sys.exit(errs)