rita
Class RiString

java.lang.Object
  extended by rita.support.Featured
      extended by rita.RiString
All Implemented Interfaces:
java.lang.CharSequence, processing.core.PConstants, FeaturedIF, RiCharSequence, RiConstants

public class RiString
extends Featured
implements RiCharSequence

RiTa's version of the Java String object (both implement the CharSequence interface) with support for 'features'; key-value pairs that contain additional information about the object. For example, you can add part-of-speech, phonemes, syllables, and stress features to a RiString object as follows:

    RiString rs = new RiString("The dog was white");
    RiAnalyzer ra = new RiAnalyzer();
    ra.analyze(rs);

    System.out.println(rs.getFeature("syllables"));
    System.out.println(rs.getFeature("phonemes"));    
    System.out.println(rs.getFeature("stresses"));
    System.out.println(rs.getFeature("pos"));


Field Summary
 
Fields inherited from class rita.support.Featured
CHUNKS, PARSE, VALUE_UNKNOWN
 
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
RiString(java.lang.CharSequence s)
           
RiString(processing.core.PApplet p, java.lang.CharSequence s)
          Included only for consistency's sake
 
Method Summary
 char charAt(int index)
           
 int compareTo(java.lang.Object arg0)
           
 int compareTo(java.lang.String anotherString)
           
 int compareToIgnoreCase(java.lang.String str)
           
 java.lang.String concat(java.lang.String str)
           
 boolean contains(java.lang.CharSequence s)
           
 boolean contentEquals(java.lang.StringBuilder sb)
           
 RiString copy()
          Creates and returns a copy of this object
static RiString copy(RiString riString)
          Creates and returns a copy of riString
static void delete(RiString text)
           
 void dump()
           
 boolean endsWith(java.lang.String suffix)
           
 boolean equals(java.lang.Object anObject)
           
 boolean equalsIgnoreCase(java.lang.String anotherString)
           
 int firstIndexOf(java.lang.String word)
          Returns the index of the first token matching word or -1 if not found
static RiString[] fromCollection(java.util.Collection c)
           
static RiString[] fromStrings(java.lang.String[] s)
           
 byte[] getBytes()
           
 byte[] getBytes(java.lang.String charsetName)
           
 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
           
 java.lang.String getPos()
          Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by spaces.
 java.lang.String getPos(boolean useWordNetTags)
           
 java.lang.String getPos(java.lang.String delim)
          Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by delim.
 java.lang.String getPos(java.lang.String delim, boolean useWordNetTags)
          Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by delim.
 java.lang.String[] getPosArr(boolean useWordNetTags)
          Returns an array of part-of-speech tags, one per word, using the default WordTokenizer & PosParser...
 java.lang.String getPosAt(int wordIdx)
          Returns the part-of-speech at wordIdx using the default WordTokenizer & PosParser...
 java.lang.String getPosAt(int wordIdx, boolean useWordNetTags)
          Returns the part-of-speech at wordIdx using the default WordTokenizer & PosParser...
 java.lang.String getText()
           
 java.lang.String getWordAt(int wordIdx)
          Returns the word at wordIdx using the default WordTokenizer.
 int getWordCount()
          Returns the # of words in the object according to the default WordTokenizer.
 java.lang.String[] getWords()
          Returns the array of words in the object, via a call to RiTa.tokenize().
 int hashCode()
           
 int indexOf(int ch)
           
 int indexOf(int ch, int fromIndex)
           
 int indexOf(java.lang.String str)
           
 int indexOf(java.lang.String str, int fromIndex)
           
 boolean insertWordAt(java.lang.String newWord, int wordIdx)
          Inserts newWord at wordIdx and shifts each subsequent word accordingly.
 java.lang.String intern()
           
 FeaturedIF join(RiString[] fstrs, java.lang.String regex)
           
 int lastIndexOf(int ch)
           
 int lastIndexOf(int ch, int fromIndex)
           
 int lastIndexOf(java.lang.String str)
           
 int lastIndexOf(java.lang.String str, int fromIndex)
           
 int length()
           
static void main(java.lang.String[] args)
           
 boolean matches(java.lang.String regex)
           
static boolean regexMatch(java.lang.String patternStr, java.lang.String fullStr)
          Utility method to test whether a String partially matches a regex pattern.
static java.lang.String regexReplace(java.lang.String patternStr, java.lang.String fullStr, java.lang.String replaceStr)
          Utility method to do regex replacement on a String
 boolean regionMatches(boolean ignoreCase, int toffset, java.lang.String other, int ooffset, int len)
           
 boolean regionMatches(int toffset, java.lang.String other, int ooffset, int len)
           
 java.lang.String replace(char oldChar, char newChar)
           
 java.lang.String replace(java.lang.CharSequence target, java.lang.CharSequence replacement)
           
 void replace(java.lang.String oldText, java.lang.String newText)
          Replaces all instances of oldText with newText in the object.
 java.lang.String replaceAll(java.lang.String regex, java.lang.String replacement)
           
 java.lang.String replaceByPos(java.lang.String newWord, java.lang.String pos)
          Randomly chooses from all words matching pos and replaces a random one with newWord.
 boolean replaceCharAt(int idx, java.lang.String replaceWith)
          Replaces the character at 'idx' with 'replaceWith'.
 java.lang.String replaceFirst(java.lang.String regex, java.lang.String replacement)
           
 boolean replaceWordAt(java.lang.String newWord, int wordIdx)
          Replaces the word at wordIdx with newWord.
 void setString(java.lang.CharSequence[] words)
           
 void setString(java.lang.String newWord)
           
 void setText(java.lang.String _text)
          Sets the current text to this String
 RiString[] split()
          Splits the RiString as per String.split(), then checks for any features with the same number of elements as the resulting String[] and adds the appropriate feature to each newly created RiString in the array.
Example:
'only a handful of responses' / {chunk=noun-phrase}, {pos=rb dt nn in nns} -> 'only' / {pos=rb} 'a' / {pos=dt} 'handful' / {pos=nn} 'of' / {pos=in} 'responses' / {pos=nns}
 RiString[] split(java.lang.String regex)
          Splits the RiString as per String.split(regex), then checks for any features with the same number of elements as the resulting String[] and adds the appropriate feature to each individual RiString.
Example:
'only a handful of responses' / {chunk=noun-phrase}, {pos=rb dt nn in nns} -> 'only' / {pos=rb} 'a' / {pos=dt} 'handful' / {pos=nn} 'of' / {pos=in} 'responses' / {pos=nns}
 boolean startsWith(java.lang.String prefix)
           
 boolean startsWith(java.lang.String prefix, int toffset)
           
 java.lang.CharSequence subSequence(int beginIndex, int endIndex)
           
 java.lang.String substring(int beginIndex)
           
 java.lang.String substring(int beginIndex, int endIndex)
           
 char[] toCharArray()
           
 java.lang.String toLowerCase()
           
 java.lang.String toLowerCase(java.util.Locale locale)
           
 java.lang.String toString()
           
 java.lang.String toUpperCase()
           
 java.lang.String toUpperCase(java.util.Locale locale)
           
 java.lang.String trim()
           
 
Methods inherited from class rita.support.Featured
addFeature, addFeature, appendFeature, asFeature, asFeature, asFeature, asFeature, asFeature, clearFeatures, getAvailableFeatures, getFeature, getFeatures, getFeatures, getId, hasFeature, removeFeature, setFeatures, toStrings
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface rita.support.FeaturedIF
addFeature, clearFeatures, getAvailableFeatures, getFeature, getFeatures, hasFeature, removeFeature, setFeatures
 

Constructor Detail

RiString

public RiString(processing.core.PApplet p,
                java.lang.CharSequence s)
Included only for consistency's sake

Invisible:

RiString

public RiString(java.lang.CharSequence s)
Method Detail

delete

public static void delete(RiString text)

setText

public void setText(java.lang.String _text)
Sets the current text to this String


firstIndexOf

public int firstIndexOf(java.lang.String word)
Returns the index of the first token matching word or -1 if not found


getWordCount

public int getWordCount()
Returns the # of words in the object according to the default WordTokenizer.

See Also:
getWords()

getWords

public java.lang.String[] getWords()
Returns the array of words in the object, via a call to RiTa.tokenize().

See Also:
RiTa.tokenize(String)

insertWordAt

public boolean insertWordAt(java.lang.String newWord,
                            int wordIdx)
Inserts newWord at wordIdx and shifts each subsequent word accordingly. Returns true if the replace was succesful, or false if the index does not exist.


replaceWordAt

public boolean replaceWordAt(java.lang.String newWord,
                             int wordIdx)
Replaces the word at wordIdx with newWord. Returns true if the replace was succesful, or false if the index does not exist.


regexReplace

public static java.lang.String regexReplace(java.lang.String patternStr,
                                            java.lang.String fullStr,
                                            java.lang.String replaceStr)
Utility method to do regex replacement on a String

Parameters:
patternStr - regex
fullStr - String to check
replaceStr - String to insert
See Also:
Pattern

regexMatch

public static boolean regexMatch(java.lang.String patternStr,
                                 java.lang.String fullStr)
Utility method to test whether a String partially matches a regex pattern.

Parameters:
patternStr - regex String
fullStr - String to check
See Also:
Pattern

replaceByPos

public java.lang.String replaceByPos(java.lang.String newWord,
                                     java.lang.String pos)
Randomly chooses from all words matching pos and replaces a random one with newWord. Returns the replaced word, or null if if no substitution could be made.

Invisible:

getWordAt

public java.lang.String getWordAt(int wordIdx)
Returns the word at wordIdx using the default WordTokenizer.


getPosAt

public java.lang.String getPosAt(int wordIdx)
Returns the part-of-speech at wordIdx using the default WordTokenizer & PosParser...


getPosAt

public java.lang.String getPosAt(int wordIdx,
                                 boolean useWordNetTags)
Returns the part-of-speech at wordIdx using the default WordTokenizer & PosParser...


getPosArr

public java.lang.String[] getPosArr(boolean useWordNetTags)
Returns an array of part-of-speech tags, one per word, using the default WordTokenizer & PosParser...


getPos

public java.lang.String getPos(java.lang.String delim,
                               boolean useWordNetTags)
Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by delim.

Invisible:

getPos

public java.lang.String getPos(java.lang.String delim)
Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by delim.

Invisible:

getPos

public java.lang.String getPos()
Returns an String of part-of-speech tags, 1 per word, using the default WordTokenizer & PosParser, delimited by spaces.


getPos

public java.lang.String getPos(boolean useWordNetTags)

replace

public void replace(java.lang.String oldText,
                    java.lang.String newText)
Replaces all instances of oldText with newText in the object.


split

public RiString[] split()
Splits the RiString as per String.split(), then checks for any features with the same number of elements as the resulting String[] and adds the appropriate feature to each newly created RiString in the array.
Example:
'only a handful of responses' / {chunk=noun-phrase}, {pos=rb dt nn in nns} ->

See Also:
RiConstants.WORD_BOUNDARY

split

public RiString[] split(java.lang.String regex)
Splits the RiString as per String.split(regex), then checks for any features with the same number of elements as the resulting String[] and adds the appropriate feature to each individual RiString.
Example:
'only a handful of responses' / {chunk=noun-phrase}, {pos=rb dt nn in nns} ->

See Also:
RiConstants.WORD_BOUNDARY

setString

public void setString(java.lang.String newWord)

setString

public void setString(java.lang.CharSequence[] words)

join

public FeaturedIF join(RiString[] fstrs,
                       java.lang.String regex)

dump

public void dump()

copy

public static RiString copy(RiString riString)
Creates and returns a copy of riString


copy

public RiString copy()
Creates and returns a copy of this object


fromStrings

public static RiString[] fromStrings(java.lang.String[] s)

fromCollection

public static RiString[] fromCollection(java.util.Collection c)

charAt

public char charAt(int index)
Specified by:
charAt in interface java.lang.CharSequence

compareTo

public int compareTo(java.lang.Object arg0)

compareTo

public int compareTo(java.lang.String anotherString)

compareToIgnoreCase

public int compareToIgnoreCase(java.lang.String str)

concat

public java.lang.String concat(java.lang.String str)

contains

public boolean contains(java.lang.CharSequence s)

contentEquals

public boolean contentEquals(java.lang.StringBuilder sb)

endsWith

public boolean endsWith(java.lang.String suffix)

equals

public boolean equals(java.lang.Object anObject)
Overrides:
equals in class java.lang.Object

equalsIgnoreCase

public boolean equalsIgnoreCase(java.lang.String anotherString)

getBytes

public byte[] getBytes()

getBytes

public byte[] getBytes(java.lang.String charsetName)
                throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

getChars

public void getChars(int srcBegin,
                     int srcEnd,
                     char[] dst,
                     int dstBegin)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

indexOf

public int indexOf(int ch,
                   int fromIndex)

indexOf

public int indexOf(int ch)

indexOf

public int indexOf(java.lang.String str,
                   int fromIndex)

indexOf

public int indexOf(java.lang.String str)

intern

public java.lang.String intern()

lastIndexOf

public int lastIndexOf(int ch,
                       int fromIndex)

lastIndexOf

public int lastIndexOf(int ch)

lastIndexOf

public int lastIndexOf(java.lang.String str,
                       int fromIndex)

lastIndexOf

public int lastIndexOf(java.lang.String str)

length

public int length()
Specified by:
length in interface java.lang.CharSequence

matches

public boolean matches(java.lang.String regex)

regionMatches

public boolean regionMatches(boolean ignoreCase,
                             int toffset,
                             java.lang.String other,
                             int ooffset,
                             int len)

regionMatches

public boolean regionMatches(int toffset,
                             java.lang.String other,
                             int ooffset,
                             int len)

replace

public java.lang.String replace(char oldChar,
                                char newChar)

replace

public java.lang.String replace(java.lang.CharSequence target,
                                java.lang.CharSequence replacement)

replaceAll

public java.lang.String replaceAll(java.lang.String regex,
                                   java.lang.String replacement)

replaceFirst

public java.lang.String replaceFirst(java.lang.String regex,
                                     java.lang.String replacement)

replaceCharAt

public boolean replaceCharAt(int idx,
                             java.lang.String replaceWith)
Replaces the character at 'idx' with 'replaceWith'. If the specified 'idx' is less than xero, or beyond the length of the current text, there will be no effect. Returns true if the replacement was made


startsWith

public boolean startsWith(java.lang.String prefix,
                          int toffset)

startsWith

public boolean startsWith(java.lang.String prefix)

subSequence

public java.lang.CharSequence subSequence(int beginIndex,
                                          int endIndex)
Specified by:
subSequence in interface java.lang.CharSequence

substring

public java.lang.String substring(int beginIndex,
                                  int endIndex)

substring

public java.lang.String substring(int beginIndex)

toCharArray

public char[] toCharArray()

toLowerCase

public java.lang.String toLowerCase()

toLowerCase

public java.lang.String toLowerCase(java.util.Locale locale)

toString

public java.lang.String toString()
Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class Featured

getText

public java.lang.String getText()
Specified by:
getText in interface FeaturedIF
Overrides:
getText in class Featured

toUpperCase

public java.lang.String toUpperCase()

toUpperCase

public java.lang.String toUpperCase(java.util.Locale locale)

trim

public java.lang.String trim()

main

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