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

Install from PyPi:

pip install totolo

Or clone this repository and copy the totolo directory wherever you need it. No 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:

    >>> 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-1.5.2.dev202404281659.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

totolo-1.5.2.dev202404281659-py2.py3-none-any.whl (23.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file totolo-1.5.2.dev202404281659.tar.gz.

File metadata

File hashes

Hashes for totolo-1.5.2.dev202404281659.tar.gz
Algorithm Hash digest
SHA256 f2e0568fe619939bf1aeb8cca0fdc6a3fc8553f4d5a86d4aa218597b48753864
MD5 e536b17aa9819a159c8e767037cbc913
BLAKE2b-256 b4da2c7e3199473a5f15234caf55453ebfdc4f4833b536897a49261efd9163fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for totolo-1.5.2.dev202404281659-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f80b9b1df90965c6c0ea42a3b478f2d7a815e5dedc905f27dc41cb3202f5d17d
MD5 3ec710ddb66961eb9786574d91c0366e
BLAKE2b-256 219e249abab143bcb6665c66c1a8291032c8eb9cd4b88d5c73ac57fdcf61b4b4

See more details on using hashes here.

Supported by

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