本文整理汇总了Python中bibtexparser.bibdatabase.BibDatabase.load_common_strings方法的典型用法代码示例。如果您正苦于以下问题:Python BibDatabase.load_common_strings方法的具体用法?Python BibDatabase.load_common_strings怎么用?Python BibDatabase.load_common_strings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bibtexparser.bibdatabase.BibDatabase
的用法示例。
在下文中一共展示了BibDatabase.load_common_strings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write_common_strings
# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import load_common_strings [as 别名]
def test_write_common_strings(self):
bib_database = BibDatabase()
bib_database.load_common_strings()
writer = BibTexWriter(write_common_strings=True)
result = bibtexparser.dumps(bib_database, writer=writer)
with io.open('bibtexparser/tests/data/common_strings.bib') as f:
expected = f.read()
self.assertEqual(result, expected)
示例2: BibTexParser
# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import load_common_strings [as 别名]
class BibTexParser(object):
"""
A parser for reading BibTeX bibliographic data files.
Example::
from bibtexparser.bparser import BibTexParser
bibtex_str = ...
parser = BibTexParser()
parser.ignore_nonstandard_types = False
parser.homogenize_fields = False
parser.common_strings = False
bib_database = bibtexparser.loads(bibtex_str, parser)
"""
def __new__(cls, data=None, **args):
"""
To catch the old API structure in which creating the parser would
immediately parse and return data.
"""
if data is None:
return super(BibTexParser, cls).__new__(cls)
else:
# For backwards compatibility: if data is given, parse
# and return the `BibDatabase` object instead of the parser.
return parse(data, **args)
def __init__(self, data=None,
customization=None,
ignore_nonstandard_types=True,
homogenize_fields=False,
common_strings=False):
"""
Creates a parser for rading BibTeX files
:return: parser
:rtype: `BibTexParser`
"""
self.bib_database = BibDatabase()
#: Load common strings such as months abbreviation
#: Default: `False`.
self.common_strings = common_strings
if self.common_strings:
self.bib_database.load_common_strings()
#: Callback function to process BibTeX entries after parsing,
#: for example to create a list from a string with multiple values.
#: By default all BibTeX values are treated as simple strings.
#: Default: `None`.
self.customization = customization
#: Ignore non-standard BibTeX types (`book`, `article`, etc).
#: Default: `True`.
self.ignore_nonstandard_types = ignore_nonstandard_types
#: Sanitize BibTeX field names, for example change `url` to `link` etc.
#: Field names are always converted to lowercase names.
#: Default: `False`.
self.homogenize_fields = homogenize_fields
# On some sample data files, the character encoding detection simply
# hangs We are going to default to utf8, and mandate it.
self.encoding = 'utf8'
# pre-defined set of key changes
self.alt_dict = {
'keyw': u'keyword',
'keywords': u'keyword',
'authors': u'author',
'editors': u'editor',
'url': u'link',
'urls': u'link',
'links': u'link',
'subjects': u'subject'
}
# Setup the parser expression
self._init_expressions()
def parse(self, bibtex_str, partial=False):
"""Parse a BibTeX string into an object
:param bibtex_str: BibTeX string
:type: str or unicode
:param partial: If True, print errors only on parsing failures.
If False, an exception is raised.
:type: boolean
:return: bibliographic database
:rtype: BibDatabase
"""
bibtex_file_obj = self._bibtex_file_obj(bibtex_str)
try:
self._expr.parseFile(bibtex_file_obj)
except self._expr.ParseException as exc:
logger.error("Could not parse properly, starting at %s", exc.line)
#.........这里部分代码省略.........
示例3: test_ignore_common_strings_only_if_not_overloaded
# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import load_common_strings [as 别名]
def test_ignore_common_strings_only_if_not_overloaded(self):
bib_database = BibDatabase()
bib_database.load_common_strings()
bib_database.strings['jan'] = 'Janvier'
result = bibtexparser.dumps(bib_database)
self.assertEqual(result, '@string{jan = {Janvier}}\n\n')
示例4: test_ignore_common_strings
# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import load_common_strings [as 别名]
def test_ignore_common_strings(self):
bib_database = BibDatabase()
bib_database.load_common_strings()
result = bibtexparser.dumps(bib_database)
self.assertEqual(result, '')