markov 1.0.6
A generic markov chain library
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
markov
A simple library that provides templated types for markov chains.
Usage
import std.stdio;
import markov;
void main()
{
// Build states for 1, 2, and 3 leading elements.
auto chain = MarkovChain!string(1, 2, 3);
chain.train("foo", "bar", "foo");
chain.train("bar", "foo", "bar");
chain.seed("foo");
foreach(i; 0 .. 10)
{
// bar foo bar foo bar . . .
writeln(chain.generate);
}
}
Serialization
Simple functions for encoding/decoding markov chains to and from JSON are included.
void main()
{
// . . .
// Serialize the markov chain into JSON.
string encoded = chain.toJson;
// Unserialize the JSON-encoded markov chain.
MarkovChain!string decoded = encoded.toMarkovChain!string;
}
In addition, helpers to write encoded data to and from files are also included.
void main()
{
// . . .
// Write a markov chain to a file.
chain.writeJson(File("markov", "w"));
// Read a markov chain from a file.
MarkovChain!string decoded = File("markov", "r").readMarkovChain!string;
}
License
MIT
- Registered by Mihail K
- 1.0.6 released 8 years ago
- mintyfresh/markov
- MIT
- Copyright © 2015-2016, Mihail K
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.10 2018-May-02 1.0.9 2016-Apr-10 1.0.8 2016-Mar-25 1.0.7 2016-Feb-07 1.0.6 2016-Feb-07 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
207 downloads total
-
- Score:
- 1.6
- Short URL:
- markov.dub.pm