跳至主要內容

BibTeX

BibTeX 是一種檔案格式和參考文獻管理系統,通常與 LaTeX 排版一起使用。 它作為一種組織和儲存學術和研究文獻書目資訊的方法。

BibTeX 檔案具有 .bib 副檔名,由純文字條目組成,表示對各種出版物的參考,例如書籍、文章、會議論文、論文等。 每個 BibTeX 條目都遵循特定的結構,並包含不同書目詳細資訊的欄位,例如作者姓名、出版物標題、期刊或書籍標題、出版年份、頁碼等。

BibTeX 檔案也可以儲存文件的路徑,例如可以檢索的 .pdf 檔案。

安裝

首先,您需要安裝 bibtexparserPyMuPDF

%pip install --upgrade --quiet  bibtexparser pymupdf

範例

BibtexLoader 具有以下參數

  • file_path.bib bibtex 檔案的路徑
  • 可選的 max_docs:預設值=None,即不限制。 使用它來限制檢索的文件數量。
  • 可選的 max_content_chars:預設值=4000。 使用它來限制單個文件中的字元數。
  • 可選的 load_extra_meta:預設值=False。 預設情況下,僅從 bibtex 條目中載入最重要的欄位:Published (出版年份)、TitleAuthorsSummaryJournalKeywordsURL。 如果為 True,它也會嘗試載入傳回 entry_idnotedoilinks 欄位。
  • 可選的 file_pattern:預設值=r'[^:]+\.pdf'。 在 file 條目中尋找檔案的 Regex 模式。 預設模式支援 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

這個頁面對您有幫助嗎?