rita.support
Class MsNGramClient

java.lang.Object
  extended by rita.RiObject
      extended by rita.support.MsNGramClient
All Implemented Interfaces:
processing.core.PConstants, RiConstants

public class MsNGramClient
extends RiObject

A REST client for the Microsoft Web N-Gram Service.

Arguments:

'apiKey' - your Microsoft-supplied authorization key for the service

'model' - the specific model you wish to use. If the argument is not provided a default model is used (currently 'bing-body/jun09/3').

'serviceURI' - can be left to the default unless the service location has changed.


Field Summary
 
Fields inherited from interface rita.support.RiConstants
BEHAVIOR_COMPLETED, BOUNDING_BOX_ALPHA, BRILL_POS_TAGGER, EASE_IN, EASE_IN_CUBIC, EASE_IN_EXPO, EASE_IN_OUT, EASE_IN_OUT_CUBIC, EASE_IN_OUT_EXPO, EASE_IN_OUT_QUARTIC, EASE_IN_OUT_SINE, EASE_IN_QUARTIC, EASE_IN_SINE, EASE_OUT, EASE_OUT_CUBIC, EASE_OUT_EXPO, EASE_OUT_QUARTIC, EASE_OUT_SINE, ESS, FADE_COLOR, FADE_IN, FADE_OUT, FADE_TO_TEXT, FIRST_PERSON, FUTURE_TENSE, ID, LERP, LINEAR, MAXENT_POS_TAGGER, MINIM, MOVE, MUTABLE, PAST_TENSE, PHONEME_BOUNDARY, PHONEMES, PLING_STEMMER, PLURAL, PORTER_STEMMER, POS, PRESENT_TENSE, SCALE_TO, SECOND_PERSON, SENTENCE_BOUNDARY, SINGULAR, SONIA, SPEECH_COMPLETED, STRESSES, SYLLABLE_BOUNDARY, SYLLABLES, TEXT, TEXT_ENTERED, THIRD_PERSON, TIMER, TIMER_COMPLETED, TIMER_TICK, TOKENS, UNKNOWN, WORD_BOUNDARY
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
MsNGramClient()
           
MsNGramClient(processing.core.PApplet pApplet)
           
 
Method Summary
 java.lang.String[] generate(java.lang.String phrase)
           
 java.lang.String[] generate(java.lang.String phrase, int maxResultSize)
          Given a phrase (a sequence of space-separated words), find the words that are the most likely to follow the phrase.
 java.lang.String[] generate(java.lang.String phrase, java.lang.String cookie)
           
 java.lang.String generateWords(java.lang.String startOfPhrase, int numWords)
           
 java.lang.String getApiKey()
           
 java.lang.String[] getAvailableModels()
          Get a list of currently supported N-Gram models
 float getBackoffValue()
          The backoff value is made available in the event that you wish to call generate() with a shortened phraseContext, so as to make the returned values compare-able.
 float getConditionalProbability(java.lang.String phrase)
          Finds the conditional probability of the words in a phrase (a sequence of space-separated words) using the current model.
 java.lang.String getModel()
           
 float getProbability(java.lang.String phrase)
          Finds the joint probability of the words in a phrase (a sequence of space-separated words), in the current model.
 java.lang.String getServiceUri()
          // doesn't seem to work at moment Returns the generated cookie (an opaque placeholder to facilitate subsequent calls) from a the last call to generate().
 java.lang.String getUserAgent()
           
static void main(java.lang.String[] args)
           
 java.lang.String nextWord(java.lang.String phrase)
           
 void setApiKey(java.lang.String apiKey)
           
 void setModel(java.lang.String model)
          Should be of the form returned by #getModels()
 void setServiceUri(java.lang.String serviceUri)
           
 void setUserAgent(java.lang.String userAgent)
           
 
Methods inherited from class rita.RiObject
dispose, getId, getPApplet, nextId
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MsNGramClient

public MsNGramClient()

MsNGramClient

public MsNGramClient(processing.core.PApplet pApplet)
Method Detail

generate

public java.lang.String[] generate(java.lang.String phrase,
                                   int maxResultSize)
Given a phrase (a sequence of space-separated words), find the words that are the most likely to follow the phrase.

The returned String[] contains words in decreasing probability order.

      Note: 
         For a model of order N, if phraseContext contains more than N-1 words, the 
         excess words at the beginning of phrase are ignored.
 


nextWord

public java.lang.String nextWord(java.lang.String phrase)

generate

public java.lang.String[] generate(java.lang.String phrase)

generate

public java.lang.String[] generate(java.lang.String phrase,
                                   java.lang.String cookie)

getProbability

public float getProbability(java.lang.String phrase)
Finds the joint probability of the words in a phrase (a sequence of space-separated words), in the current model.

The base-10 log of the joint probability of the word sequence.

     For instance, if you have the following word sequence:
       w1, w2, …, wn
       
     The return value is the log of the following:
         P(w1) P(w2|w1) … P(wn | wn-m+1…wn-1)
         
     Notes:
       The token  represents the beginning of a phrase.
       Punctuation is generally ignored.
 


getConditionalProbability

public float getConditionalProbability(java.lang.String phrase)
Finds the conditional probability of the words in a phrase (a sequence of space-separated words) using the current model.

The base-10 log of the conditional probability of the last word in a sequence, in a given context.

  For instance, for the following word sequence (for an ngram-model of size m):
         w1, w2, …, wn
       
       The return value is the log of the following:
           P(wn | wn-m+1…wn-1)
           
       Notes:
         If n=0, the return value is Float.NaN.
         If n>m, the words at the beginning of phrase are ignored.
 


getAvailableModels

public java.lang.String[] getAvailableModels()
Get a list of currently supported N-Gram models


getApiKey

public java.lang.String getApiKey()

setApiKey

public void setApiKey(java.lang.String apiKey)

getUserAgent

public java.lang.String getUserAgent()

setUserAgent

public void setUserAgent(java.lang.String userAgent)

getServiceUri

public java.lang.String getServiceUri()
// doesn't seem to work at moment Returns the generated cookie (an opaque placeholder to facilitate subsequent calls) from a the last call to generate(). Before the first call to generate(), getGeneratedCookie() will return an empty string. public String getGeneratedCookie() { return savedCookie; }


setServiceUri

public void setServiceUri(java.lang.String serviceUri)

getModel

public java.lang.String getModel()

setModel

public void setModel(java.lang.String model)
Should be of the form returned by #getModels()


getBackoffValue

public float getBackoffValue()
The backoff value is made available in the event that you wish to call generate() with a shortened phraseContext, so as to make the returned values compare-able.

Before the first call to generate(), getBackoffValue() will return an empty string.


generateWords

public java.lang.String generateWords(java.lang.String startOfPhrase,
                                      int numWords)

main

public static void main(java.lang.String[] args)