markovchain
markovchain copied to clipboard
support more than one chain at a time
It appears in light testing, that this library produces unexpected results if you start() one process while another is still going.
Related to this, it would be great for the API to offer a way to load up from a file, then use the chain many times without reloading.
Hi
I just released a new version so you can do something like below where you can make multiple calls to the process property function to get multiple results.
var MarkovChain = require('./index').MarkovChain
, quotes = new MarkovChain({ files: './test.txt' })
var useUpperCase = function(wordList) {
var tmpList = Object.keys(wordList).filter(function(word) { return word[0] >= 'A' && word[0] <= 'Z' })
return tmpList[~~(Math.random()*tmpList.length)]
}
quotes
.start(useUpperCase)
.end(5)
.process(function(err, s) {
console.log('#1', s)
})
.process(function(err, s) {
console.log('#2', s)
})
I'm not sure about your 1st bug unless you passed a function through to the start property function. There was a bug with using functions that I fixed so if that's the case please try again with the new version I just deployed to npm.
If that doesn't fix it, could you produce some sample code where it goes wrong?
Thank you, I will try the updates.
Here is what would help more, though. Move the file reading up earlier in the steps, so that everything is populated and ready to go when the tool is called on to generate data. Then the actual generation would not re-read the files each time (!) and would not need to be a callback - much more convenient to use deep in data processing code.
Hi, sorry for the late reply.
I will consider rewriting it to read only once. I forgot my initial reasoning for this, possibly just related to the way I was using this.
Anyway, will try to get to it, but PRs also accepted!