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


Python bibtexparser.load方法代码示例

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


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

示例1: import_bibtex

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def import_bibtex(bibtex, pub_dir="publication", featured=False, overwrite=False, normalize=False, dry_run=False):
    """Import publications from BibTeX file"""

    # Check BibTeX file exists.
    if not Path(bibtex).is_file():
        err = "Please check the path to your BibTeX file and re-run"
        log.error(err)
        raise AcademicError(err)

    # Load BibTeX file for parsing.
    with open(bibtex, "r", encoding="utf-8") as bibtex_file:
        parser = BibTexParser(common_strings=True)
        parser.customization = convert_to_unicode
        parser.ignore_nonstandard_types = False
        bib_database = bibtexparser.load(bibtex_file, parser=parser)
        for entry in bib_database.entries:
            parse_bibtex_entry(entry, pub_dir=pub_dir, featured=featured, overwrite=overwrite, normalize=normalize, dry_run=dry_run) 
开发者ID:sourcethemes,项目名称:academic-admin,代码行数:19,代码来源:cli.py

示例2: _ingest_citations

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def _ingest_citations(rc):
    import bibtexparser
    from bibtexparser.bparser import BibTexParser
    from bibtexparser.customization import getnames

    parser = BibTexParser()
    parser.ignore_nonstandard_types = False

    def customizations(record):
        for n in ["author", "editor"]:
            if n in record:
                a = [i for i in record[n].replace("\n", " ").split(", ")]
                b = [i.split(" and ") for i in a]
                c = [item for sublist in b for item in sublist]
                d = [i.strip() for i in c]
                record[n] = getnames(d)

        return record

    parser.customization = customizations
    with open(rc.filename, "r", encoding='utf-8') as f:
        bibs = bibtexparser.load(f, parser=parser)
    coll = rc.client[rc.db][rc.coll]
    for bib in bibs.entries:
        bibid = bib.pop("ID")
        bib["entrytype"] = bib.pop("ENTRYTYPE")
        if "author" in bib:
            bib["author"] = [
                a.strip() for b in bib["author"] for a in RE_AND.split(b)
            ]
        if "title" in bib:
            bib["title"] = RE_SPACE.sub(" ", bib["title"])
        rc.client.update_one(rc.db, rc.coll, {"_id": bibid}, bib, upsert=True) 
开发者ID:regro,项目名称:regolith,代码行数:35,代码来源:commands.py

示例3: add_from_source

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def add_from_source(self, bibtex_source):
        '''
        Add source to bibliography.

        Arguments:
            bibtex_source (str, or list) : bibtex string, bibtex file
            name, path to bibtex file, or list of such arguments.
        '''

        if isinstance(bibtex_source, str):
            bibtex_sources = [bibtex_source]
        else:
            bibtex_sources = bibtex_source

        for bibtex_source in bibtex_sources:

            new_references = bibtexparser_to_references(bibtexparser.loads(bibtex_source))

            if len(new_references) == 0:
                try:
                    with open(bibtex_source) as source_file:
                        new_references = bibtexparser_to_references(bibtexparser.load(source_file))
                except Exception as e:
                    _log.warning(e)

                if len(new_references) == 0:

                    for source_file_name in glob(bibtex_source + '*.bib'):

                        with open(source_file_name) as source_file:
                            new_references = bibtexparser_to_references(bibtexparser.load(source_file))


            if len(new_references) > 0:
                self.references.update(new_references)

            else:
                warn('Cannot load bibliography.')
                _log.warning('Bibliography source %s not found' % bibtex_source)
                sys.exit(1) 
开发者ID:hchauvet,项目名称:beampy,代码行数:42,代码来源:biblio.py

示例4: parse_bibtex_files

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def parse_bibtex_files(fol, recursive=False):
    from collections import Counter, defaultdict
    all_authors = []
    papers = set()
    authors_papers = defaultdict(list)
    # https://bibtexparser.readthedocs.io/en/master/tutorial.html
    bib_fnames = glob.glob(op.join(op.join(fol, '**', '*.bib')), recursive=True) if recursive \
        else glob.glob(op.join(op.join(fol, '*.bib')))
    for bib_fname in bib_fnames:
        parent_fol = op.split(bib_fname)[-2]
        if recursive and parent_fol == fol:
            # Read only files in subfolders
            continue
        own_paper_name = namebase(bib_fname)
        with open(bib_fname) as bibtex_file:
            bib = bibtexparser.load(bibtex_file)
            print('{} has {} entries'.format(bib_fname, len(bib.entries)))
            for entry in bib.entries:
                paper_name = entry['title']
                # avoid duplicates
                if paper_name in papers:
                    continue
                papers.add(paper_name)
                authors = parse_authors(entry)
                for author in authors:
                    authors_papers[author].append('"{}" ({}) -> "{}"'.format(
                        paper_name, entry['year'] if 'year' in entry else '', own_paper_name))
                all_authors.extend(authors)
    all_authors = Counter(all_authors).most_common()
    print(all_authors)
    print('{} has cited you in {} publications!'.format(all_authors[0][0], all_authors[0][1]))
    # print(authors_papers[all_authors[0][0]])
    return all_authors, authors_papers 
开发者ID:pelednoam,项目名称:mmvt,代码行数:35,代码来源:google_scholar.py

示例5: export_bibtex

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def export_bibtex(author_name, fol, recursive=False):
    from bibtexparser.bwriter import BibTexWriter
    from bibtexparser.bibdatabase import BibDatabase
    db = BibDatabase()

    papers = set()
    bib_fnames = get_bib_files(fol, recursive)
    for bib_fname in tqdm(bib_fnames):
        with open(bib_fname) as bibtex_file:
            bib = bibtexparser.load(bibtex_file)
            for entry in bib.entries:
                paper_name = entry['title']
                if paper_name in papers:
                    continue
                papers.add(paper_name)
                authors = parse_authors(entry)
                if author_name in authors:
                    db.entries.append(entry)

    author_name = author_name.replace(' ', '').replace(',', '_')
    bibtex_fname = op.join(fol, '{}.bib'.format(author_name))
    writer = BibTexWriter()
    with open(bibtex_fname, 'w') as bibfile:
        bibfile.write(writer.write(db))
    print('The bibtex file with {} papers of {} where she cited you was exported to {}'.format(
        len(db.entries), author_name, bibtex_fname)) 
开发者ID:pelednoam,项目名称:mmvt,代码行数:28,代码来源:google_scholar.py

示例6: load

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def load(fname):
    with open(fname, 'rb') as fp:
        obj = pickle.load(fp)
    return obj 
开发者ID:pelednoam,项目名称:mmvt,代码行数:6,代码来源:google_scholar.py

示例7: load

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def load(cls, path, package=None):
        if package is not None:
            root = pkg_resources.resource_filename(package, '.')
            root = os.path.abspath(root)
            path = os.path.join(root, path)

        parser = bp.bparser.BibTexParser()
        # Downstream tooling is much easier with unicode. For actual latex
        # users, use the modern biber backend instead of bibtex
        parser.customization = bp.customization.convert_to_unicode
        with open(path) as fh:
            try:
                db = bp.load(fh, parser=parser)
            except Exception as e:
                raise ValueError("There was a problem loading the BiBTex file:"
                                 "%r" % path) from e

        entries = collections.OrderedDict()
        for entry in db.entries:
            id_ = entry.pop('ID')
            type_ = entry.pop('ENTRYTYPE')
            if id_ in entries:
                raise ValueError("Duplicate entry-key found in BibTex file: %r"
                                 % id_)
            entries[id_] = CitationRecord(type_, entry)

        return cls(entries) 
开发者ID:qiime2,项目名称:qiime2,代码行数:29,代码来源:cite.py

示例8: convert

# 需要导入模块: import bibtexparser [as 别名]
# 或者: from bibtexparser import load [as 别名]
def convert(source, crossrefQuery=''):

    r = requests.get(source)

    bibText = r.text.encode('utf-8')


    if True:

        author = ''
        title = ''
        year = ''
        for line in bibText.split('\n'):
            if line.strip() == '':
                continue

            if line.find(' author =') != -1:
                author = line.strip()
                author = author[author.find('{') + 1 : author.rfind('}')].strip().replace(' and ', ', ')

            if line.find(' year =') != -1:
                year = line.strip()
                year = year[year.find('{') + 1 : year.rfind('}')].strip()
                year = 'description:' + year


            if line.find(' title =') != -1:
                title = line.strip()
                title = title[title.find('{') + 1 : title.rfind('}')].strip()

                print ' | ' + title + ' | | ' + ' author:'+ author + ' ' + year

                title = ''
                author = ''
                year = ''

    else:

        f = open('web_content/bib', 'w+')

        f.write(bibText)

        f.close()

        f = open('web_content/bib', 'r')

        bib_database = bibtexparser.load(f)

        for entry in bib_database.entries:
            desc = ''
            if entry.has_key('year'):
                desc = 'description:' + entry['year']
            line = ' | ' + entry['title'] + ' |  | author:' + entry['author'] + ' ' + desc 
            print line.encode('utf-8') 
开发者ID:wowdd1,项目名称:xlinkBook,代码行数:56,代码来源:convert_bibliographies.py


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