本文整理汇总了Python中bibtexparser.bwriter.BibTexWriter.comma_first方法的典型用法代码示例。如果您正苦于以下问题:Python BibTexWriter.comma_first方法的具体用法?Python BibTexWriter.comma_first怎么用?Python BibTexWriter.comma_first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bibtexparser.bwriter.BibTexWriter
的用法示例。
在下文中一共展示了BibTexWriter.comma_first方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comma_first
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import comma_first [as 别名]
def test_comma_first(self):
with io.open(_data_path('book.bib'), 'r') as bibfile:
bib = BibTexParser(bibfile.read())
with io.open(_data_path('book_comma_first.bib'), 'r') as bibfile:
expected = bibfile.read()
writer = BibTexWriter()
writer.indent = ' '
writer.comma_first = True
result = writer.write(bib)
self.maxDiff = None
self.assertEqual(expected, result)
示例2: test_comma_first_and_trailing_comma
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import comma_first [as 别名]
def test_comma_first_and_trailing_comma(self):
with io.open(_data_path('article.bib'), 'r') as bibfile:
bib = BibTexParser(bibfile.read())
with io.open(_data_path('article_comma_first_and_trailing_comma_output.bib'), 'r') as bibfile:
expected = bibfile.read()
writer = BibTexWriter()
writer.add_trailing_comma = True
writer.comma_first = True
result = writer.write(bib)
self.maxDiff = None
self.assertEqual(expected, result)
示例3: toString
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import comma_first [as 别名]
def toString(e):
writer = BibTexWriter()
writer.indent = ' ' # indent entries with 4 spaces instead of one
writer.comma_first = True # place the comma at the beginning of the line
return writer._entry_to_bibtex(e)
示例4: formatText
# 需要导入模块: from bibtexparser.bwriter import BibTexWriter [as 别名]
# 或者: from bibtexparser.bwriter.BibTexWriter import comma_first [as 别名]
def formatText(self):
if self.BibtexfilePath != '':
self.openfile()
else:
self.readcontent()
m = self.getMap()
m['IEEE Global Communications Conference'] = m['IEEE Global Communications Conference, incorporating the Global Internet Symposium']
del m['IEEE Global Communications Conference, incorporating the Global Internet Symposium']
print m
length = 0
nb = {}
for bibtex in self.allbibtex:
for key in bibtex.keys():
if len(key) > length and key != 'ENTRYTYPE':
length = len(key)
for k, v in bibtex.items():
if k == 'ENTRYTYPE' or k == 'ID':
nb[k] = v
continue
elif k == 'ID':
nb[k] = v
continue
elif k == 'doi' or k == 'ISSN' or k == 'keywords':
continue
elif v == '':
continue
elif 'url' in k:
continue
nk = k + (length - len(k)) * ' '
if 'booktitle' in nk:
if '(' in v:
v1 = v.split('(')[1].split(')')[0]
nb[nk] = 'Proc. of ' + v1
continue
flag = 0 # 未更改booktitle
to_remove = "~`[email protected]#$%^&*(){}[];':<>|-=_+"
table = {ord(char): None for char in to_remove}
clean_v = v.translate(table)
#clean_v = v.translate(string.punctuation)
#print clean_v
for kk, vv in m.items():
if kk in clean_v:
nb[nk] = 'Proc. of ' + vv[0]
publish = 'publish' + (length - 7) * ' '
nb[publish] = vv[1]
flag = 1
break
if flag == 0:
nb[nk] = v
print v
continue
elif nk.strip() == 'title' and 'booktitle' not in nk:
self.tilte = v
nv = v.split(' ')
for i in range(len(nv)):
# 标题除介词和冠词外,首字母大写
if nv[i] in self.prep or nv[i] in self.artie:
continue
# 首字母大写
else:
if 97 <= ord(nv[i][0]) <= 122:
nv[i] = chr(ord(nv[i][0])-32)+nv[i][1:]
v = ' '.join(nv)
nb[nk] = '{' + v + '}'
continue
elif 'pages' in nk:
if '--' in v:
nb[nk] = v
continue
nb[nk] = v.replace('-', '--')
continue
elif 'author' in nk:
if '\n' in v:
nb[nk] = v.replace('\n', ' ')
continue
# 其他不做改变
nb[nk] = v
db = BibDatabase()
db.entries = [nb]
writer = BibTexWriter()
writer.indent = '\t' # indent entries with 4 spaces instead of one
writer.comma_first = False # place the comma at the beginning of the line
with open(self.tilte+'.bib', 'wb') as bibfile:
bibfile.write(writer.write(db))