Skip to content

eminano/markov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markov

GoDoc

Simple library using markov chains for n-gram modeling.

This library uses an in memory map storing the current state as key and the candidate states with the associated probability as value.

Main features are:

  • Flexible ngram processing (support starting at 2-grams)
  • Safe for concurrent use
  • Easy text processing support via io.Reader interface

Usage

package main

import (
	"fmt"
	"strings"

	"github.com/eminano/markov"
)

func main() {
	// Create a chain for trigrams (3-grams)
	chain, _ := markov.NewNGramChain(3)

	// Parse text to process
	text := strings.NewReader(`
	I am batman. 
	I am groot.
	I am your father`)

	chain.ProcessText(text)

	// generate random text based on input
	output := chain.GenerateRandomText(10)

	// get a random candidate for the prefix
	candidate := chain.GetCandidate("I am")

	// get the probability of a given candidate for a prefix
	probability := chain.CandidateProbability("I am", "batman.")
}

About

Markov library for n-gram processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages