Skip to content

Markov Chain Generator focussed on generating headlines or single sentences

License

Notifications You must be signed in to change notification settings

e-dard/headlines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

headlines

GoDoc

Markov Chain Generator focussed on generating headlines or single sentences.

What?

Markov Chains.

This package generates a Markov Chain from a data stream of line-separated phrases.

Usage

A minimal implementation follows. In this case we're generating 100 phrases, each of which being a maximum of 20 words long. When generating each phrase the previous two words are used to select the next word in the phrase.

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/e-dard/dailymarkov/generator"
)

func main() {
	if fi, err = os.Open("/tmp/foo.txt"); err != nil {
		log.Fatal(err)
	}
	defer fi.Close()

	chain := generator.NewChain(2)
	if err := chain.Build(fi); err != nil {
		log.Fatal(err)
	}

	for i := 0; i < 100; i++ {
		text, err := chain.Generate(20)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(text)
	}
}

About

Markov Chain Generator focussed on generating headlines or single sentences

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages