Description
A Markov chain algorithm optimized by memory consumption generates text by creating a statistical model of potential textual Suffixes for a given Links.
Generating random text: a Markov chain algorithm
A Markov chain algorithm generates text by creating a statistical model of potential textual suffixes for a given links of chain.
Markov Chain Algorithm alternatives and similar packages
Based on the "Text Processing" category.
Alternatively, view Markov Chain Algorithm alternatives based on common mentions on social networks and blogs.
-
micro-editor
A modern and intuitive terminal-based text editor -
sh
A shell parser, formatter, and interpreter with bash support; includes shfmt -
go-humanize
Go Humans! (formatters for units to human friendly sizes) -
goldmark
:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured. -
bluemonday
bluemonday: a fast golang HTML sanitizer (inspired by the OWASP Java HTML Sanitizer) to scrub user generated content of XSS -
commonregex
๐ซ A collection of common regular expressions for Go -
mxj
Decode / encode XML to/from map[string]interface{} (or JSON); extract values with dot-notation paths and wildcards. Replaces x2j and j2x packages. -
Dataflow kit
Extract structured data from web sites. Web sites scraping. -
htmlquery
htmlquery is golang XPath package for HTML query. -
xpath
XPath package for Golang, supports HTML, XML, JSON document query. -
omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc. -
Koazee
A StreamLike, Immutable, Lazy Loading and smart Golang Library to deal with slices. -
html-to-markdown
โ๏ธ Convert HTML to Markdown. Even works with entire websites and can be extended through rules. -
go-pkg-rss
This package reads RSS and Atom feeds and provides a caching mechanism that adheres to the feed specs. -
go-edlib
๐ String comparison and edit distance algorithms library, featuring : Levenshtein, LCS, Hamming, Damerau levenshtein (OSA and Adjacent transpositions algorithms), Jaro-Winkler, Cosine, etc... -
gotabulate
Gotabulate - Easily pretty-print your tabular data with Go -
goribot
A simple golang spider/scraping framework,build a spider in 3 lines. -
goq
A declarative struct-tag-based HTML unmarshaling or scraping package for Go built on top of the goquery library -
xquery
XQuery lets you extract data from HTML/XML documents using XPath expression. -
github_flavored_markdown
GitHub Flavored Markdown renderer with fenced code block highlighting, clickable header anchor links. -
gospider
โก Light weight Golang spider framework | ่ฝป้็ Golang ็ฌ่ซๆกๆถ -
go-pkg-xmlx
Extension to the standard Go XML package. Maintains a node tree that allows forward/backwards browsing and exposes some simple single/multi-node search functions. -
strutil-go
Golang metrics for calculating string similarity and other string utility functions -
editorconfig-core-go
EditorConfig Core written in Go -
shell2telegram
Telegram bot constructor from command-line -
did
A golang package to work with Decentralized Identifiers (DIDs) -
regroup
Match regex group into go struct using struct tags and automatic parsing -
go-fixedwidth
Encoding and decoding for fixed-width formatted data -
go-zero-width
Zero-width character detection and removal for Go -
cat
Extract text from plaintext, .docx, .odt and .rtf files. Pure go. -
align
A general purpose application and library for aligning text. -
pagser
Pagser is a simple, extensible, configurable parse and deserialize html page to struct based on goquery and struct tags for golang crawler
Access the most powerful time series database as a service
Do you think we are missing an alternative of Markov Chain Algorithm or a related project?
README
Markov Chain Algorithm

A Markov chain algorithm optimized by memory consumption generates text by creating a statistical model of potential textual Suffixes for a given Links.
Generating random text: a Markov chain algorithm
Based on the program presented in the "Design and Implementation" chapter of The Practice of Programming (Kernighan and Pike, Addison-Wesley 1999). See also Computer Recreations, Scientific American 260, 122 - 125 (1989).
A Markov chain algorithm generates text by creating a statistical model of potential textual suffixes for a given links of chain. Consider this text:
One fish one fish one fish two fish red fish blue fish
Our Markov chain algorithm would arrange this text into this set of links and suffixes, or "chain": (This table assumes a link length of two words.)
Link Suffix
======== ==================
"" "" [One, 1]
"" One [fish, 3]
One fish [One, 2], [two, 1]
fish one [fish,2]
fish two [fish,1]
Two fish [red,1]
fish red [fish, 1]
red fish [blue, 1]
blue fish [`END`, 1]
To generate text using this table we select an initial links ("One fish", for example), choose one of the suffixes associated with that prefix at random with probability determined by the input statistics ("One, 2", "fish, 1"), and then create a new links by removing the first word from the link and appending the suffix (making the new link is "fish one" and second "fish two"). Repeat this process until we can't find any suffixes for the current link or we exceed the word limit. (The word limit is necessary as the chain table may contain cycles.)
Current optimized algorithm support similar logic described at following example: https://golang.org/doc/codewalk/markov/, but optimized for memory consumption when base text contains lot of identical suffixes for the same link. E.g. in example above following pair of link and suffexes below would contain 2 same suffixes for "one" and 1 for "fish"
Link Suffix
======== ==================
... ...
One fish one, one, fish
but in optimized version pairs of link and related suffixes would be created in the following way when each suffix contains number of appearances with the appropriate link.
Link Suffix
======== ==================
... ...
One fish [One, 2], [two, 1]
Note: keep in mind if your text not long or you're suggesting it is not contains lot of duplicated pair of link and suffixes initial version of algorithm might be more optimized from performance prospectives.
Enjoy coding!!
Example
c := NewChain(2) // Words per Links
c.Build(strings.NewReader("One fish two fish red fish blue fish))"
text := c.Generate(250) // Generate text.
fmt.Println(text)
Contributing
We welcome pull requests, bug fixes and issue reports.
Before proposing a change, please discuss your change by raising an issue.
Authors
- Valentyn Ponomarenko - Initial work - P-A-R-U-S
License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
*Note that all licence references and agreements mentioned in the Markov Chain Algorithm README section above
are relevant to that project's source code only.