com.googlecode.whatswrong
Class NLPInstance

java.lang.Object
  extended by com.googlecode.whatswrong.NLPInstance

public class NLPInstance
extends java.lang.Object

An NLPInstance represents a sentence or any other kind of utterance and some of its (NLP) properties. Properties of sentence are its tokens, that have their own properties, and edges between tokens. Such edges can represent syntactic or semantic dependencies, such as SRL predicate-argument relations, as well as annotated spans (such as NP chunks or NER entities).

Author:
Sebastian Riedel

Nested Class Summary
static class NLPInstance.RenderType
           
 
Constructor Summary
NLPInstance()
          Creates an empty NLPInstance without edges or tokens.
NLPInstance(java.util.Collection<Token> tokens, java.util.Collection<Edge> edges, NLPInstance.RenderType renderType, java.util.List<java.lang.Integer> splitPoints)
          Creates a new NLPInstance with the given tokens and edges.
 
Method Summary
 void addDependency(int from, int to, java.lang.String label, java.lang.String type)
          Creates and adds an edge with rendertype Edge.RenderType.dependency
 void addEdge(Edge edge)
          Adds an edge.
 void addEdge(int from, int to, java.lang.String label, java.lang.String type)
          Creates and adds an edge from the token at the given 'from' index to the token at the given 'to' index with the given label and type.
 void addEdge(int from, int to, java.lang.String label, java.lang.String type, Edge.RenderType renderType)
          Creates and adds a new edge with the given properties.
 void addEdge(Token from, Token to, java.lang.String label, java.lang.String type)
          Creates and adds an edge with the given properties.
 void addEdge(Token from, Token to, java.lang.String label, java.lang.String type, Edge.RenderType renderType)
          Creates and adds an edge with the given properties.
 void addEdges(java.util.Collection<Edge> edges)
          Adds the given edges to this instance.
 void addSpan(int from, int to, java.lang.String label, java.lang.String type)
          Creates and adds an edge with rendertype Edge.RenderType.span
 void addSplitPoint(int tokenIndex)
          Add a split point token index.
 Token addToken()
          Adds a new token and returns it.
 Token addToken(int index)
          Adds a token at a certain index.
 void addTokens(java.util.Collection<Token> tokens)
          Adds the given collection of tokens to this instance.
 void addTokenWithProperties(java.lang.String... properties)
          Adds token that has the provided properties with default property names.
 void consistify()
          If tokesn were added with addToken(int) this method ensures that all internal representations of the token sequence are consistent.
 java.util.List<Edge> getEdges()
          Returns all edges of this instance.
 java.util.List<Edge> getEdges(Edge.RenderType renderType)
          Returns all edges of this instance with the given render type.
 NLPInstance.RenderType getRenderType()
          Returns the render type that controls which renderer to use.
 java.util.List<java.lang.Integer> getSplitPoints()
          Returns the list of split points for this instance.
 Token getToken(int index)
          Returns the token at the given index.
 java.util.List<Token> getTokens()
          Returns a list of all tokens in this instance.
 void merge(NLPInstance nlp)
          Merges the given instance with this instance.
 void setRenderType(NLPInstance.RenderType renderType)
          Sets the render type for this instance.
 java.lang.String toString()
          Returns a string representation of this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NLPInstance

public NLPInstance()
Creates an empty NLPInstance without edges or tokens.


NLPInstance

public NLPInstance(java.util.Collection<Token> tokens,
                   java.util.Collection<Edge> edges,
                   NLPInstance.RenderType renderType,
                   java.util.List<java.lang.Integer> splitPoints)
Creates a new NLPInstance with the given tokens and edges. The passed collections will be copied and not changed.

Parameters:
tokens - the tokens of the sentence.
edges - the edges of the sentence.
renderType - the render type for the instance.
splitPoints - the points at which the instance can be split.
Method Detail

getRenderType

public NLPInstance.RenderType getRenderType()
Returns the render type that controls which renderer to use.

Returns:
the render type for this instance.

setRenderType

public void setRenderType(NLPInstance.RenderType renderType)
Sets the render type for this instance.

Parameters:
renderType - the render type for this instance.

addEdge

public void addEdge(int from,
                    int to,
                    java.lang.String label,
                    java.lang.String type)
Creates and adds an edge from the token at the given 'from' index to the token at the given 'to' index with the given label and type. The edge will have the default render type.

Parameters:
from - index of the token the edge should start at. The token at the given index must already exist in the sentence.
to - index of the token edge should end at. The token at the given index must already exist in the sentence.
label - the label of the edge.
type - the type of edge.
See Also:
Edge

addEdge

public void addEdge(int from,
                    int to,
                    java.lang.String label,
                    java.lang.String type,
                    Edge.RenderType renderType)
Creates and adds a new edge with the given properties.

Parameters:
from - index of the token the edge should start at. The token at the given index must already exist in the sentence.
to - index of the token edge should end at. The token at the given index must already exist in the sentence.
label - the label of the edge.
type - the type of edge.
renderType - the render type of the edge.
See Also:
Edge

addEdge

public void addEdge(Edge edge)
Adds an edge.

Parameters:
edge - the edge to add.

addSpan

public void addSpan(int from,
                    int to,
                    java.lang.String label,
                    java.lang.String type)
Creates and adds an edge with rendertype Edge.RenderType.span

Parameters:
from - index of the token the edge should start at. The token at the given index must already exist in the sentence.
to - index of the token edge should end at. The token at the given index must already exist in the sentence.
label - the label of the edge.
type - the type of edge.
See Also:
Edge

addDependency

public void addDependency(int from,
                          int to,
                          java.lang.String label,
                          java.lang.String type)
Creates and adds an edge with rendertype Edge.RenderType.dependency

Parameters:
from - index of the token the edge should start at. The token at the given index must already exist in the sentence.
to - index of the token edge should end at. The token at the given index must already exist in the sentence.
label - the label of the edge.
type - the type of edge.
See Also:
Edge

addEdge

public void addEdge(Token from,
                    Token to,
                    java.lang.String label,
                    java.lang.String type)
Creates and adds an edge with the given properties. It will have the default render type.

Parameters:
from - The start token. The created edge will start at the token of this sentence with the same index as the provided token. This means the start token of created edge does not need to be equal to the provided token -- they just have to have the same index.
to - the end token. The created edge will end at the token of this sentence with the same index as the provided token. This means that the end token of created edge does not need to be equal to the provided token -- they just have to have the same index.
label - the label of the edge.
type - the type of edge.
See Also:
Edge

addEdge

public void addEdge(Token from,
                    Token to,
                    java.lang.String label,
                    java.lang.String type,
                    Edge.RenderType renderType)
Creates and adds an edge with the given properties. It will have the default render type.

Parameters:
from - The start token. The created edge will start at the token of this sentence with the same index as the provided token. This means the start token of created edge does not need to be equal to the provided token -- they just have to have the same index.
to - the end token. The created edge will end at the token of this sentence with the same index as the provided token. This means that the end token of created edge does not need to be equal to the provided token -- they just have to have the same index.
label - the label of the edge.
type - the type of edge.
renderType - the render type of the edge.
See Also:
Edge

addTokens

public void addTokens(java.util.Collection<Token> tokens)
Adds the given collection of tokens to this instance.

Parameters:
tokens - the tokens to add.

addEdges

public void addEdges(java.util.Collection<Edge> edges)
Adds the given edges to this instance.

Parameters:
edges - the edges to add.

merge

public void merge(NLPInstance nlp)
Merges the given instance with this instance. A merge will add for every token i all properties of the token i of the passed instance nlp. It will also add every edge between i and i in the given instance nlp as an edge between the tokens i and j of this instance, using the same type, label and rendertype as the original edge.

Parameters:
nlp - the instance to merge into this instance.

addTokenWithProperties

public void addTokenWithProperties(java.lang.String... properties)
Adds token that has the provided properties with default property names.

Parameters:
properties - an vararray of strings.

addToken

public Token addToken()
Adds a new token and returns it.

Returns:
the token that was added.

addToken

public Token addToken(int index)
Adds a token at a certain index. This method can be used when we don't want to build the sentence in order. Note that if you build the instance using this method you have to call consistify() when you are done.

Parameters:
index - the index of the token to add.
Returns:
the token that was added.

consistify

public void consistify()
If tokesn were added with addToken(int) this method ensures that all internal representations of the token sequence are consistent.


addSplitPoint

public void addSplitPoint(int tokenIndex)
Add a split point token index.

Parameters:
tokenIndex - a token index at which the instance should be split.

getSplitPoints

public java.util.List<java.lang.Integer> getSplitPoints()
Returns the list of split points for this instance. A split point is a point at which renderers can split the token list.

Returns:
the list of split points.

getEdges

public java.util.List<Edge> getEdges()
Returns all edges of this instance.

Returns:
all edges of this instance as unmodifiable list.

getEdges

public java.util.List<Edge> getEdges(Edge.RenderType renderType)
Returns all edges of this instance with the given render type.

Parameters:
renderType - the render type of the edges to return.
Returns:
all edges of this instance with the given render type. This list can be altered if needed.

getToken

public Token getToken(int index)
Returns the token at the given index.

Parameters:
index - the index of the token to return
Returns:
the token at the given index.

getTokens

public java.util.List<Token> getTokens()
Returns a list of all tokens in this instance.

Returns:
an unmodifiable list of all tokens of this sentence, in the right order.

toString

public java.lang.String toString()
Returns a string representation of this instance. Mostly for debugging purposes.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this instance.


Copyright © 2009. All Rights Reserved.