我有一份关于某个主题的参考书目(不管是什么主题,大约有 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 版本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)
最小工作示例:
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')