BibTeX
BibTeX 是一种文件格式和参考文献管理系统,通常与
LaTeX排版系统配合使用。它用于组织和存储学术及研究文档的 bibliographic(书目)信息。
BibTeX 文件具有 .bib 扩展名,并且由表示各种出版物引用的纯文本条目组成,例如书籍、文章、会议论文、论文等。每个 BibTeX 条目都遵循特定结构,并包含作者姓名、出版标题、期刊或图书标题、发表年份、页码等不同的文献细节。
BibTeX文件也可以存储文档路径,例如可以检索的.pdf文件。
安装
首先,您需要安装bibtexparser和PyMuPDF。
%pip install --upgrade --quiet bibtexparser pymupdf
示例
BibtexLoader 有这些参数:
file_path: the path of the.bibbibtex文件- 可选
max_docs:默认值=None,即无限制。用于限制检索到的文档数量。 - 可选
max_content_chars:默认值=4000。用于限制单个文档中的字符数量。 - optional
load_extra_meta: default=False. By default only the most important fields from the bibtex entries:Published(publication year),Title,Authors,Summary,Journal,Keywords, andURL. If True, it will also try to load returnentry_id,note,doi, andlinksfields. - optional
file_pattern: default=r'[^:]+\.pdf'. Regex模式用于在file条目中查找文件。默认的模式支持Zotero风格的bibtex样式和原始文件路径。
from langchain_community.document_loaders import BibtexLoader
API 参考:Bibtex 加载器
# Create a dummy bibtex file and download a pdf.
import urllib.request
urllib.request.urlretrieve(
"https://www.fourmilab.ch/etexts/einstein/specrel/specrel.pdf", "einstein1905.pdf"
)
bibtex_text = """
@article{einstein1915,
title={Die Feldgleichungen der Gravitation},
abstract={Die Grundgleichungen der Gravitation, die ich hier entwickeln werde, wurden von mir in einer Abhandlung: ,,Die formale Grundlage der allgemeinen Relativit{\"a}tstheorie`` in den Sitzungsberichten der Preu{\ss}ischen Akademie der Wissenschaften 1915 ver{\"o}ffentlicht.},
author={Einstein, Albert},
journal={Sitzungsberichte der K{\"o}niglich Preu{\ss}ischen Akademie der Wissenschaften},
volume={1915},
number={1},
pages={844--847},
year={1915},
doi={10.1002/andp.19163540702},
link={https://onlinelibrary.wiley.com/doi/abs/10.1002/andp.19163540702},
file={einstein1905.pdf}
}
"""
# save bibtex_text to biblio.bib file
with open("./biblio.bib", "w") as file:
file.write(bibtex_text)
docs = BibtexLoader("./biblio.bib").load()
docs[0].metadata
{'id': 'einstein1915',
'published_year': '1915',
'title': 'Die Feldgleichungen der Gravitation',
'publication': 'Sitzungsberichte der K{"o}niglich Preu{\\ss}ischen Akademie der Wissenschaften',
'authors': 'Einstein, Albert',
'abstract': 'Die Grundgleichungen der Gravitation, die ich hier entwickeln werde, wurden von mir in einer Abhandlung: ,,Die formale Grundlage der allgemeinen Relativit{"a}tstheorie`` in den Sitzungsberichten der Preu{\\ss}ischen Akademie der Wissenschaften 1915 ver{"o}ffentlicht.',
'url': 'https://doi.org/10.1002/andp.19163540702'}
print(docs[0].page_content[:400]) # all pages of the pdf content
ON THE ELECTRODYNAMICS OF MOVING
BODIES
By A. EINSTEIN
June 30, 1905
It is known that Maxwell’s electrodynamics—as usually understood at the
present time—when applied to moving bodies, leads to asymmetries which do
not appear to be inherent in the phenomena. Take, for example, the recipro-
cal electrodynamic action of a magnet and a conductor. The observable phe-
nomenon here depends only on the r