babble

package module
v0.0.0-...-b5cd662 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2016 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Babble GoDoc

Package babble implements a finite Markov chain sentence generator, inspired by Jeremy Singer-Vine's excellent markovify for Python. Eric Bower's sentences package is used for sentence extraction.

Usage

package main

import (
        "fmt"
        "io/ioutil"

        "github.com/ragnar-johannsson/babble"
)

func main() {
        // The Problems of Philosophy by Bertrand Russell
        b, _ := ioutil.ReadFile("./texts/pg5827.txt")
        t := babble.NewTextModel(string(b), babble.DEFAULT_STATE_SIZE)

        fmt.Println(t.MakeShortSentence(140))
        // Our nature is the characteristic of the universe, we have discovered so far.
}

License

BSD 2-Clause. See the LICENSE file for details.

Documentation

Index

Examples

Constants

View Source
const (
	DEFAULT_SENTENCE_TRIES    = 10
	DEFAULT_MAX_OVERLAP_RATIO = 0.7
	DEFAULT_MAX_OVERLAP_TOTAL = 15
	DEFAULT_STATE_SIZE        = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

func NewChain

func NewChain(corpus []([]string), stateSize int) Chain

func (*Chain) Generate

func (c *Chain) Generate() string

type TextModel

type TextModel struct {
	Tries           int
	MaxOverlapTotal int
	MaxOverlapRatio float64
	// contains filtered or unexported fields
}

func NewTextModel

func NewTextModel(inputText string, stateSize int) TextModel

func (*TextModel) MakeSentence

func (t *TextModel) MakeSentence() string
Example
package main

import (
	"fmt"
	"io/ioutil"

	"github.com/ragnar-johannsson/babble"
)

func main() {
	b, _ := ioutil.ReadFile("./texts/pg5827.txt")
	t := babble.NewTextModel(string(b), babble.DEFAULT_STATE_SIZE)

	fmt.Println(t.MakeSentence())
}
Output:

func (*TextModel) MakeShortSentence

func (t *TextModel) MakeShortSentence(lengthLimit int) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL