kylm.model.ngram
Class NgramNode

java.lang.Object
  extended by kylm.model.ngram.NgramNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<NgramNode>
Direct Known Subclasses:
BranchNode

public class NgramNode
extends java.lang.Object
implements java.io.Serializable, java.lang.Iterable<NgramNode>

A single node in a tree holding n-gram data

Author:
neubig
See Also:
Serialized Form

Nested Class Summary
static class NgramNode.NgramNodeIdComparator
           
 
Field Summary
static int ADD_BRANCH
           
static int ADD_LEAF
           
static int ADD_NONE
           
static float TRIM_SCORE
           
 
Constructor Summary
NgramNode(int id, NgramNode parent)
          Create a new NgramNode that represents id and has a parent parent
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 float getBackoffScore()
           
 NgramNode getChild(int id)
          Get a child from the child vector, return null if no child exists.
 NgramNode getChild(int id, int add)
          Get a child from the child vector.
 int getChildCount()
           
 int getCount()
           
 NgramNode getFallback()
          Get the node to be fallen back to when the context doesn't exist.
 int getId()
           
 NgramNode getParent()
           
 float getScore()
           
 boolean hasChildren()
          Return whether this node has children or not
 void incrementCount()
           
 java.util.Iterator<NgramNode> iterator()
           
 void setBackoffScore(float backoff)
           
 void setChildren(java.util.Vector<NgramNode> children)
           
 void setCount(int count)
           
 void setId(int id)
           
 void setParent(NgramNode parent)
           
 void setScore(float score)
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADD_NONE

public static final int ADD_NONE
See Also:
Constant Field Values

ADD_LEAF

public static final int ADD_LEAF
See Also:
Constant Field Values

ADD_BRANCH

public static final int ADD_BRANCH
See Also:
Constant Field Values

TRIM_SCORE

public static final float TRIM_SCORE
See Also:
Constant Field Values
Constructor Detail

NgramNode

public NgramNode(int id,
                 NgramNode parent)
Create a new NgramNode that represents id and has a parent parent

Parameters:
id - The id of the symbol represented by this ngram
parent - The parent of this ngram in the tree
Method Detail

getChild

public NgramNode getChild(int id)
Get a child from the child vector, return null if no child exists.

Parameters:
id - The id of the child to find.
Returns:
The child.

getChild

public NgramNode getChild(int id,
                          int add)
Get a child from the child vector. If add is true and no child exists, add one. If add is false and no child exists, return null.

Parameters:
id - The id of the child to find.
add - Whether or not to add the child if it exists.
Returns:
The child.

hasChildren

public boolean hasChildren()
Return whether this node has children or not


getFallback

public NgramNode getFallback()
Get the node to be fallen back to when the context doesn't exist.

Returns:
The fallback node

getParent

public final NgramNode getParent()

setParent

public final void setParent(NgramNode parent)

getId

public final int getId()

setId

public final void setId(int id)

getCount

public final int getCount()

setCount

public final void setCount(int count)

getScore

public final float getScore()

setScore

public final void setScore(float score)

getBackoffScore

public float getBackoffScore()

setBackoffScore

public void setBackoffScore(float backoff)

equals

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

incrementCount

public final void incrementCount()

setChildren

public void setChildren(java.util.Vector<NgramNode> children)

iterator

public java.util.Iterator<NgramNode> iterator()
Specified by:
iterator in interface java.lang.Iterable<NgramNode>

getChildCount

public int getChildCount()