chain

package
v0.0.0-...-c8fda3c Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2016 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package chain is used to generate fake comments.

The chain is built using a corpus of existing data, preferably in the style of the comments that you wish to generate.

A chain consists of a prefix followed by all the possible words that appeared after the prefix in the training data. A prefix may consist of one or more words, and is consistent for an entire chain.

There are helper methods which try to optimize the output for seeming real-ish. A comment will, by default, have a small number of paragraphs, and the paragraphs will be neither particularly short, nor extremely long. Where possible, the generated output will end with punctuation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	Nodes     []*Node
	PrefixLen int `json:"prefix_len"`
}

Chain contains sentence fragments that can be recombined.

func FromFile

func FromFile(path string) (*Chain, error)

FromFile unmarshalls a stored JSON chain.

func NewChain

func NewChain(prefixLen int) *Chain

NewChain creates an empty chain. The prefix of each node will be prefixLen words long.

func (*Chain) Build

func (c *Chain) Build(r io.Reader)

Build creates a new chain from newline delimited text.

func (*Chain) Generate

func (c *Chain) Generate() string

Generate creates multiple paragraphs.

func (*Chain) GenerateParagraph

func (c *Chain) GenerateParagraph() string

GenerateParagraph creates a single paragraph.

func (*Chain) ToFile

func (c *Chain) ToFile(path string) error

ToFile marshalls a chain to a file in JSON format.

type Node

type Node struct {
	Key       string
	Fragments []string
}

Node connects a key with all the possible words that may follow it. A key may be one or more words. This number will be consistent for an entire chain (collection of nodes).

Jump to

Keyboard shortcuts

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