meaningless.utilities package

Exceptions

exception meaningless.utilities.exceptions.BaseError

Bases: Exception

exception meaningless.utilities.exceptions.InvalidPassageError(book, chapter_from, passage_from, chapter_to, passage_to, translation)

Bases: BaseError

An exception thrown when processing a non-existent passage (or passage range)

exception meaningless.utilities.exceptions.InvalidSearchError(url)

Bases: BaseError

An exception thrown when searching for an invalid passage on the Bible Gateway site

exception meaningless.utilities.exceptions.TranslationMismatchError(extractor_translation, file_translation)

Bases: BaseError

An exception thrown when using the extractor to read a file, and both use different translations

exception meaningless.utilities.exceptions.UnsupportedTranslationError(translation)

Bases: BaseError

An exception thrown when handling translations that are not currently supported

YAML File Interface

meaningless.utilities.yaml_file_interface.read(data_file)

A helper function to read a YAML data file

Parameters:

data_file (str) – Path the data file to read

Returns:

Contents of the file as an object. Raises an exception when a read problem occurs.

Return type:

dict

meaningless.utilities.yaml_file_interface.write(data_file, document)

A helper function to write to a YAML data file. Note that Unix line endings (LF) are used.

Parameters:
  • data_file (str) – Path to the data file to write to

  • document (dict) – In-memory YAML structure, usually a dictionary

Returns:

Returns 1 on success. Raises an exception when a write problem occurs.

Return type:

int

JSON File Interface

meaningless.utilities.json_file_interface.read(data_file)

A helper function to read a JSON data file

Parameters:

data_file (str) – Path the data file to read

Returns:

Contents of the file as an object. Raises an exception when a read problem occurs.

Return type:

dict

meaningless.utilities.json_file_interface.write(data_file, document)

A helper function to write to a JSON data file.

Parameters:
  • data_file (str) – Path to the data file to write to

  • document (dict) – In-memory JSON structure, usually a dictionary

Returns:

Returns 1 on success. Raises an exception when a write problem occurs.

Return type:

int

XML File Interface

meaningless.utilities.xml_file_interface.read(data_file)

A helper function to read a XML data file. Note that the input data must adhere to the following conventions:

  1. The top-level tag is called ‘root’.

  2. All <book> tags must have a “tag” attribute.

  3. All <chapter> tags must have a “tag” attribute and must be nested within a <book> tag.

  4. All <passage> tags must have a “tag” attribute and must be nested within a <chapter> tag.

If the XML data file is valid, the returned object will differ from the XML data file in the following ways:

  1. Leading and trailing underscores will be removed.

  2. All other underscores will be converted into spaces.

  3. All keys will be converted to title case (all first letters of each word are capitalised)

Parameters:

data_file (str) – Path to the data file to read

Returns:

Contents of the file as an object. Raises an exception when a read problem occurs.

Return type:

dict

meaningless.utilities.xml_file_interface.write(data_file, document)

A helper function to write to a XML data file. Note that the input data must adhere to the following conventions:

  1. If a top-level key is named ‘Info’, it must be a mapping of string keys to string values.

  2. All other top-level keys map to a 3-layer dictionary or similar data structure with key-value pairs.

  3. The 3rd layer of this data structure is a mapping of string keys to string values.

Parameters:
  • data_file (str) – Path to the data file to write to

  • document (dict) – In-memory data structure, usually a dictionary

Returns:

Returns 1 on success. Raises an exception when a write problem occurs.

Return type:

int

CSV File Interface

meaningless.utilities.csv_file_interface.read(data_file)

A helper function to read a CSV data file. Note that the file data must adhere to the following conventions:

  1. A header row is included as the first line.

  2. All data is contained within the first 8 columns.

Parameters:

data_file (str) – Path the data file to read

Returns:

Contents of the file as an object. Raises an exception when a read problem occurs.

Return type:

dict

meaningless.utilities.csv_file_interface.write(data_file, document)

A helper function to write to a CSV data file. Note that the input data must adhere to the following conventions:

  1. The input document is a dictionary.

  2. There is a top-level key called ‘Info’, with string values for the following keys: ‘Language’, ‘Translation’, ‘Timestamp’, ‘Meaningless’

  3. There is at least one other top-level key-value pair, mapping to a dictionary of dictionaries.

  4. There are no keys or values with the value set as None (excluding the sub-keys under the top-level ‘Info’ key).

Parameters:
  • data_file (str) – Path to the data file to write to

  • document (dict) – In-memory data structure, usually a dictionary

Returns:

Returns 1 on success. Raises an exception when a write problem occurs.

Return type:

int