🔍 Code Extractor

function get_bibtext

Maturity: 30

Retrieves and parses BibTeX citation data for a given DOI (Digital Object Identifier), extracting the title and formatted BibTeX string.

File:
/tf/active/vicechatdev/offline_parser_docstore.py
Lines:
54 - 69
Complexity:
simple

Purpose

This function fetches bibliographic information in BibTeX format for academic papers using their DOI. It calls an external function get_bib() to retrieve the raw BibTeX data, then parses it using bibtexparser to extract the title and return both the formatted BibTeX string and the paper title. It handles errors gracefully by returning 'Not available' and 'NA' when the resource is not found or parsing fails.

Source Code

def get_bibtext(doi):

    #print("doi in ",doi)
    bibtex=get_bib(doi)
    if bibtex=='Resource not found.':
        return 'Not available','NA'
    #print("bibtex out ",bibtex)
    try:
        bibtex = bibtexparser.parse_string(bibtex)
        #print(bibtex.entries)
        title=bibtex.entries[0].get('title').value
        bibtex = bibtexparser.write_string(bibtex)
        return bibtex,title.replace("'","`")
    except Exception as e:
        print(e)
        return 'Not available','NA'

Parameters

Name Type Default Kind
doi - - positional_or_keyword

Parameter Details

doi: A string representing the Digital Object Identifier (DOI) of an academic paper or publication. This is a unique alphanumeric string assigned to scholarly articles (e.g., '10.1234/example.doi'). The function uses this to retrieve bibliographic information.

Return Value

Returns a tuple of two strings: (bibtex_string, title). The first element is the formatted BibTeX citation string, and the second is the paper title with single quotes replaced by backticks. If the resource is not found or an error occurs, returns ('Not available', 'NA').

Dependencies

  • bibtexparser

Required Imports

import bibtexparser

Usage Example

# Assuming get_bib() function is available
# from your_module import get_bibtext

doi = '10.1038/nature12373'
bibtex_citation, paper_title = get_bibtext(doi)

if bibtex_citation != 'Not available':
    print(f"Title: {paper_title}")
    print(f"BibTeX:\n{bibtex_citation}")
else:
    print("Citation not available for this DOI")

Best Practices

  • Always check if the returned values are 'Not available' and 'NA' before using them to avoid processing invalid data
  • The function replaces single quotes with backticks in titles to avoid string formatting issues - be aware of this transformation
  • Ensure the get_bib() function is properly implemented and accessible in the same scope
  • The function silently catches all exceptions and prints them - consider logging errors for production use
  • The function expects bibtex.entries to have at least one entry with a 'title' field - malformed BibTeX data may cause failures

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_bib 74.7% similar

    Fetches BibTeX citation data for a given DOI (Digital Object Identifier) from the CrossRef API.

    From: /tf/active/vicechatdev/offline_parser_docstore.py
  • function parse_references_section 50.4% similar

    Parses a formatted references section string and extracts structured data including reference numbers, sources, and content previews using regular expressions.

    From: /tf/active/vicechatdev/improved_convert_disclosures_to_table.py
  • class ReferenceManager_v3 40.4% similar

    Manages extraction and formatting of references for LLM chat responses. Handles both file references and BibTeX citations, formatting them according to various academic citation styles.

    From: /tf/active/vicechatdev/OneCo_hybrid_RAG_old.py
  • class ReferenceManager_v2 40.3% similar

    Manages extraction and formatting of references for LLM chat responses. Handles both file references and BibTeX citations, formatting them according to various academic citation styles.

    From: /tf/active/vicechatdev/OneCo_hybrid_RAG copy.py
  • class ReferenceManager_v4 39.9% similar

    Manages extraction and formatting of references for LLM chat responses. Handles both file references and BibTeX citations, formatting them according to various academic citation styles.

    From: /tf/active/vicechatdev/OneCo_hybrid_RAG.py
← Back to Browse