Adding and updating docs for bibtex_customizations
+'''
+`bibtexparser` customizations
+'''
import re
@@ -5,15 +8,42 @@ HOWPUB_URL_RE = re.compile(r'\\url{([^}]+)}')
def customizations(record):
- """Use some functions delivered by the library
+ """
+ Standard owmeta `bibtexparser` customizations
+
+ Includes: `url`, `note_url`, `doi`, `listify`, and `author`
+
- :param record: a record
- :returns: -- customized record
+ Parameters
+ ----------
+ record : dict
+ the record
+
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
"""
return url(note_url(doi(listify(author(record)))))
def listify_one(record, name):
+ '''
+ If the given field `name` does not have a `list` value, then updates the record by
+ turning that value into a list.
+
+ Parameters
+ ----------
+ record : dict
+ The record to update
+ name : str
+ The name of the field to turn into a list
+
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
+ '''
if not isinstance(record[name], (list, tuple)):
record[name] = [record[name]]
elif isinstance(record[name], tuple):
@@ -22,6 +52,9 @@ def listify_one(record, name):
def listify(record):
+ '''
+ Turns every value in the record into a list except for ``ENTRYTYPE`` and ``ID``
+ '''
# Since some items can be multiples, it simplifies code in most places to
# just make everything a list, even if it cannot appear more than once in
# the properly formatted record.
@@ -33,11 +66,17 @@ def listify(record):
def doi(record):
"""
+ Adds a doi URI to the record if there's a ``doi`` entry in the record
- :param record: the record.
- :type record: dict
- :returns: dict -- the modified record.
+ Parameters
+ ----------
+ record : dict
+ the record to update
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
"""
doi = record.get('doi')
if doi is not None:
@@ -59,12 +98,17 @@ def doi(record):
def author(record):
"""
- Split author field by 'and' into a list of names.
+ Split author field by the string 'and' into a list of names.
- :param record: the record.
- :type record: dict
- :returns: dict -- the modified record.
+ Parameters
+ ----------
+ record : dict
+ the record
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
"""
if "author" in record:
if record["author"]:
@@ -75,6 +119,19 @@ def author(record):
def note_url(record):
+ '''
+ Extracts URLs from ``note`` entries in the given record
+
+ Parameters
+ ----------
+ record : dict
+ the record
+
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
+ '''
note = record.get('note')
if note is not None:
for n in note:
@@ -88,6 +145,22 @@ def note_url(record):
def url(record):
+ r'''
+ Merges any URL from ``\url{...}`` in ``howpublished``, and any existing ``link`` or
+ ``url`` values in the record and normalizes them into a `list` in the ``url`` field of
+ the record
+
+ Parameters
+ ----------
+ record : dict
+ the record
+
+ Returns
+ -------
+ dict
+ the given `record` with any updates applied
+ '''
+
u = record.get('howpublished', '')
md = HOWPUB_URL_RE.match(u)
if md:
