Convertir la base de datos bib a csv

Convertir la base de datos bib a csv

Tengo una bibliografía sobre un tema (no importa de qué tema sea, hay alrededor de 20 archivos diferentes y alrededor de 1000 registros). Necesito convertirlo a csv (o cualquier otro formato de tabla que pueda abrirse en Excel/LibreOffice Calc, etc.)

¿Alguien puede nombrar una herramienta para esto?

Respuesta1

Abra los archivos .bib enJabrefy expórtelos como archivos .csv de OpenOffice. Encontrarás la opción debajo del menú File,Export

Jabref_exportar

Ya que puedes correr Jabrefdesde elpágina de inicio del programa, no es necesario instalarlo. Sin embargo, necesitas Java.

Respuesta2

La mejor opción sería un lenguaje de secuencias de comandos, por ejemplo, Python. No sé si eres programador, pero crear un script tomando cada entrada y convirtiéndola debería ser bastante rápido (¡siempre que escribir python script_file.pyel mensaje no te asuste!). Python también se instala de forma predeterminada en la mayoría de los sistemas operativos Unix.

Aquí hay un script básico de Python que accede a algunos campos:

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

Puede adaptarlo a sus necesidades y guardar los campos deseados en un .csvarchivo.

Respuesta3

Una versión de Python usando bibtexparserbibtexparserypandas

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)

Y un ejemplo mínimo de trabajo:

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)

Respuesta4

Otra opción en R es usar el paquetebib2df:

# 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')

información relacionada