mchain
v0.2.0
Published
Markov chain
Downloads
4
Readme
mchian
Markov chain
Installation
npm install mchain
Usage
import mchain from 'mchain';
var data: string[][] = [
[null, "私", "は"],
["私", "は", "りんご"],
["は", "りんご", "が"],
["りんご", "が", "好き"],
["が", "好き", "だ"],
["好き", "だ", null],
[null, "彼", "は"],
["彼", "は", "みかん"],
["は", "みかん", "が"],
["みかん", "が", "好き"],
["が", "好き", "だ"],
["好き", "だ", null]
];
var result = mchain<string>(
() => data.filter(xs => xs[0] === null),
previous => data.filter(xs => xs[0] === previous));
console.log(result.map(xs => xs.join('')).join(''));
// Output:
// 私はりんごが好きだ or
// 私はみかんが好きだ or
// 彼はりんごが好きだ or
// 彼はみかんが好きだ
License
The MIT License. See LICENSE.