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


Python bwriter.BibTexWriter类代码示例

本文整理汇总了Python中bibtexparser.bwriter.BibTexWriter的典型用法代码示例。如果您正苦于以下问题:Python BibTexWriter类的具体用法?Python BibTexWriter怎么用?Python BibTexWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BibTexWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_paper_citation_dict

def format_paper_citation_dict(citation, indent='  '):
    """
    Format a citation dict for a paper or a list of papers into a BibTeX
    record string.

    :param citation: A ``Paper`` citation dict or list of such dicts.
    :param indent: Indentation to be used in BibTeX output.
    """
    if isinstance(citation, dict):
        entries = [citation]
    else:
        entries = citation

    # Handle conflicting ids for entries
    entries_ids = collections.defaultdict(lambda: 0)
    for entry in entries:
        entry_id = entry['ID']
        entries_ids[entry_id] += 1
        if entries_ids[entry_id] > 1:
            entry['ID'] = '%s_%s' % (entry_id, entries_ids[entry_id])

    writer = BibTexWriter()
    writer.indent = indent
    with io.StringIO('') as bibfile:
        db = BibDatabase()
        db.entries = entries
        bibfile.write(writer.write(db))
        return bibfile.getvalue().strip()
开发者ID:Phyks,项目名称:dissemin,代码行数:28,代码来源:bibtex.py

示例2: exif_pdf

 def exif_pdf(self, filename):
     fields = ["Author", "Year",  "Journal", "Title", "Publisher",
                    "Page", "Address", "Annote", "Booktitle", "Chapter",
                    "Crossred", "Edition", "Editor", "HowPublished",
                    "Institution", "Month", "Note", "Number",
                    "Organization", "Pages", "School",
                    "Series", "Type", "Url", "Volume", "Doi", "File"]
     op=pexif.get_json(filename)
     try:
         new_op = {
             field: str(value) for field in fields
             for key, value in op[0].items() if field.lower() in key.lower()
         }
         if 'Author' not in new_op:
             new_op['Author'] = 'Unknown'
         id_auth=new_op["Author"].split()[-1]
         id_tit = (new_op["Title"].split()[:2])
         id_tit.append(id_auth)
         id_val = "_".join(id_tit)
         new_op["ID"] = str(id_val)
         new_op["ENTRYTYPE"] = "article"
         op[0] = new_op
         db = BibDatabase()
         db.entries = op
         writer =  BibTexWriter()
         pdf_buff = (writer.write(db))
         self.create_textview(pdf_buff)
     except:
         self.Messages.on_error_clicked("Can't extract data from this pdf file", "Try other methods")
开发者ID:rudrab,项目名称:mkbib,代码行数:29,代码来源:getdata.py

示例3: parse

def parse(bibfile):

	with open(bibfile) as bibtex_file:
		writer = BibTexWriter()
		bib_database = bibtexparser.load(bibtex_file)

		for entry in bib_database.entries:
			print "\t-"
			print "\t\tlayout: paper"
			print "\t\tpaper-type: "+ preprocess(entry["type"])
			print "\t\tyear: " + preprocess(entry["year"])
			print "\t\tselected: no"
			print "\t\ttitle: >\n\t\t\t"+preprocess(entry["title"])
			print "\t\tauthors: "+ parseauthors(preprocess(entry["author"])).encode('UTF8')
			print "\t\timg: "
			print "\t\tvenue: "
			if("pages" in entry.keys()):
				print "\t\tpages: "+preprocess(entry["pages"])
			if("booktitle" in entry.keys()):
				print "\t\tbooktitle: "+preprocess(entry["booktitle"])
			if("journal" in entry.keys()):
				print "\t\tjournal: "+preprocess(entry["journal"])
			if("url" in entry.keys()):
				print "\t\tdoc-url: "+preprocess(entry["url"])
			else:
				print "\t\tdoc-url: "

			if("abstract" in entry.keys()):
				print "\t\tabstract: >\n\t\t\t" + preprocess(entry["abstract"]).encode('UTF8')

			print "\t\tbibtex: >\n\t\t\t"+ writer._entry_to_bibtex(entry).replace("\n","\n\t\t\t").encode('UTF8')
开发者ID:hsajjad,项目名称:guzmanhe.github.io,代码行数:31,代码来源:parsebib.py

示例4: test_content_entries_only

    def test_content_entries_only(self):
        with open('bibtexparser/tests/data/multiple_entries_and_comments.bib') as bibtex_file:
            bib_database = bibtexparser.load(bibtex_file)
        writer = BibTexWriter()
        writer.contents = ['entries']
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@book{Toto3000,
 author = {Toto, A and Titi, B},
 title = {A title}
}

@article{Wigner1938,
 author = {Wigner, E.},
 doi = {10.1039/TF9383400029},
 issn = {0014-7672},
 journal = {Trans. Faraday Soc.},
 owner = {fr},
 pages = {29--41},
 publisher = {The Royal Society of Chemistry},
 title = {The transition state method},
 volume = {34},
 year = {1938}
}

@book{Yablon2005,
 author = {Yablon, A.D.},
 publisher = {Springer},
 title = {Optical fiber fusion slicing},
 year = {2005}
}

"""
        self.assertEqual(result, expected)
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:34,代码来源:test_bibtexwriter.py

示例5: persist

 def persist(self):
     if self.__bib:
         self.__bib.entries[0]['note'] = self.note
         self.__bib.entries[0]['tags'] = ';'.join(self.tags)
         writer = BibTexWriter()
         with open(self.__bib_file_path, 'w') as bibfile:
             bibtex = writer.write(self.__bib)
             bibfile.write(bibtex)
开发者ID:rcorcs,项目名称:paperman,代码行数:8,代码来源:paper.py

示例6: test_trailing_comma

    def test_trailing_comma(self):
        with io.open(_data_path('article.bib'), 'r') as bibfile:
            bib = BibTexParser(bibfile.read())

        with io.open(_data_path('article_trailing_comma_output.bib'), 'r') as bibfile:
            expected = bibfile.read()
        writer = BibTexWriter()
        writer.add_trailing_comma = True
        result = writer.write(bib)
        self.maxDiff = None
        self.assertEqual(expected, result)
开发者ID:sciunto-org,项目名称:python-bibtexparser,代码行数:11,代码来源:test_bwriter.py

示例7: test_comma_first

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

示例8: test_align

    def test_align(self):
        bib_database = BibDatabase()
        bib_database.entries = [{'ID': 'abc123',
                                 'ENTRYTYPE': 'book',
                                 'author': 'test',
                                 'thisisaverylongkey': 'longvalue'}]
        writer = BibTexWriter()
        writer.align_values = True
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@book{abc123,
 author             = {test},
 thisisaverylongkey = {longvalue}
}

"""
        self.assertEqual(result, expected)

        with open('bibtexparser/tests/data/multiple_entries_and_comments.bib') as bibtex_file:
            bib_database = bibtexparser.load(bibtex_file)
        writer = BibTexWriter()
        writer.contents = ['entries']
        writer.align_values = True
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@book{Toto3000,
 author    = {Toto, A and Titi, B},
 title     = {A title}
}

@article{Wigner1938,
 author    = {Wigner, E.},
 doi       = {10.1039/TF9383400029},
 issn      = {0014-7672},
 journal   = {Trans. Faraday Soc.},
 owner     = {fr},
 pages     = {29--41},
 publisher = {The Royal Society of Chemistry},
 title     = {The transition state method},
 volume    = {34},
 year      = {1938}
}

@book{Yablon2005,
 author    = {Yablon, A.D.},
 publisher = {Springer},
 title     = {Optical fiber fusion slicing},
 year      = {2005}
}

"""
        self.assertEqual(result, expected)
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:52,代码来源:test_bibtexwriter.py

示例9: parsing_write

 def parsing_write(self, filename):
     # print(self.booklist)
     datalist = []
     writer = BibTexWriter()
     writer.indent = '    '
     for ref in self.TreeView.full_list:
         # print(type(ref))
         datadict = dict((k, v) for k, v in
                         zip(self.entries, ref) if v is not None)
         datalist.append(datadict)
     self.db.entries = datalist
     with open(filename, 'w') as bibfile:
         bibfile.write(writer.write(self.db))
开发者ID:rudrab,项目名称:mkbib,代码行数:13,代码来源:pybib.py

示例10: test_content_comment_only

    def test_content_comment_only(self):
        with open('bibtexparser/tests/data/multiple_entries_and_comments.bib') as bibtex_file:
            bib_database = bibtexparser.load(bibtex_file)
        writer = BibTexWriter()
        writer.contents = ['comments']
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@comment{}

@comment{A comment}

"""
        self.assertEqual(result, expected)
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:13,代码来源:test_bibtexwriter.py

示例11: test_entry_separator

    def test_entry_separator(self):
        bib_database = BibDatabase()
        bib_database.entries = [{'ID': 'abc123',
                                 'ENTRYTYPE': 'book',
                                 'author': 'test'}]
        writer = BibTexWriter()
        writer.entry_separator = ''
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@book{abc123,
 author = {test}
}
"""
        self.assertEqual(result, expected)
开发者ID:gpoo,项目名称:python-bibtexparser,代码行数:14,代码来源:test_bibtexwriter.py

示例12: test_indent

    def test_indent(self):
        bib_database = BibDatabase()
        bib_database.entries = [{'id': 'abc123',
                                 'type': 'book',
                                 'author': 'test'}]
        writer = BibTexWriter()
        writer.indent = '  '
        result = bibtexparser.dumps(bib_database, writer)
        expected = \
"""@book{abc123,
  author = {test}
}

"""
        self.assertEqual(result, expected)
开发者ID:NeoIO,项目名称:python-bibtexparser,代码行数:15,代码来源:test_bibtexwriter.py

示例13: test_sort_missing_field

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

示例14: bibtex

 def bibtex(self,simplified=False):
     if not self.__bib:
         return None
     from copy import deepcopy
     bib = deepcopy(self.__bib)
     if 'note' in bib.entries[0].keys():
         del bib.entries[0]['note']
     if 'tags' in bib.entries[0].keys():
         del bib.entries[0]['tags']
     if simplified:
         for k in ['doi','acmid','isbn', 'url','link']:
             if k in bib.entries[0].keys():
                 del bib.entries[0][k]
     writer = BibTexWriter()
     return writer.write(bib).strip()
开发者ID:rcorcs,项目名称:paperman,代码行数:15,代码来源:paper.py

示例15: _cleanupBibTex

    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)
开发者ID:siudej,项目名称:Cite,代码行数:16,代码来源:fetch.py


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