Tools to handle bibliographic metadata
This module provides functionality to handle bibliographic metadata, i.e. structured metadata describing sources of data/research.
- class clldutils.source.Source(genre, id_, *args, _check_id=True, _lowercase=False, _strip_tex=None, **kw)[source]
Bibliographic metadata about a source used for some analysis in a linguistic database.
Following BibTeX-style, a Source is just an ordered list of key-value pairs, augmented with an id (a.k.a. BibTeX citekey) and a genre (a.k.a. Entry Types).
- Variables:
id (str) – The citekey of a source.
genre (str) – The entry type of a source.
Note
We restrict the allowed syntax for the id to make sure it can safely be used as path component in a URL. To skip this check, pass _check_id=False to the constructor.
Usage:
>>> from clldutils.source import Source >>> src = Source('article', 'Meier2000', author='Meier', year='2000', title='The Title') >>> print(src.bibtex()) @article{Meier2000, author = {Meier}, year = {2000}, title = {The Title} } >>> print(src) Meier. 2000. The Title.
- Parameters:
genre (
str) –id_ (
str) –_check_id (
bool) –_lowercase (
bool) –_strip_tex (
typing.Optional[collections.abc.Iterable[str]]) –
- classmethod from_entry(key, entry, **_kw)[source]
Factory method to initialize a Source instance from a pybtex.database.Entry.
- Parameters:
key (
str) – Citation key, e.g. a key in pybtex.database.BibliographyData.entries.entry – pybtex.database.Entry
_kw – Keyword arguments passed through to cls.__init__
- Return type:
- classmethod from_bibtex(bibtex_string, lowercase=False, _check_id=True)[source]
Initialize a Source object from the data in a BibTeX record.
Note
We support somewhat limited BibTeX syntax. Thus, it’s best to feed preprocessed BibTeX (e.g. using a tool such as bibtool). In particular, we assume all key-value-pairs to be on single lines, i.e. we don’t support multiline values. Alternatively, you can parse BibTeX data using pybtex and feed pybtex.database.Entry objects to
Source.from_entry().- Parameters:
bibtex_string (
str) –lowercase (
bool) –_check_id (
bool) –
- Return type:
- static split_names(s)[source]
Splits string like author lists.
- Parameters:
s (
str) –- Return type:
list[bibtexparser.middlewares.names.NameParts]
- static reformat_names(s)[source]
Reformats names using <first last> format.
>>> Source.reformat_names('Max Meier and Müller, Hans') 'Meier, Max & Hans Müller'
- Parameters:
s (
str) –- Return type:
str
- bibtex()[source]
Represent the source in BibTeX format.
- Return type:
str- Returns:
string encoding the source in BibTeX syntax.
- get_with_translation(key)[source]
Return the value for a key, possibly with an english translation.
- Parameters:
key (
str) –- Return type:
str
- property norm_pages: str
Replace the LaTeX double-hyphen used for page ranges with single hyphen.
- text(markdown=False)[source]
Linearize the bib source according to the rules of the unified style.
- Parameters:
markdown – If True, italics are used to distinguish volume titles.
- Return type:
str
Book: author. year. booktitle. (series, volume.) address: publisher.
Article: author. year. title. journal volume(issue). pages.
Incollection: author. year. title. In editor (ed.), booktitle, pages. address: publisher.