Skip to main content

The Python interface to themeontology.org.

Project description

PyPI version codecov Life cycle downloads License: MIT

totolo

This repository contains a Python package, totolo, for working with data from the Theme Ontology theming repository.

Installation

pip install totolo

Or clone this repository and copy the totolo directory wherever you need it. No package dependencies are required.

Basic Usage

    #: import package
    >>> import totolo

    #: get the latest main branch version of the ontology
    >>> ontology = totolo.remote()
    >>> print(ontology)
<2945 themes, 4475 stories>

    #: write it or read it locally
    >>> ontology.write("/home/mo/themes")
    >>> ontology = totolo.files("/home/mo/themes")
    >>> print(ontology)
<2945 themes, 4475 stories>

Explore the themes

    #: go over all the themes and find the ones you want
    >>> for theme in ontology.themes():
    ...     if "romantic love" in theme.name:
    ...         print(theme)
b'personal freedom vs. romantic love'[3]
b'romantic love'[3]

    #: check the definition of a theme
    >>> love = ontology.theme["love"]
    >>> love.print()
    (...)

Explore the stories

    >>> story = ontology.story["movie: Ran (1985)"]
    >>> for weight, theme in story.iter_themes():
    ...     print(f"{weight:<15} {theme.name}")
Choice Themes   betrayal
Choice Themes   the lust for power
(...)

Convert it to a pandas dataframe

    >>> df = ontology.dataframe()
    >>> df
                                 story_id             title        date                      theme        weight
0                 theamericanshortstory01  The Music School        1974      human self-reflection  Major Themes
1                 theamericanshortstory01  The Music School        1974                     murder  Major Themes
...                                   ...               ...         ...                        ...           ...
52453  videogame: Final Fantasy VI (1994)  Final Fantasy VI  1994-04-02  feral children in society  Minor Themes
52454  videogame: Final Fantasy VI (1994)  Final Fantasy VI  1994-04-02             father and son  Minor Themes

[52455 rows x 5 columns]

Snippets

List official versioned releases of the ontology

    list(totolo.remote.versions())

Load the v2023.06 release

    ontology = totolo.remote.version('v2023.06')

Create an excel sheet with all the usages of the theme "loyalty" as well as any child theme of the same

    df = ontology.theme['loyalty'].descendants().dataframe(motivation=True, descriptions=True)
    df.to_excel("/mnt/d/repos/themelist-loyalty.xlsx", "loyalty")

Find theme entries in stories according to some criteria. For example, find empty motivations

    empty_motivations = [
        (story, weight, part)
        for story in ontology.stories()
        for weight, part in story.iter_theme_entries()
        if part.motivation.strip() == ""
    ]

Getting Help

If you encounter a bug, please file a minimal reproducible example on GitHub issues. For feature requests and other matters, please post on the GitHub discussions board.

Code Test Coverage

codecov

License

All code in this repository is published with the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

totolo-2.0.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

totolo-2.0.0-py2.py3-none-any.whl (31.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file totolo-2.0.0.tar.gz.

File metadata

  • Download URL: totolo-2.0.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for totolo-2.0.0.tar.gz
Algorithm Hash digest
SHA256 46f0f3bad57fbaf2ba6dc6a47c1644de3ca073c0c4b2e5251347030dd0cc39f7
MD5 21039bbc15c6a06a9d27d4291d51bb26
BLAKE2b-256 f0a4f0cb48e8868f79f5261951a6acddce9a7d9c722e284860aa431cdad12bb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for totolo-2.0.0.tar.gz:

Publisher: publish.yaml on theme-ontology/python-totolo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file totolo-2.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: totolo-2.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for totolo-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2f82fe5b81168a14f5a2347f429a3647fe54f795e849456181aa270146e0bb45
MD5 9cc391d7aec35da8dcd855c803a49b04
BLAKE2b-256 70d6dfb179de903411c472475f8f4d3b0d3a346b82551aae24c32290e05beb1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for totolo-2.0.0-py2.py3-none-any.whl:

Publisher: publish.yaml on theme-ontology/python-totolo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page