Skip to main content

A package to generate grammatically valid but semantically nonsensical English sentences.

Project description

Python application

Green Ideas

Green Ideas is a Python package designed to generate grammatically valid but semantically nonsensical sentences. It is effectively a generative grammar engine, employing recursive rewrite rules to create sentence structures. It can then convert these structures into templates compatible with the twaddle package for language templating.

Features

Greenideas defines a grammar engine which expands a root sentence node into a full sentence tree, according to a variety of user-defined rules. Documentation for defining these rules will come at a later date. The package includes a pre-written set of rules which produce (mostly) grammatically valid English sentences.

The key features of the package are:

  • Generation of trees describing valid English sentence structures
  • Support for recursive rewrite rules for sentence structure generation.
  • Converting sentence trees into twaddle-compatible templates.
  • Modular design allowing for easy extension and modification of grammar rules.

Installation

The package can be downloaded manually from Github or installed via pip:

pip install greenideas

The package uses Poetry for dependency management, dependencies can be installed by running

poetry install

Usage

To use the greenideas package, you can (or at least you will be able to, at some point) import the main classes from the package, provide the location of your twaddle dictionaries, and start generating sentences. The main.py file offers a simple example:

import readline  # noqa: F401
import sys

from twaddle.runner import TwaddleRunner

from greenideas.grammar_engine import GrammarEngine
from greenideas.parts_of_speech.pos_types import POSType
from greenideas.rules.default_english_rules.default_rules import default_rules
from greenideas.twaddle.default_formatters.default_formatting_handlers import (
    default_formatting_handlers,
)
from greenideas.twaddle.twaddle_formatter import TwaddleFormatter


def main():
    if len(sys.argv) < 2:
        print("argument required: path to directory containing dictionary files")
        return
    dictionary_path = sys.argv[1]
    twaddle_runner = TwaddleRunner(dictionary_path)

    engine = GrammarEngine()
    engine.add_ruleset(default_rules)
    tree = engine.generate_tree(POSType.S)
    print(tree)

    formatter = TwaddleFormatter()
    for type, handler in default_formatting_handlers.items():
        formatter.register_formatting_handler(type, handler)

    twaddle_string = formatter.format_as_sentence(tree)
    print(twaddle_string)
    print(twaddle_runner.run_sentence(twaddle_string))

An official set of twaddle dictionaries for use with the default English language rules is available at https://github.com/chrishengler/greenideas-dict

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

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

greenideas-0.6.0.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

greenideas-0.6.0-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

Details for the file greenideas-0.6.0.tar.gz.

File metadata

  • Download URL: greenideas-0.6.0.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for greenideas-0.6.0.tar.gz
Algorithm Hash digest
SHA256 05c1f9cb2f7cad2e2cc7d64ae8a66738b3cfc5a9112afcc4165b1a77210be7fc
MD5 10fc17448622063971eb364edb7677b4
BLAKE2b-256 0c5d716a9f472b1ea6115e32543b6e0784842bf0d4b849feff81fe9258bef483

See more details on using hashes here.

Provenance

The following attestation bundles were made for greenideas-0.6.0.tar.gz:

Publisher: python-publish.yml on chrishengler/greenideas

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

File details

Details for the file greenideas-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: greenideas-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 44.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for greenideas-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b4543625b1f6def1cb4bf38c839fa493e2e06fd8d87459546c127f484f2f5b2
MD5 f071e9e4ee840c8480f78ec7200a5030
BLAKE2b-256 78046ce0cd1c4c3f64a1e64bea94c497ace7a2df715f0ecc74809b3984d3b814

See more details on using hashes here.

Provenance

The following attestation bundles were made for greenideas-0.6.0-py3-none-any.whl:

Publisher: python-publish.yml on chrishengler/greenideas

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