swh.indexer.bibtex module#

swh.indexer.bibtex.TMP_ROOT_URI_PREFIX = 'https://www.softwareheritage.org/schema/2022/indexer/tmp-node/'#

IRI used for skolemization; it is not used outside codemeta_to_bibtex().

exception swh.indexer.bibtex.BibTeXCitationError[source]#

Bases: Exception

class swh.indexer.bibtex.BibTeXWithMacroWriter(encoding=None)[source]#

Bases: Writer

quote(s)[source]#
>>> w = BibTeXWithMacroWriter()
>>> print(w.quote(f'{MACRO_PREFIX}:jan'))
jan
swh.indexer.bibtex.codemeta_to_bibtex(doc: Dict[str, Any], swhid: QualifiedSWHID | None = None, *, resolve_unknown_context_url: bool = False, force_codemeta_context: bool = False) str[source]#

Generate citation in BibTeX format from a parsed codemeta.json file.

Parameters:
  • doc – parsed codemeta.json file

  • swhid – optional SWHID to add as swhid field in BibTeX citation

  • resolve_unknown_context_url – if const:True unknown JSON-LD context URL will be fetched using requests instead of raising an exception, False by default as it can lead sending requests to arbitrary URLs so use with caution

  • force_codemeta_context – if True, the @context field in the JSON-LD document will be set to the CodeMeta v3.0 one, this can be used to ensure citation can be generated when strict JSON-LD parsing failed

Returns:

A BibTeX citation as a string.

Raises:

BibTeXCitationError – when citation could not be generated

swh.indexer.bibtex.cff_to_bibtex(content: str, swhid: QualifiedSWHID | None = None) str[source]#

Generate citation in BibTeX format from a raw citation.cff file.

Parameters:
  • content – raw content of a citation.cff file

  • swhid – optional SWHID to add as swhid field in BibTeX citation

Returns:

A BibTeX citation as a string.

Raises:

BibTeXCitationError – when citation could not be generated