ctext
index
Name CMarkov
Examples
// Create a markov model with N = 3
PMarkov markov = new PMarkov(this, 3);  

// Load file <data-dir>/in1.txt into the model 
markov.loadFile("in1.txt");

// Load in2.txt tripling its probabilities 
markov.loadFile("in2.txt", 3);
Description Represents a Markov (or n-Gram) Model for probabilistic text generation.
Constructors
CMarkov(parent);
CMarkov(parent, nFactor);
Methods
addSentences ( )   Loads an array of sentences into the model; each element in the array must be a single sentence for proper parsing.

dumpModel ( )   Outputs a String representing the models probability tree.

NOTE: this method will block for potentially long periods of time on large models.

generate ( )   Generates some # (one or more) of sentences from the model.

Note: multiple sentences generated by this method WILL follow the model across sentence boundaries, thus, the following two calls are NOT equivalent:

     String[] results = pmarkov.generate(10);
               and
     for (int i = 0; i < array.length; i++)
       results[i] = pmarkov.generate();
     
The first will create 10 sentences with no explicit relationship between one and the next; while the 2nd will follow the markov prob- abilities from one sentence (across a boundary) to the next.

getInfo ( )   Returns some minimal info about the model.

getMaxSentenceLength ( )   returns the maximum length (in words) of a valid generated sentence

getMinSentenceLength ( )   Returns the minimum length (in words) of a valid generated sentence

getNFactor ( )   Returns the n-value for the n-gram (or Markov) model

getStrictSentenceStarts ( )   Returns whether atypical sentence starts are permitted; e.g., 'THAT boy was good.', or 'Hymn22 is my favorite'. If true, only first words matching this regex: (\"?[A-Z][a-z"',;`]*) are allowed.

loadFile ( )   Load a text file (of sentences) into the model -- if using Processing, the file should be in the sketch's data folder.

loadString ( )   Load a text String (of sentences) into the model

setMaxSentenceLength ( )   Sets the maximum length (in words) of a valid generated sentence

setMinSentenceLength ( )   Sets the minimum length (in words) of a valid generated sentence

setStrictSentenceStarts ( )   Set whether atypical sentence starts are permitted; if true, the model accepts only those first words matching this regex: (\"?[A-Z][a-z"',;`]*)

Usage Web & Application
Related