Giter VIP home page Giter VIP logo

margopher's Introduction

margopher

Build Status

Markov chain random text generator

How it Works

TL;DR You give it some text, it gives you a random (and sane) chunk out of this text.

Basically margopher is based on Markov chain statistical model, except that it starts by choosing a random prefix from the states dictionary to ensure more randomness.

It starts by parsing the input text and putting it into states dictionary then starts generating the output sentence.

The generator will keep generating words till it encounters a terminal word (a word that ends in any of .,:;?!)

States is a map contains prefix as keys and suffix as values.

Prefix is an array of two consecutive words from the original text.

Suffix is a slice of all the words that occur after a given prefix.

Installation

go get github.com/aonemd/margopher

Usage

  1. Import the package
import "github.com/aonemd/margopher"
  1. Create new margopher object
m := margopher.New()
  1. Read input text using one of three parsing methods:
  • ReadText(text string)
text := "Cats are nice. Cats love pizza, and Cats hates dogs."
fmt.Println(m.ReadText(text))
  • ReadFile(filePath string)
filePath := "../file.txt"
fmt.Println(m.ReadFile(filePath))
  • ReadURL(url string)
url := "https://github.com/aonemd/margopher"
fmt.Println(m.ReadURL(url))
  1. You can see the input parsed into a dictionary of States using margopher.StateDictionary():
  • It returns a dicitonary of this signature map[[2]string][]string.
  • The words are unordered because Go maps do not keep order.
fmt.Println(m.StateDictionary())

Feedback

I wrote this simple project particularly to learn Go so any feedback is more than welcome. If you have any, please open an issue or send a pull request.

License

See LICENSE.

margopher's People

Contributors

aonemd avatar

Watchers

James Cloos 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.