edu.upenn.cis.spinal
Class SpinalNode

java.lang.Object
  extended by edu.upenn.cis.spinal.SpinalNode

public class SpinalNode
extends Object

Represents the spine of a spinal elementary tree. A typical line in the treebank that contains a spine looks like this:

 b_( VP VB^ VP* )
 
However, the first letter indicates a property of the elementary tree (whether it is initial, auxiliary, or coordination) and is strictly speaking not a part of the spine, nor is the underscore folloing it. So we only consider the following a spine:
 ( VP VB^ VP* )
 
Other examples of spines:
 ( S ( VP VBD^ ) )
 
 ( S ( VP ( XP JJ^ ) ) )
 
 ( XP NONE^ )
 
 JJ^                       
 
 ( S S S )                 # a spine for predicate coordination
 
Spines may be of three shapes (Libin Shen's thesis, p. 15): Instances of this class are immutable as seen from the "public" view.

Author:
Lucas Champollion

Field Summary
static String ANCHOR
          Represents the character used to show that a node is an anchor node (the node where the word is attached), i.e.
static String ANCHORS
          Some alternative characters that might be used for the anchor because they look similar.
static String FOOT
          Represents the character used to show that a node is a foot node, in an auxiliary tree, i.e.
static String STANDARD
          Represents the character used to show that a node is neither an anchor nor a foot node (this character is the empty string in Libin Shen's treebank).
 
Constructor Summary
protected SpinalNode(List list, ElemTree host)
          Creates an instance of SpinalNode from a tokenized list of strings.
  SpinalNode(String s, ElemTree host)
          Creates a new instance of SpinalNode from a string representation.
 
Method Summary
 List getAllNodes()
          Returns a list of all the descendents of this spinal node, including itself.
 SpinalNode getChild(int n)
          Returns the specified child of this spinal node.
 SpinalNode[] getChildren()
          Returns an array of children, or null if there are no children to this node.
 List getChildrenList()
          Returns a list of children, or an empty list if there are no children to this node.
 ElemTree getElemTree()
          Gets the elementary tree to which this spine or spinal node belongs.
 String getLabel()
          Gets the label of this spinal node.
 GornAddress getLocationInSpine()
          Returns the GornAddress of this spinal node, relative to the root of the spine in which it is contained (rather than the root of the derivation tree in which it is contained).
 SpinalNode getParent(boolean acrossElemTrees)
          Returns the SpinalNode that is the parent of this node.
 String getType()
          Gets the type of this SpinalNode.
 boolean isAnchor()
          Returns whether this node is an anchor node.
 boolean isFoot()
          Returns whether this node is a foot node.
 boolean isRootOfSpine()
          Returns whether this node is at the root of its spine.
 boolean isStandard()
          Returns whether this node is a standard node (neither foot nor anchor).
 String toString()
          Returns a canonical representation of the subtree rooted in this spinal node (e.g.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANCHOR

public static final String ANCHOR
Represents the character used to show that a node is an anchor node (the node where the word is attached), i.e. "^".

See Also:
Constant Field Values

ANCHORS

public static final String ANCHORS
Some alternative characters that might be used for the anchor because they look similar. These are:

See Also:
Constant Field Values

FOOT

public static final String FOOT
Represents the character used to show that a node is a foot node, in an auxiliary tree, i.e. "*".

See Also:
Constant Field Values

STANDARD

public static final String STANDARD
Represents the character used to show that a node is neither an anchor nor a foot node (this character is the empty string in Libin Shen's treebank).

See Also:
Constant Field Values
Constructor Detail

SpinalNode

public SpinalNode(String s,
                  ElemTree host)
           throws ElemTreeFormatException
Creates a new instance of SpinalNode from a string representation.

Parameters:
s - the string representation from which to create the SpinalNode
host - the ElemTree to which the spine belongs of which this SpinalNode is a member, or null if you don't wish to specify it
Throws:
ElemTreeFormatException - if the input string can't be parsed

SpinalNode

protected SpinalNode(List list,
                     ElemTree host)
              throws ElemTreeFormatException
Creates an instance of SpinalNode from a tokenized list of strings. The list is not modified during the construction of the SpinalNode.

Parameters:
list - the list of strings
host - the ElemTree to which the spine belongs of which this SpinalNode is a member, or null if you don't wish to specify it
Throws:
ElemTreeFormatException - if list is empty
NullPointerException - if list is null
Method Detail

getLabel

public String getLabel()
Gets the label of this spinal node.

Returns:
A string, e.g. XP or NNS. Characters that denote foot nodes or anchors are not returned.

getType

public String getType()
Gets the type of this SpinalNode. Returns one of "ANCHOR", "FOOT", or "STANDARD".

Returns:
Either ANCHOR, FOOT, or STANDARD

isAnchor

public boolean isAnchor()
Returns whether this node is an anchor node.

Returns:
a boolean value

isFoot

public boolean isFoot()
Returns whether this node is a foot node.

Returns:
a boolean value

isStandard

public boolean isStandard()
Returns whether this node is a standard node (neither foot nor anchor).

Returns:
a boolean value

getChildren

public SpinalNode[] getChildren()
Returns an array of children, or null if there are no children to this node. Children are understood as children nodes within the spine of this elementary tree, not as other elementary trees.

Returns:
the children of this spinal node

getChildrenList

public List getChildrenList()
Returns a list of children, or an empty list if there are no children to this node. Children are understood as children nodes within the spine of this elementary tree, not as other elementary trees.

Returns:
the children of this spinal node

getAllNodes

public List getAllNodes()
Returns a list of all the descendents of this spinal node, including itself.

Returns:
the descendents of this node

getChild

public SpinalNode getChild(int n)
Returns the specified child of this spinal node.

Parameters:
n - a number specifying the child, starting with zero.
Returns:
a SpinalNode for the child
Throws:
ArrayIndexOutOfBoundsException - if this node does not have as many children as the specified index

getLocationInSpine

public GornAddress getLocationInSpine()
Returns the GornAddress of this spinal node, relative to the root of the spine in which it is contained (rather than the root of the derivation tree in which it is contained).

Returns:
a Gorn address, such as 0 for the root of the spine

toString

public String toString()
Returns a canonical representation of the subtree rooted in this spinal node (e.g. (XP NNS^)).

Overrides:
toString in class Object
Returns:
a string.

getElemTree

public ElemTree getElemTree()
Gets the elementary tree to which this spine or spinal node belongs.

Returns:
the host tree

getParent

public SpinalNode getParent(boolean acrossElemTrees)
Returns the SpinalNode that is the parent of this node.

Parameters:
acrossElemTrees - if true, then if this node is at the root of its ElemTree, then the attachment site in the parent ElemTree will be returned; otherwise if this node is at the root of its ElemTree, null will be returned
Returns:
the parent of this node in the spine

isRootOfSpine

public boolean isRootOfSpine()
Returns whether this node is at the root of its spine.

Returns:
a boolean value