RiTa
index
Name RiTravesty
Description Represents a Markov chain (or n-Gram) model that treats each character as a separate token (a la the original Travesty program). Provides a range of methods (see examples below) to query the model for probabilites and/or completions.

    RiTravesty rm = new RiTravesty(this, 5);

    rm.setEndOfSequenceChar(' ');                // treats each word as separate input

    rm.loadFile("myTestFile.txt");               // load the file (w' no multiplier)

    rm.printTree();                              // prints the model as a tree

                            ---------------------------

    println("p(g)="+rm.getProbability("g"));     // the probability of 'g'

    println("p(X|g)="+rm.getProbabilities("g")); // probabilities for next letters(X) after g, p(X|g) 

    String comp = rm.getCompletion("gr");        // returns a prob. random completion 

    String[] comps = rm.getCompletions("gr");    // returns all possible completions
 
Constructors
RiTravesty(parent, nFactor);
Methods
containsChar()   Returns true if the model contains the token in any position, else false.

getCompletion()   Chooses a single completion (if there are more than 1) based upon probabilistic random choices.

getCompletions()   Returns all completions (in the input) for a given substring

getEndOfSequenceChar()   Returns the character marking the end of an input sequence;

getNFactor()   Returns the current n-value for the model

getProbabilities()   Returns the full set of possible next tokens (as a HashMap: String -> Float (probability)) given an array of tokens representing the path down the tree (with length less than n). If the input array length is not less than n, or the path cannot be found, or the endnode has no children, null is returned.

As the returned Map represents the full set of possible next tokens, the sum of its probabilities will alwyas equal 1.

getProbability()   Returns the probability of obtaining a sequence of k character tokens were k <= nFactor, e.g., if nFactor = 3, then valid lengths for the String tokens are 1, 2 & 3.

isSmoothing()   Returns whether (add-1) smoothing is enabled for the model

loadCharData()   Load a String into the model, treating each character as separate entity

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

printTree()   Outputs a String representing the models probability tree using the supplied print stream (or System.out).

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

setEndOfSequenceChar()   Sets the character to mark the end of an input sequence. To parse each word token separately, for example, set this to {@link Character} a space - default is Character.EOF.

setUseSmoothing()   Toggles whether (add-1) smoothing is enabled for the model

Usage Web & Application