markov-ja

1.0.12 • Public • Published

markov-ja

Requirements

You need to install MeCab before using this package.

How to use

$ npm install -S markov-ja

Try this:

const MarkovJa = require('markov-ja')

var markov = new MarkovJa()

// Maybe you want to load the database from file…?
const path = 'triplets_db.json'
markov.loadDatabase(fs.readFileSync(path, 'utf-8'))

var text = fs.readFileSync('in.txt', 'utf-8')
markov.learn(text)

// Now your original texts are generated with the power of markov chain
console.log(markov.generate().join('\n'))

// Maybe you want to save the database to file…?
fs.writeFileSync(path, markov.exportDatabase(), 'utf-8')
// You can change the options for mecab command
markov.mecab.commandOptions = '-d /usr/local/lib/mecab/dic/mecab-ipadic-neologd/'

For more information, please see my source code.

There are Japanese jsdoc in the code.

Readme

Keywords

none

Package Sidebar

Install

npm i markov-ja

Weekly Downloads

22

Version

1.0.12

License

MIT

Unpacked Size

13.2 kB

Total Files

13

Last publish

Collaborators

  • private_yusuke