GithubHelp home page GithubHelp logo

hevia / grampy Goto Github PK

View Code? Open in Web Editor NEW
20.0 1.0 3.0 13 KB

A lightweight and easily readable context-free grammar generator!

License: MIT License

Python 100.00%
python context-free-grammar story-generation text-generation procedural

grampy's Introduction

GramPy

An easily readable context-free grammar text generator!

generate_items() function cotrbuted by https://github.com/tgsachse

Big thanks to https://github.com/Caleb-Shepard for help with the thinking this through!

Inspired by Daniel Shiffman's CFG coding challenge: https://www.youtube.com/watch?v=8Z9FRiW2Jlc

If you're new to using CFG's for text generation Daniel Shiffman's video on the subject is a great resource: https://www.youtube.com/watch?v=Rhqk9HYiB7Q

How to use

  • Our "Rules" dict is composed of a string key and is a list of lists
  • The generate_items() function is used to insert our list of strings element by element.
  • The expansion() function takes an input list and compares each element to see if it is one of our Rule's keys. If so it then randomly selects a corresponding list from that key value and replaces it in the list. After the initial for loop we perform another check to make sure our list has expanded correctly and if so we call it recursively until our list contains no more non-terminal values

What to do

  • Provide more detailed examples of using GramPy with more then just text
  • Provide functions to read and import grammars from JSON, and CSV values

grampy's People

Contributors

hevia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.