当前位置: 首页>>代码示例>>Python>>正文


Python BibDatabase.load_common_strings方法代码示例

本文整理汇总了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)
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:10,代码来源:test_bibtex_strings.py

示例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)
#.........这里部分代码省略.........
开发者ID:MartinKl,项目名称:python-bibtexparser,代码行数:103,代码来源:bparser.py

示例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')
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:8,代码来源:test_bibtex_strings.py

示例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, '')
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:7,代码来源:test_bibtex_strings.py


注:本文中的bibtexparser.bibdatabase.BibDatabase.load_common_strings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。