![將書目資料庫轉換為 csv](https://rvso.com/image/254708/%E5%B0%87%E6%9B%B8%E7%9B%AE%E8%B3%87%E6%96%99%E5%BA%AB%E8%BD%89%E6%8F%9B%E7%82%BA%20csv.png)
我有一個關於某個主題的參考書目(無論是什麼主題,都有大約 20 個不同的文件和大約 1000 條記錄)。我需要將其轉換為 csv(或可以在 Excel/LibreOffice Calc 等中開啟的任何其他表格格式)
誰能為此命名一個工具嗎?
答案1
答案2
最好的選擇是腳本語言,例如Python。我不知道您是否是程式設計師,但是製作一個腳本來獲取每個條目並轉換它們應該非常快(前提是python script_file.py
在提示中輸入不會嚇到您!)。大多數 Unix 作業系統上也預設安裝了 Python。
這是一個存取幾個欄位的基本 python 腳本:
from pybtex.database.input import bibtex
#open a bibtex file
parser = bibtex.Parser()
bibdata = parser.parse_file("myrefs.bib")
#loop through the individual references
for bib_id in bibdata.entries:
b = bibdata.entries[bib_id].fields
try:
# change these lines to create a SQL insert
print(b["title"])
print(b["journal"])
print(b["year"])
#deal with multiple authors
for author in bibdata.entries[bib_id].persons["author"]:
print(author.first(), author.last())
# field may not exist for a reference
except(KeyError):
continue
您可以根據您的需求進行調整,並將所需的欄位儲存到.csv
文件中。
答案3
使用 bibtexparser 的 python 版本書目解析器和貓熊
with open('ref.bib') as bibtex_file:
bib_database = bibtexparser.load(bibtex_file)
df = pd.DataFrame(bib_database.entries)
df.to_csv('ref.csv', index=False)
以及一個最小的工作範例:
import bibtexparser
import pandas as pd
bibtex = """@article{ einstein1935can,
title={Can quantum-mechanical description of physical reality be considered complete?},
author={Einstein, Albert and Podolsky, Boris and Rosen, Nathan},
journal={Physical review},
volume={47},number={10},
pages={777},
year={1935},
publisher={APS}}
@inproceedings{sharma2017daniel,
title={DANIEL: A deep architecture for automatic analysis and retrieval of building floor plans},
author={Sharma, Divya and Gupta, Nitin and Chattopadhyay, Chiranjoy and Mehta, Sameep},
booktitle={2017 14th IAPR International Conference on Document Analysis and Recognition (ICDAR)},
volume={1},pages={420--425},year={2017},organization={IEEE}}"""
with open('ref.bib', 'w') as bibfile:
bibfile.write(bibtex)
with open('ref.bib') as bibtex_file:
bib_database = bibtexparser.load(bibtex_file)
df = pd.DataFrame(bib_database.entries)
df.to_csv('ref.csv', index=False)
答案4
R 中的另一個選擇是使用套件bib2df
:
# Install bib2df
install.packages('bib2df')
# Load bib2df
library(bib2df)
# Set path to .bib
# (Example data)
path <- system.file("extdata", "LiteratureOnCommonKnowledgeInGameTheory.bib", package = "bib2df")
# (Alternatively, your own file)
# path <- 'refs.bib'
# Read .bib as a data.frame
df <- bib2df(path)
# Parse the author and editor columns (list columns cannot be saved directly in a csv)
df$AUTHOR <- vapply(df$AUTHOR, paste, collapse = ' and ', '')
df$EDITOR <- vapply(df$EDITOR, paste, collapse = ' and ', '')
# Export to csv
write.csv(df, 'refs.csv')