diff options
Diffstat (limited to 'js/bird-words/beak.js')
-rw-r--r-- | js/bird-words/beak.js | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/js/bird-words/beak.js b/js/bird-words/beak.js index 38a2584..12c6a79 100644 --- a/js/bird-words/beak.js +++ b/js/bird-words/beak.js @@ -43,4 +43,38 @@ for (let i = 0; i < storyLength; i++) { story += " " + randomPair.split(' ')[1]; } -console.log(wrap(prettyItUp(story), 40)); +// console.log(wrap(prettyItUp(story), 40)); + + + +let nouns = fs.readFileSync('nouns.txt', 'utf8').split('\n'); +let adjectives = fs.readFileSync('adjectives.txt', 'utf8').split('\n'); +let places = fs.readFileSync('places.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('PLACE')) { + parts[i] = places[Math.floor(Math.random() * places.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@ was found in @PLACE@, where there was a partial inscription that read, @MARKOV 22@'; +console.log(fillGaps(script)); \ No newline at end of file |