org.jscience.ml.tigerxml
Class GraphNode

java.lang.Object
  extended by org.jscience.ml.tigerxml.GraphNode
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
NT, T

public class GraphNode
extends java.lang.Object
implements java.io.Serializable

Represents a node in the syntax tree, either a terminal node or a non-terminal node.

GraphNode is a generalization over NT (non-terminal) and T (terminal) nodes. GraphNode implements all methods and attributes that are common to both, NT and T nodes. NT and T are subclasses of this class and inherit all methods. Furthermore, they implement methods which are specific to non-terminal and terminal nodes respectively.

It is possible to cast one class to one of the others:

Example:

 Corpus corp = new Corpus("sampleTIGER");
 GraphNode gn = corp.getGraphNodeBySpan("s1_1..s1_3");
 if (gn.isTerminal()) {
   System.out.println( (T)gn.getWord());
 } else {
   System.out.println( (NT)gn.toTreeString());
 }
 

See Also:
NT, T, Serialized Form

Field Summary
protected  int verbosity
          The higher this value the more process and debug information will written to stderr.
 
Constructor Summary
GraphNode()
          Creates an empty instance of GraphNode with all values set to null or emty.
GraphNode(java.lang.String id, Sentence sentence, NT mother, java.lang.String edge2mother, boolean isTerminal, int index)
          Creates an instance of GraphNode with alls values set as given.
 
Method Summary
 boolean before(GraphNode node)
          Returns true if the leftmost terminal of the tree whose root node this node is linearly preceedes the leftmost terminal of the tree whose root node the input node is.
 boolean dominates(GraphNode node)
          Returns true if this node dominates the input node in the syntax tree.
 boolean equals(GraphNode otherNode)
          Returns true if the two nodes are identical.
 Corpus getCorpus()
          Returns the corpus this GraphNode is part of.
 NT getDominatingNodeByCat(java.lang.String cat)
          Returns the nearest dominating node with category cat, null if there is no such node If this node has the category cat it will be returned itself.
 java.lang.String getEdge2Mother()
          Returns the label of the edge going to the mother node.
 java.lang.String getEdge2SecMother(NT s_mother)
          Returns the label that belongs to the edge going to the secondary mother s_mother.
 java.lang.String getId()
          Returns the ID String of this node.
 int getIndex()
          Returns the position index of this node in the ArrayList holding it.
 T getLeftmostTerminal()
          Returns the leftmost terminal of the tree whose root node this node is.
 NT getMother()
          Returns the mother node.
 Path getPath(GraphNode toNode)
          Returns a Path object representing the path through the syntax tree which connects this node and the input node.
 java.util.ArrayList getSecMothers()
          Returns an ArrayList of the secondary mothers of this node.
 Sentence getSentence()
          Returns the sentence this GraphNode is part of.
 java.lang.String getText()
          Returns the surface string of this node.
 int getVerbosity()
          Gets the currently set level of verbosity of this instance.
 boolean hasMother()
          Returns true if this node has a mother node.
 boolean hasSecMothers()
          Returns true if this node has any secondary mothers.
 boolean hasSurfaceWord(java.lang.String word)
          Returns true if one of the leaves of the subtree whose root this node is has the input word as its word
 boolean isDominatedBy(GraphNode node)
          Returns true if this node is dominated by the input node in the syntax tree.
 boolean isDominatedBy(java.lang.String cat)
          Returns true if there is a dominating node that has the category cat.
 boolean isTerminal()
          Returns true if this node is a terminal node (T), false if not.
 void printNode()
          Prints identifying information about this node.
 void printNode(java.lang.String comment)
          Prints a comment and identifying information about this node.
 void printNodeErr()
          Prints identifying information on this node to stderr.
 void printNodeErr(java.lang.String comment)
          Prints a comment and identifying information on this node to stderr.
 void printTree()
          Prints all daughters recursively in a tree structure to stdout.
 void printTreeErr()
          Prints all daughters recursively in a tree structure to stderr.
 void setEdge2Mother(java.lang.String newedge2mother)
          Sets the label String of the edge going to the mother node.
 void setId(java.lang.String newid)
          Sets the ID String of this node.
 void setIndex(int index)
          Sets the position index in the ArrayList holding this node.
 void setMother(NT newmother)
          Sets the mother of this node.
 void setSecMother(NT mother, java.lang.String label)
          Sets a secondary mother of this node and the label of the edge going to it.
 void setSentence(Sentence sentence)
          Sets the sentence this GraphNode is part of.
 void setTerminal(boolean isTerminal)
          Sets whether this node is a terminal.
 void setVerbosity(int verbosity)
          Sets the currently set level of verbosity of this instance.
 java.lang.String toNodeInfoString()
          Returns identifying information about this node as a string.
 java.lang.String toString()
          Returns the String representation of this node.
 java.lang.String toTreeString()
          Returns the tree structure of this GraphNode as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

verbosity

protected int verbosity
The higher this value the more process and debug information will written to stderr.

Constructor Detail

GraphNode

public GraphNode()
Creates an empty instance of GraphNode with all values set to null or emty.


GraphNode

public GraphNode(java.lang.String id,
                 Sentence sentence,
                 NT mother,
                 java.lang.String edge2mother,
                 boolean isTerminal,
                 int index)
Creates an instance of GraphNode with alls values set as given.

Parameters:
id - The ID-String of the node.
sentence - The sentence this instance of GraphNode is part of.
mother - The mother node (can only be a NT).
edge2mother - The label of the edge going to the mother node.
isTerminal - True/false for whether this instance is an instance of T.
index - The position index of this node in the ArrayList holding it.
Method Detail

isTerminal

public boolean isTerminal()
Returns true if this node is a terminal node (T), false if not. If this is a terminal node, it can be casted to T.

Returns:
True if this is an instance of T.
See Also:
T

setTerminal

public void setTerminal(boolean isTerminal)
Sets whether this node is a terminal.

Parameters:
isTerminal - True if this node is a terminal.

getId

public java.lang.String getId()
Returns the ID String of this node.


setId

public void setId(java.lang.String newid)
Sets the ID String of this node.


getSentence

public Sentence getSentence()
Returns the sentence this GraphNode is part of.


setSentence

public void setSentence(Sentence sentence)
Sets the sentence this GraphNode is part of.


getCorpus

public Corpus getCorpus()
Returns the corpus this GraphNode is part of.


getMother

public NT getMother()
Returns the mother node. You might have to use a cast like this: NT myNonTerminal = (NT) someGraphNode.getMother();


setMother

public void setMother(NT newmother)
Sets the mother of this node.


getEdge2Mother

public java.lang.String getEdge2Mother()
Returns the label of the edge going to the mother node.


setEdge2Mother

public void setEdge2Mother(java.lang.String newedge2mother)
Sets the label String of the edge going to the mother node.


setSecMother

public void setSecMother(NT mother,
                         java.lang.String label)
Sets a secondary mother of this node and the label of the edge going to it.


hasSecMothers

public boolean hasSecMothers()
Returns true if this node has any secondary mothers.


getSecMothers

public java.util.ArrayList getSecMothers()
Returns an ArrayList of the secondary mothers of this node. Note that it returns null if there aren't any secondary mothers.


getEdge2SecMother

public java.lang.String getEdge2SecMother(NT s_mother)
Returns the label that belongs to the edge going to the secondary mother s_mother.


getIndex

public int getIndex()
Returns the position index of this node in the ArrayList holding it.

Returns:
An integer denoting the index of the ArrayList holding this node.

setIndex

public void setIndex(int index)
Sets the position index in the ArrayList holding this node.


toString

public java.lang.String toString()
Returns the String representation of this node.

Overrides:
toString in class java.lang.Object
Returns:
The String representation (all terminal nodes' word strings).

equals

public boolean equals(GraphNode otherNode)
Returns true if the two nodes are identical.


hasMother

public boolean hasMother()
Returns true if this node has a mother node. Use this method to catch cases where a returned null from getMother() would cause trouble.


printNodeErr

public void printNodeErr()
Prints identifying information on this node to stderr.


printNodeErr

public void printNodeErr(java.lang.String comment)
Prints a comment and identifying information on this node to stderr.

Parameters:
comment - A comment precding the printed information.

getText

public java.lang.String getText()
Returns the surface string of this node. All contained terminal strings sorted by linear precedence and put into a single string.

Returns:
The surface string of this node.

hasSurfaceWord

public boolean hasSurfaceWord(java.lang.String word)
Returns true if one of the leaves of the subtree whose root this node is has the input word as its word


isDominatedBy

public boolean isDominatedBy(java.lang.String cat)
Returns true if there is a dominating node that has the category cat. or if this node has the category cat itself

Returns:
A truth value indicating wheter there is a dominating cat node.

getDominatingNodeByCat

public NT getDominatingNodeByCat(java.lang.String cat)
Returns the nearest dominating node with category cat, null if there is no such node If this node has the category cat it will be returned itself.

Returns:
The nearest node whith cat that dominates this node.

getPath

public Path getPath(GraphNode toNode)
Returns a Path object representing the path through the syntax tree which connects this node and the input node.

Returns:
a Path object representing the path which connects this and the input node.

isDominatedBy

public boolean isDominatedBy(GraphNode node)
Returns true if this node is dominated by the input node in the syntax tree.

Returns:
a truth value indicating whether this node is dominated by the input node.

dominates

public boolean dominates(GraphNode node)
Returns true if this node dominates the input node in the syntax tree.

Returns:
a truth value indicating whether this node dominates the input node.

toTreeString

public java.lang.String toTreeString()
Returns the tree structure of this GraphNode as a string.

Returns:
The tree structure of this GraphNode as a string.

toNodeInfoString

public java.lang.String toNodeInfoString()
Returns identifying information about this node as a string.

Returns:
Identifying information about this node as a string.

printTree

public void printTree()
Prints all daughters recursively in a tree structure to stdout.


printTreeErr

public void printTreeErr()
Prints all daughters recursively in a tree structure to stderr.


printNode

public void printNode()
Prints identifying information about this node.


printNode

public void printNode(java.lang.String comment)
Prints a comment and identifying information about this node.

Parameters:
comment - A comment precding the printed information.

before

public boolean before(GraphNode node)
Returns true if the leftmost terminal of the tree whose root node this node is linearly preceedes the leftmost terminal of the tree whose root node the input node is.


getLeftmostTerminal

public T getLeftmostTerminal()
Returns the leftmost terminal of the tree whose root node this node is.


getVerbosity

public int getVerbosity()
Gets the currently set level of verbosity of this instance. The higher the value the more information is written to stderr.

Returns:
The level of verbosity.

setVerbosity

public void setVerbosity(int verbosity)
Sets the currently set level of verbosity of this instance. The higher the value the more information is written to stderr.

Parameters:
verbosity - The level of verbosity.