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


Python BibDatabase.entries方法代码示例

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


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

示例1: merge

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
def merge(entry1, entry2):
    db = BibDatabase()
    entries = {}
    keys1 = entry1.keys()
    keys2 = entry2.keys()
    intersection = intersect(keys1, keys2)
    union = get_union(keys1, keys2)
    not_intersect = not_intersection(union, intersection)

    #The two entries have the same keys, so everything needs to be merged
    if not not_intersect:
        for key in keys1:
            if key == 'author':
                author = merge_author(entry1[key], entry1['author_norm'], entry2[key], entry2['author_norm'])
                author_norm = normalize_author(str(author))
                entries = add_field(entries, key, author)
                entries = add_field(entries, 'author_norm', author_norm)
            if key == 'editor':
                editor = merge_author(entry1[key], entry1['editor_norm'], entry2[key], entry2['editor_norm'])
                editor_norm = normalize_author(str(editor))
                entries = add_field(entries, key, editor)
                entries = add_field(entries, 'editor_norm', editor_norm)
            elif key == 'keywords' or key == 'topics':
                entries = add_field(entries, key, merge_keywords(entry1[key], entry2[key]))
            elif key == 'month':
                entries = add_field(entries, key, entry1[key])
            elif len(entry1[key]) == len(entry2[key]) or len(entry1[key]) < len(entry2[key]):
                entries = add_field(entries, key, entry2[key])
            else:
                entries = add_field(entries, key, entry1[key])
    else:
        #All the keys in the two entries aren't the same, so some need to be merged
        #some can just be written
        #print "Entries are not the same!"
        #print keys1, keys2
        for key in intersection:
            if key == 'author':
                author = merge_author(entry1[key], entry1['author_norm'], entry2[key], entry2['author_norm'])
                entries = add_field(entries, key, author)
            if key == 'editor':
                editor = merge_author(entry1[key], entry1['editor_norm'], entry2[key], entry2['editor_norm'])
                entries = add_field(entries, key, editor)
            elif key == 'keywords' or key == 'topics':
                entries = add_field(entries, key, merge_keywords(entry1[key], entry2[key]))
            elif key == 'month':
                entries = add_field(entries, key, entry1[key])
            elif key == 'doi':
                entries = add_field(entries, get_keycount(intersection, key), entry1[key])
            elif len(entry1[key]) == len(entry2[key]) or len(entry1[key]) < len(entry2[key]):
                entries = add_field(entries, key, entry2[key])
            else:
                entries = add_field(entries, key, entry1[key])
        for key in not_intersect:
            if key in keys1:
                entries = add_field(entries, key, entry1[key])
            elif key in keys2:
                entries = add_field(entries, key, entry2[key])
    
    db.entries = [entries]
    return db
开发者ID:Juvawa,项目名称:bib2web,代码行数:62,代码来源:merge.py

示例2: format_paper_citation_dict

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
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,代码行数:30,代码来源:bibtex.py

示例3: merge_folder_tree

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
def merge_folder_tree(folder, use_backup):
    """
    Merge bib files from the current subtree into a master bib file at the root.
    This function updates the 'file' link of each entry with the relative path
    to each subfolder that has been processed.

    Args:
        folder (str): relative or absolute path of the folder to process.

    Returns:
        Nothing, but creates a file named `master.bib` in the given folder.
    """
    db = BibDatabase()
    for subdir, _dirs, _files in os.walk(os.path.abspath(folder)):
        if os.path.exists(os.path.join(subdir, '.nobib')):
            continue  # Skip blacklisted folders
        reldir = os.path.relpath(subdir, os.path.abspath(folder))
        bib_path = os.path.join(subdir, 'biblio.bib')
        subdb = utils.read_bib_file(bib_path)
        for entry in subdb.entries:
            filename = utils.decode_filename_field(entry['file'])
            filename = os.path.join(reldir, filename)
            entry['file'] = utils.encode_filename_field(filename)
        db.entries += subdb.entries
    # Remove duplicated entries
    entries_dict = db.entries_dict
    db.entries = [val for key, val in entries_dict.items()]
    # Write result
    bib_path = os.path.join(folder, 'master.bib')
    utils.write_with_backup(bib_path, utils.write_bib(db, order=True), use_backup)
开发者ID:jdumas,项目名称:autobib,代码行数:32,代码来源:autobib.py

示例4: save_citation

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
def save_citation(citation_record):
    cite_anchor = citation_record.find('a', {'class': 'gs_nph', 'href': '#', "role": "button"})
    if not cite_anchor or not cite_anchor['onclick']:
        logging.warn("No Cite anchor for citation: %s" % citation_record)
        return
    citation_id = cite_anchor['onclick'].split(',')[1][1:-1]
    logging.info("Getting formated cite from citation id: " + citation_id)
    params = {"q": "info:%s:scholar.google.com/" % citation_id, "output": "cite"}
    soup = create_soup_by_url("https://scholar.google.com/scholar", params)
    bib_anchor = soup.find('a', {"class": "gs_citi"})
    if not bib_anchor:
        logging.debug("BibTex page soup is: %s" % soup.getText())
        logging.warn("No BibTex citation provided for citation: %s" % citation_id)
        return
    soup = create_soup_by_url(bib_anchor['href'])
    global citation_num
    citation_num += 1
    # Adding a tag to the bib entry about google scholar citation ID
    citation_entry = bibtexparser.loads(soup.getText()).entries[0]
    citationID = citation_entry['ID'] # e.g., melville2004review
    citation_entry["gscholar_id"] = citation_id
    db_entry=[]
    db_entry.append(citation_entry)
    db = BibDatabase()
    db.entries = db_entry
    g_bib_entry = bibtexparser.dumps(db)
    bib_entry = "%% [%d]\n%s" % (citation_num, g_bib_entry)
    logging.info(bib_entry.strip())
    with open(opts.citation_name, "a+") as f:
        f.write(bib_entry.encode('utf-8'))
    if opts.should_download:
        pdf_div = citation_record.find('div', {"class": "gs_ggs gs_fl"})
        if pdf_div:
            download_pdf(pdf_div.a['href'], citationID)
开发者ID:shiqiezi,项目名称:google-scholar-citations,代码行数:36,代码来源:main.py

示例5: exif_pdf

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
 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,代码行数:31,代码来源:getdata.py

示例6: test_align

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
    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,代码行数:54,代码来源:test_bibtexwriter.py

示例7: test_entry_separator

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
    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,代码行数:16,代码来源:test_bibtexwriter.py

示例8: write_selected_to_file

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
def write_selected_to_file(selected):
    db = BibDatabase()
    result = []
    for item in selected:
        path = str(bib_dir) + str(files[item])
        with open(path, 'r') as f:
            db = bibtexparser.load(f)
            result.append(db.entries[0])
    db.entries = result
    print db.entries
    with open(website_dir, 'w') as f:
        bibtexparser.dump(db, f)

    subprocess.call(['bib2html', '-f', website_dir])
开发者ID:Juvawa,项目名称:abi,代码行数:16,代码来源:gui.py

示例9: test_sort_missing_field

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
 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,代码行数:17,代码来源:test_bibtexwriter.py

示例10: test_indent

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
    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,代码行数:17,代码来源:test_bibtexwriter.py

示例11: __str__

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
 def __str__(self):
     bib = BibDatabase()
     bib.entries = [{
         'ENTRYTYPE': 'article',
         'ID': self.entry_number,
         'author': self.author,
         'journal': self.journal,
         'title': self.title,
         'year': self.year,
         'volume': self.volume,
         'number': self.number,
         'pages': self.pages,
         'abstract': self.abstract,
         'keyword': self.keyword,
         'doi': self.doi,
         'issn': self.issn
     }]
     return bibtexparser.dumps(bib)
开发者ID:cxsmarkchan,项目名称:ieee-crawler,代码行数:20,代码来源:models.py

示例12: write_selected_to_file

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
    def write_selected_to_file(self, selected, website):
        db = BibDatabase()
        result = []
        for item in selected:
            path = str(self.bib_dir) + str(item)
            with open(path, 'r') as f:
                db = bibtexparser.load(f)
                result.append(db.entries[0])
        db.entries = result
        if website == 'personal':
            with open(self.personal_website_bib, 'w') as f:
                bibtexparser.dump(db, f)
        elif website == 'group':
            with open(self.group_website_bib, 'w') as f:
                bibtexparser.dump(db, f)

        #Make sure the file is uploaded to Dropbox before it is send to BibBase
        time.sleep(1)
        
        #Query to BibBase with the right URL
        if website == 'personal':
            html = urllib2.urlopen("http://bibbase.org/show?bib=" + str(self.personal_link)).read()
        elif website == 'group':
            html = urllib2.urlopen("http://bibbase.org/show?bib=" + str(self.group_link)).read()
        #The html does not contain styling and jquery or javascript
        html = '<head>' + \
            '<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>' + \
            '<script src="http://bibbase.org/js/bibbase.min.js" type="text/javascript"></script>' + \
            '<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">' + \
            '<link rel="stylesheet" href="http://bibbase.org/css/bootstrap.min.css" type="text/css" media="screen">' + \
            '<link rel="stylesheet" href="http://bibbase.org/css/styles/default.css" type="text/css" media="screen">' + \
            '<link rel="stylesheet" href="http://bibbase.org/css/styles/common.css" type="text/css" media="screen">' + \
            '<link rel="stylesheet" href="http://bibbase.org/css/styles/hide_text.css" type="text/css" media="screen">' + str(html)

        if website == 'personal':
            with open(self.personal_website_html, 'w') as website:
                website.write(html)    
        elif website == 'group':
            with open(self.group_website_html, 'w') as website:
                website.write(html)    
开发者ID:Juvawa,项目名称:bib2web,代码行数:42,代码来源:gui.py

示例13: main

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
def main():
    if len(sys.argv) < 3:
        print("Wrong number of arguments. Usage: \n")
        print("python3 dump_db.py name.db dump.bib")

    print("Dump database")
    print("Database: ", sys.argv[1])

    engine = create_engine('sqlite:///app.db')
    Session = sessionmaker()
    Session.configure(bind=engine)
    session = Session()

    db = BibDatabase()
    db.entries = []

    dbentries = session.query(BiblioEntry)
    for e in dbentries:
        db.entries.append(
            {'journal': e.journal,
             'title': e.title,
             'year': str(e.year),
             'publisher': e.publisher,
             'school': e.school,
             'ID': e.ID,
             'url': e.url,
             'author': e.authors,
             'keyword': e.keywords,
             'ENTRYTYPE': e.ENTRYTYPE}
                        )

    print("Write file on", sys.argv[2])
    writer = BibTexWriter()
    with open(sys.argv[2], 'w') as bibfile:
        bibfile.write(writer.write(db))

    session.close()
    print("Connection closed.")
开发者ID:frapac,项目名称:bibtex-browser,代码行数:40,代码来源:dump_db.py

示例14: formatText

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [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))
开发者ID:beddingearly,项目名称:LMM,代码行数:97,代码来源:BibtexParser.py

示例15: BibDatabase

# 需要导入模块: from bibtexparser.bibdatabase import BibDatabase [as 别名]
# 或者: from bibtexparser.bibdatabase.BibDatabase import entries [as 别名]
import sqlite3
import re
import datetime

from bibtexparser.bwriter import BibTexWriter
from bibtexparser.bibdatabase import BibDatabase

db = sqlite3.connect("profile.db")
c = db.cursor()

db = BibDatabase()
db.entries = []

id_dict = {}

c.execute(
    'SELECT title, authors, journal, journal_abbr, volume, pages, month, year FROM journal_paper WHERE locale = "international" ORDER BY year, month'
)
for row in c:
    title, authors, journal, journal_abbr, volume, pages, month, year = row

    title_kwd = None
    authors_kwd = None
    journal_kwd = None

    bib_obj = {"ENTRYTYPE": "article"}
    if title is not None:
        bib_obj["title"] = title
        for word in re.split("[^A-Za-z0-9]", title):
            word = word.lower()
            if word != "a" and word != "the" and word != "an":
开发者ID:seokhwankim,项目名称:seokhwankim.github.io,代码行数:33,代码来源:generate_bib.py


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