BibTeX
BibTeX 是一种文件格式和参考文献管理系统,通常与
LaTeX
排版系统配合使用。它用于组织和存储学术及研究文档的参考文献信息。
BibTeX
文件具有 .bib
扩展名,由纯文本条目组成,代表对各种出版物的引用,如书籍、文章、会议论文、学位论文等。每个 BibTeX
条目都遵循特定的结构,包含用于不同参考文献详细信息的字段,例如作者姓名、出版物标题、期刊或书籍标题、出版年份、页码等。
BibTeX 文件还可以存储文档的路径,例如可检索的 .pdf
文件。
安装
首先,你需要安装 bibtexparser
和 PyMuPDF
。
%pip install --upgrade --quiet bibtexparser pymupdf
示例
BibtexLoader
具有以下参数:
file_path
:.bib
BibTeX 文件的路径- 可选参数
max_docs
: 默认值=None,即不设限制。使用它来限制检索到的文档数量。 - 可选参数
max_content_chars
: 默认值=4000。使用它来限制单个文档中的字符数量。 - 可选参数
load_extra_meta
: 默认值=False。默认情况下,只加载 BibTeX 条目中最重要的字段:Published
(出版年份)、Title
、Authors
、Summary
、Journal
、Keywords
和URL
。如果为 True,它还将尝试加载并返回entry_id
、note
、doi
和links
字段。 - 可选参数
file_pattern
: 默认值=r'[^:]+\.pdf'
。用于在file
条目中查找文件的正则表达式模式。默认模式支持Zotero
风格的 BibTeX 样式和裸文件路径。
from langchain_community.document_loaders import BibtexLoader
API 参考:BibtexLoader
# 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