diff options
Diffstat (limited to 'js/bird-words/README.md')
-rw-r--r-- | js/bird-words/README.md | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/js/bird-words/README.md b/js/bird-words/README.md index be12836..81940d7 100644 --- a/js/bird-words/README.md +++ b/js/bird-words/README.md @@ -10,4 +10,39 @@ In the future I would like to modify this such that I am able to present a scrip The @NOUN@ of @ADJECTIVE@ @NOUN@ is known for @MARKOV 13@ ``` -Where `@NOUN@` would select a word from a noun word list at random, `@ADJECTIVE@`, likewise, and `@MARKOV 13@` wold generate a 13 pair long Markov chain to insert at that point. \ No newline at end of file +Where `@NOUN@` would select a word from a noun word list at random, `@ADJECTIVE@`, likewise, and `@MARKOV 13@` wold generate a 13 pair long Markov chain to insert at that point. + +That'll be something like... + +```js +let nouns = fs.readFileSync('nouns.txt', 'utf8').split('\n'); +let adjectives = fs.readFileSync('adjectives.txt', 'utf8').split('\n'); + +function fillGaps(script) { + let parts = script.split('@'); + for (let i = 0; i < parts.length; i++) { + if (parts[i].startsWith('NOUN')) { + parts[i] = nouns[Math.floor(Math.random() * nouns.length)]; + } else if (parts[i].startsWith('ADJECTIVE')) { + parts[i] = adjectives[Math.floor(Math.random() * adjectives.length)]; + } else if (parts[i].startsWith('MARKOV')) { + let length = parseInt(parts[i].split(' ')[1]); + let chain = ''; + let pair = pairs[Math.floor(Math.random() * pairs.length)]; + for (let j = 0; j < length; j++) { + let nextWords = markovChain.get(pair); + let nextWord = nextWords[Math.floor(Math.random() * nextWords.length)]; + chain += ' ' + nextWord; + pair = pair.split(' ')[1] + ' ' + nextWord; + } + parts[i] = chain; + } + } + return parts.join(''); +} + +let script = 'The @NOUN@ of @ADJECTIVE@ @NOUN@ is known for @MARKOV 13@'; +console.log(fillGaps(script)); +``` + +But this remains totally untested at this time. \ No newline at end of file |