0.1.7 • Published 5 years ago

markov-text v0.1.7

Weekly downloads
9
License
WTFPL
Repository
github
Last release
5 years ago

Markov Text Build Status

A simple procedural text generator implementing Markov chains

Markov Chain

Installation

npm install markov-text

Usage

    var Markov = require('markov-text');

    const trainingText = 'Lorem ipsum dolor sit ammet'

    options = {...}
    
    const loremGenerator = new Markov(options) // Setup generator
    
    loremGenerator.seed(trainingText) // Seed chain with "training" text

    const generatedText = loremGenerator.generate(5) // Set length of the generated output.
MethodArgumentsReturnsDescription
seedtrainingText-Seeds the generator with the training text. The generator splits the text into nGrams (pieces of n-characters or n-words length, depending on the mode)analog to chainlinks.
generateoutputLengthoutputReturns the generated text of the specified length. (Length is in ngrams not in charcters/words)

Options

You can pass in an options object when instancing the generator that accepts the following options:

PropertyTypeOptionsDefaultDescription
orderinteger1-nnoSpecifies the length of the ngrams (chainlinks). Longer chainlinks will produce more coherent text but less 'creativity'
modestring'single''multiple''multiple'Single mode will generate single words and will use training text as single independent words. Multiple mode will generate sentences and will use training text as word blocks.

Debuggin

You can view the chain building step by setting up the enviroment variable DEBUG_CHAIN to true

DEBUG_CHAIN=true node myTextGenerator

Examples

Provided are two examples you can run using:

Metamorphosis

metamorphosis-text

Uses a excerpt of Franz Kafka's Metamorphosis to generate sentences of the desired length.

npm run example:metamorphosis

Lotr

lotr-text

Uses all the names from characters of LOTR to generate a new one

npm run example:lotr

Copyright for training texts is owned by their respetive authors and is not protected by the license of this library

Tests

npm test

Credit

This is mainly my best shot at implementating in Javascript what is explained in this great series by starbeamrainbowlabs

0.1.7

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago