Giter VIP home page Giter VIP logo

chatterbox's Introduction

Chatterbox

Generates text based on a context-free grammar.

For example, given this grammar:

start -> "The" _ <noun> _ "is" _ <adj> "." | "A" _ <adj> _ <noun> "." ;
noun -> "house" | "cat" ;
adj -> "green" | "big" ;

will generate one of the following:

The house is green.
The house is big.
The cat is green.
The cat is big.
A big house.
A big cat.
A green house.
A green cat.

The full example listing:

const { parse, validate, generate } = require("@aradzie/chatterbox");

const grammar = parse(`
start ->
    "The " <noun> " is " <adj> "."
  | "A " <adj> " " <noun> "."
  ;
noun ->
    "house"
  | "cat"
  ;
adj ->
    "green"
  | "big"
  ;
`);

validate(grammar);

console.log(generate(grammar));

This project is based on book Dive Into Python which included an example of how to generate mock philosophy based on a context-free grammar. I had a good laugh reading mock Kant passages:

The noumena are the clue to the discovery of, therefore,our judgements. I assert, certainly, that the architectonic of human reason is just as necessary as, therefore, our concepts; still, the things in themselves are the clue to the discovery of, in the case of necessity, the never-ending regress in the series of empirical conditions. It must not be supposed that the paralogisms, irrespective of all empirical conditions, can be treated like the thing in itself, as is shown in the writings of Galileo. In the case of the transcendental aesthetic, the Categories are just as necessary as, in other words, our faculties, by virtue of pure reason. (The phenomena can not take account of the Ideal of practical reason, and the Ideal of practical reason is a representation of time.) Necessity would thereby be made to contradict, in the case of the thing in itself, the thing in itself, yet the transcendental unity of apperception constitutes the whole content for philosophy.

I ported the original grammar XML files to a new syntax which is more readable. The files are available in the grammar directory.

chatterbox's People

Contributors

aradzie avatar dependabot[bot] avatar

Watchers

 avatar  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.