rita.support
Class TextNode

java.lang.Object
  extended by rita.support.TextNode
All Implemented Interfaces:
java.lang.Comparable, RiProbable, RiTextNode

public class TextNode
extends java.lang.Object
implements java.lang.Comparable, RiProbable, RiTextNode

A node in a graph containing text and some # of child TextNodes


Field Summary
static int totalNodes
          the # of non-root nodes
static int totalTokens
          the # of tokens processed
 
Method Summary
 TextNode addChild(char c, int initialCount)
           
 TextNode addChild(java.lang.String newToken)
          If the newToken does not exist as a child, creates a new child node with a frequency of 1 (e.g., else increments the existing child node's frequency by 1.
 TextNode addChild(java.lang.String newToken, int initialCount)
          If the newToken does not exist as a child, creates a new child node with initialCount as its frequency (e.g., for smoothing), else increments the existing child nodes frequency by 1
 java.lang.String asTree(boolean sort)
           
 java.util.Iterator childIterator()
           
 int compareTo(java.lang.Object o)
           
static TextNode createRoot(boolean ignoreCase)
           
 java.util.Map getChildMap()
           
 java.util.Collection getChildNodes()
           
 java.util.List getChildNodes(java.lang.String regex)
          Returns a List of all children matching the supplied regular expression.
 int getCount()
           
 float getProbability()
          Returns a probability value between 0 - 1
 float getRawValue()
          To satisfy the RiProbable interface; simply returns the count here
 java.lang.String getToken()
           
 boolean hasChildren()
           
 boolean hasChildren(java.lang.String regex)
          Return true if the node has at least one child matching the given regular expression (if one is supplied).
 int increment()
           
 boolean isIgnoringCase()
           
 boolean isLeaf()
           
 boolean isRoot()
           
 boolean isSentenceStart()
           
 TextNode lookup(char charToLookup)
          Does a lookup on the children of this node and returns any nodes that match charToLookup, else returns null.
 TextNode lookup(RiTextNode tokenToLookup)
          Does a lookup on the children of this node and returns any nodes that match tokenToLookup, else returns null.
 TextNode lookup(java.lang.String tokenToLookup)
          Does a lookup on the children of this node and returns any nodes that match tokenToLookup, else returns null.
static void main(java.lang.String[] args)
           
 int numChildren()
          Returns number of children of this node
 void pathFromRoot(java.util.Stack result)
           
 TextNode selectChild()
           
 TextNode selectChild(boolean probabalisticSelect)
           
 TextNode selectChild(java.lang.String regex, boolean probabalisticSelect)
           
 void setCount(int initialCount)
           
 void setIgnoreCase(boolean b)
           
 void setIsSentenceStart(boolean isSentenceStart)
           
 java.lang.String toString()
           
 int uniqueCount()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

totalTokens

public static int totalTokens
the # of tokens processed


totalNodes

public static int totalNodes
the # of non-root nodes

Method Detail

createRoot

public static TextNode createRoot(boolean ignoreCase)

addChild

public TextNode addChild(java.lang.String newToken)
Description copied from interface: RiTextNode
If the newToken does not exist as a child, creates a new child node with a frequency of 1 (e.g., else increments the existing child node's frequency by 1.

Specified by:
addChild in interface RiTextNode
Returns:
the child node

addChild

public TextNode addChild(char c,
                         int initialCount)
Specified by:
addChild in interface RiTextNode

addChild

public TextNode addChild(java.lang.String newToken,
                         int initialCount)
Description copied from interface: RiTextNode
If the newToken does not exist as a child, creates a new child node with initialCount as its frequency (e.g., for smoothing), else increments the existing child nodes frequency by 1

Specified by:
addChild in interface RiTextNode
Returns:
the child node

getToken

public java.lang.String getToken()
Specified by:
getToken in interface RiTextNode

getCount

public int getCount()
Specified by:
getCount in interface RiTextNode

increment

public int increment()
Specified by:
increment in interface RiTextNode

toString

public java.lang.String toString()
Specified by:
toString in interface RiTextNode
Overrides:
toString in class java.lang.Object

isRoot

public boolean isRoot()
Specified by:
isRoot in interface RiTextNode

pathFromRoot

public void pathFromRoot(java.util.Stack result)
Specified by:
pathFromRoot in interface RiTextNode

uniqueCount

public int uniqueCount()
Specified by:
uniqueCount in interface RiTextNode

getProbability

public float getProbability()
Description copied from interface: RiProbable
Returns a probability value between 0 - 1

Specified by:
getProbability in interface RiProbable
Specified by:
getProbability in interface RiTextNode

childIterator

public java.util.Iterator childIterator()
Specified by:
childIterator in interface RiTextNode

numChildren

public int numChildren()
Description copied from interface: RiTextNode
Returns number of children of this node

Specified by:
numChildren in interface RiTextNode

compareTo

public int compareTo(java.lang.Object o)
Specified by:
compareTo in interface java.lang.Comparable
Specified by:
compareTo in interface RiTextNode

lookup

public TextNode lookup(java.lang.String tokenToLookup)
Description copied from interface: RiTextNode
Does a lookup on the children of this node and returns any nodes that match tokenToLookup, else returns null.

Specified by:
lookup in interface RiTextNode

lookup

public TextNode lookup(RiTextNode tokenToLookup)
Description copied from interface: RiTextNode
Does a lookup on the children of this node and returns any nodes that match tokenToLookup, else returns null.

Specified by:
lookup in interface RiTextNode

lookup

public TextNode lookup(char charToLookup)
Description copied from interface: RiTextNode
Does a lookup on the children of this node and returns any nodes that match charToLookup, else returns null.

Specified by:
lookup in interface RiTextNode

getChildNodes

public java.util.Collection getChildNodes()
Specified by:
getChildNodes in interface RiTextNode

asTree

public java.lang.String asTree(boolean sort)
Specified by:
asTree in interface RiTextNode

isLeaf

public boolean isLeaf()
Specified by:
isLeaf in interface RiTextNode

setIgnoreCase

public void setIgnoreCase(boolean b)
Specified by:
setIgnoreCase in interface RiTextNode

isIgnoringCase

public boolean isIgnoringCase()
Specified by:
isIgnoringCase in interface RiTextNode

selectChild

public TextNode selectChild()
Specified by:
selectChild in interface RiTextNode

selectChild

public TextNode selectChild(boolean probabalisticSelect)
Specified by:
selectChild in interface RiTextNode

selectChild

public TextNode selectChild(java.lang.String regex,
                            boolean probabalisticSelect)
Specified by:
selectChild in interface RiTextNode

getChildNodes

public java.util.List getChildNodes(java.lang.String regex)
Returns a List of all children matching the supplied regular expression.

Specified by:
getChildNodes in interface RiTextNode
Parameters:
regex - public List getChildren(String regex) { Matcher m = null; List tmp = new LinkedList(); Pattern p = Pattern.compile(regex); for (Iterator i = childIterator(); i.hasNext();) { TextNode tn = (TextNode) i.next(); m = p.matcher(tn.getWord()); if (m.matches()) tmp.add(tn.getWord()); } return tmp; }
Returns:
a List of matching children or null if none are found.

hasChildren

public boolean hasChildren(java.lang.String regex)
Description copied from interface: RiTextNode
Return true if the node has at least one child matching the given regular expression (if one is supplied).

Specified by:
hasChildren in interface RiTextNode

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface RiTextNode

getChildMap

public java.util.Map getChildMap()
Specified by:
getChildMap in interface RiTextNode

isSentenceStart

public boolean isSentenceStart()
Specified by:
isSentenceStart in interface RiTextNode

setIsSentenceStart

public void setIsSentenceStart(boolean isSentenceStart)
Specified by:
setIsSentenceStart in interface RiTextNode

setCount

public void setCount(int initialCount)
Specified by:
setCount in interface RiTextNode

getRawValue

public float getRawValue()
To satisfy the RiProbable interface; simply returns the count here

Specified by:
getRawValue in interface RiProbable

main

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