org.jscience.ml.tigerxml
Class Sentence

java.lang.Object
  extended by org.jscience.ml.tigerxml.Sentence
All Implemented Interfaces:
java.io.Serializable

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

Represents a sentence in a corpus. Sentence objects hold a list of NTs and a list of Ts. They also provide methods for traversing the syntax tree, accessing nodes directly, and getting other structural information.

See Also:
GraphNode, NT, T, Serialized Form

Constructor Summary
Sentence()
          Creates a new Sentence instance setting all member variables to null or empty.
Sentence(org.w3c.dom.Element sElement, Corpus corpus)
          Creates a new Sentence instance extracting all necessary information from the passed DOM Element.
Sentence(org.w3c.dom.Element sElement, Corpus corpus, int verbosity)
          Creates a new Sentence instance extracting all necessary information from the passed DOM Element.
 
Method Summary
 void addNT(NT newnt)
           
 void addT(T newt)
           
 void addVNode(VNode v_node)
           
 boolean equals(java.lang.Object obj)
          Returns true if the object is identical to this Sentence object.
 java.util.ArrayList getAllGraphNodes()
          Returns all GraphNode objects contained in this sentence.
 GraphNode getById(java.lang.String pass_id)
          Finds and returns a GraphNode in this sentence or returns null if there is no GraphNode with the given ID.
 Corpus getCorpus()
          Returns the corpus this sentence is part of.
 GraphNode getGraphNode(java.lang.String id)
          Returns the GraphNode which has the given ID.
 java.lang.String getId()
           
 int getIndex()
          Returns the position index of this sentence in the corpus holding it.
 Sentence getNextSentence()
          Returns the sentence object succeeding this sentence in the sentences ArrayList of the corpus containing this sentence.
 Sentence getNextSentence(int n)
          Returns the sentence object succeeding this sentence in the sentences ArrayList of the corpus containing this sentence by n.
 int getNoOfNTs()
          Deprecated. As of org.jscience.ml.tigerxml 1.1 - use getNTCount() instead.
 int getNoOfTs()
          Deprecated. As of org.jscience.ml.tigerxml 1.1 - use getTCount() instead.
 NT getNT(int i)
           
 NT getNT(java.lang.String id)
          Returns the NT which has the given ID.
 int getNTCount()
          Returns the number of NT objects in the sentence.
 java.util.ArrayList getNTs()
           
 Sentence getPrevSentence()
          Returns the sentence object predecessing this sentence in the sentences ArrayList of the corpus containing this sentence.
 Sentence getPrevSentence(int n)
          Returns the sentence object predecessing this sentence in the sentences ArrayList of the corpus containing this sentence by n.
 NT getRootNT()
          Returns the root node of the sentence (always an NT).
 java.lang.String getSpan()
          Returns the MMAX-style span of the sentence.
 T getT(int i)
           
 T getT(java.lang.String id)
          Returns the T which has the given ID.
 int getTCount()
          Returns the number of T objects in the sentence.
 T getTerminal(java.lang.String id)
          Returns the T which has the given ID.
 java.util.ArrayList getTerminals()
          Returns all terminal daughters.
 java.lang.String getText()
           
 java.util.ArrayList getTs()
           
 int getVerbosity()
          Gets the currently set level of verbosity of this instance.
 VNode getVNode(java.lang.String v_node_id)
           
 NT getVROOT()
          Returns the VROOT of this sentence.
 int hashCode()
           
 boolean hasRootNT()
           
 boolean hasVNode(java.lang.String v_node_id)
           
protected  void print2Xml(java.io.FileWriter out_xml)
           
 void printTree()
          Prints the syntax tree structure of this sentence to stout.
 void printTreeErr()
          Prints the syntax tree structure of this sentence to stderr.
 void setCorpus(Corpus passCorpus)
          Sets the corpus this sentence is part of.
 void setId(java.lang.String newid)
           
 void setIndex(int index)
          Sets the position index in the corpus holding this sentence.
 void setVerbosity(int verbosity)
          Sets the currently set level of verbosity of this instance.
 java.lang.String toString()
          Returns the String representation of this Sentence - its ID.
 java.lang.String toTreeString()
          Returns the syntax tree structure of this sentence as as string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Sentence

public Sentence()
Creates a new Sentence instance setting all member variables to null or empty.


Sentence

public Sentence(org.w3c.dom.Element sElement,
                Corpus corpus)
Creates a new Sentence instance extracting all necessary information from the passed DOM Element.

Parameters:
sElement - The DOM Sentence Element.
corpus - The Corpus this Sentence is part of.

Sentence

public Sentence(org.w3c.dom.Element sElement,
                Corpus corpus,
                int verbosity)
Creates a new Sentence instance extracting all necessary information from the passed DOM Element.

Parameters:
sElement - The DOM Sentence Element.
corpus - The Corpus this Sentence is part of.
Method Detail

getId

public java.lang.String getId()

setId

public void setId(java.lang.String newid)

getIndex

public int getIndex()
Returns the position index of this sentence in the corpus holding it.

Returns:
An integer denoting the index in the corpus holding this sentence.

setIndex

public void setIndex(int index)
Sets the position index in the corpus holding this sentence.


getCorpus

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

Returns:
The corpus that holds this sentence in its sentences ArrayList.

setCorpus

public void setCorpus(Corpus passCorpus)
Sets the corpus this sentence is part of.


getNextSentence

public Sentence getNextSentence()
Returns the sentence object succeeding this sentence in the sentences ArrayList of the corpus containing this sentence.

Returns:
The sentence succeeding this sentence.

getPrevSentence

public Sentence getPrevSentence()
Returns the sentence object predecessing this sentence in the sentences ArrayList of the corpus containing this sentence.

Returns:
The sentence predecessing this sentence.

getNextSentence

public Sentence getNextSentence(int n)
Returns the sentence object succeeding this sentence in the sentences ArrayList of the corpus containing this sentence by n.

Returns:
The sentence succeeding this sentence by n.

getPrevSentence

public Sentence getPrevSentence(int n)
Returns the sentence object predecessing this sentence in the sentences ArrayList of the corpus containing this sentence by n.

Returns:
The sentence predecessing this sentence by n.

getSpan

public java.lang.String getSpan()
Returns the MMAX-style span of the sentence.

Returns:
A String representing the span (e.g. "s1_1..s1_14")

getNTCount

public int getNTCount()
Returns the number of NT objects in the sentence.

Returns:
An integer denoting the number of NTs in this sentence.

getNoOfNTs

public int getNoOfNTs()
Deprecated. As of org.jscience.ml.tigerxml 1.1 - use getNTCount() instead.

Returns the number of NT objects in the sentence.

Returns:
An integer denoting the number of non-terminals in this sentence.

getNT

public NT getNT(int i)

getNT

public NT getNT(java.lang.String id)
Returns the NT which has the given ID. Returns null if the search fails. If the sentence of the NT is not known, Corpus#getNT(Stringid) can be used to retrieve the wanted NT.

Parameters:
id - The ID of the NT to be found.
Returns:
The NT that is identified by ID or null if the search fails.

getT

public T getT(java.lang.String id)
Returns the T which has the given ID. Returns null if the search fails. If the sentence of the T is not known, Corpus#getT(Stringid) can be used to retrieve the wanted T.

Parameters:
id - The ID of the T to be found.
Returns:
The T that is identified by ID or null if the search fails.

getGraphNode

public GraphNode getGraphNode(java.lang.String id)
Returns the GraphNode which has the given ID. Returns null if the search fails. If the sentence of the GraphNode is not known, Corpus#getGraphNode(Stringid) can be used to retrieve the wanted GraphNode.

Parameters:
id - The ID of the GraphNode to be found.
Returns:
The GraphNode that is identified by ID or null if the search fails.

getAllGraphNodes

public java.util.ArrayList getAllGraphNodes()
Returns all GraphNode objects contained in this sentence. The returned GraphNodes are in the order of the XML corpus file. In order to have the list ordered by linear precedence, use org.jscience.ml.tigerxml.tools.GeneralTools#sortNodes(ArrayListnodes).

The returned list does not contain the VROOT.

Ordering by class:
All NT objects of the sentence are followed by all T object of the corpus.

Returns:
All graph nodes contained in this Sentence.

getTerminal

public T getTerminal(java.lang.String id)
Returns the T which has the given ID. Returns null if the search fails. If the sentence of the T is not known, Corpus#getTerminal(Stringid) can be used to retrieve the wanted T.

Parameters:
id - The ID of the T to be found.
Returns:
The T that is identified by ID or null if the search fails.

getNTs

public java.util.ArrayList getNTs()

getTs

public java.util.ArrayList getTs()

addNT

public void addNT(NT newnt)

getRootNT

public NT getRootNT()
Returns the root node of the sentence (always an NT). Note that this method returns null if there is no sentence root but the VROOT at the top of the tree. That's the way NEGRA Syntax analyses simple sentences (headlines) like "Darmstadt-Braunschweig 1:0"

Returns:
The root NT, null if sth. goes wrong.

getVROOT

public NT getVROOT()
Returns the VROOT of this sentence. If necessary creates it first, linking all of its daughter nodes to it.

The virtual root node is imaginary and the only node that holds all other nodes.

Returns:
The virtual root node of this sentence - VROOT.

hasRootNT

public boolean hasRootNT()

getTCount

public int getTCount()
Returns the number of T objects in the sentence.

Returns:
An integer denoting the number of terminals in this sentence.

getNoOfTs

public int getNoOfTs()
Deprecated. As of org.jscience.ml.tigerxml 1.1 - use getTCount() instead.

Returns the number of T objects in the sentence.

Returns:
An integer denoting the number of terminals in this sentence.

getT

public T getT(int i)

addT

public void addT(T newt)

getText

public java.lang.String getText()

getTerminals

public java.util.ArrayList getTerminals()
Returns all terminal daughters. The returned terminals are in the order of the sentence (linear precedence).


toTreeString

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


printTree

public void printTree()
Prints the syntax tree structure of this sentence to stout.


printTreeErr

public void printTreeErr()
Prints the syntax tree structure of this sentence to stderr.


toString

public java.lang.String toString()
Returns the String representation of this Sentence - its ID.

Overrides:
toString in class java.lang.Object
Returns:
The String representation of this Sentence - its ID.

equals

public boolean equals(java.lang.Object obj)
Returns true if the object is identical to this Sentence object. Identity is determined by comparing the sentence IDs.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The Java Object to which this is to be compared to.
Returns:
True if the object is a sentence and the sentences are identical.
See Also:
getId()

hashCode

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

getById

public GraphNode getById(java.lang.String pass_id)
Finds and returns a GraphNode in this sentence or returns null if there is no GraphNode with the given ID.

Parameters:
pass_id - The ID of the GraphNode to be found.
Returns:
The GraphNode with the given ID or null.

addVNode

public void addVNode(VNode v_node)

hasVNode

public boolean hasVNode(java.lang.String v_node_id)

getVNode

public VNode getVNode(java.lang.String v_node_id)

print2Xml

protected void print2Xml(java.io.FileWriter out_xml)

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.