com.googlecode.whatswrong
Class Token

java.lang.Object
  extended by com.googlecode.whatswrong.Token
All Implemented Interfaces:
java.lang.Comparable<Token>

public class Token
extends java.lang.Object
implements java.lang.Comparable<Token>

A Token represents a word in an utterance. It consists of an index and a set of properties with name and value.

Author:
Sebastian Riedel

Constructor Summary
Token(int index)
          Creates a new token with the given index.
 
Method Summary
 void addProperty(int index, java.lang.String property)
          Add the property with name "Property [index]" and the given value.
 void addProperty(java.lang.String value)
          Adds a property with the given value.
 Token addProperty(java.lang.String name, java.lang.String value)
          Add a property with the given name and value.
 Token addProperty(TokenProperty property, java.lang.String value)
          Add a property with given value.
 int compareTo(Token o)
          Compares the indices of both tokens.
 boolean equals(java.lang.Object o)
          Checks whether the two tokens have the same index.
 int getIndex()
          Returns the index of the token.
 java.lang.String getProperty(TokenProperty property)
          Get the value of the given property.
 java.util.Collection<TokenProperty> getPropertyTypes()
          Return all token properties (the property names).
 java.util.Collection<java.lang.String> getPropertyValues()
          Returns a collection of all property values.
 java.util.List<TokenProperty> getSortedProperties()
          Sorts the properties by property level and name.
 int hashCode()
          Returns the index of the token.
 void merge(Token token)
          Inserts all properties and values of the other token into this token.
 boolean propertiesContain(java.util.Collection<java.lang.String> substrings, boolean wholeWord)
          Check whether any of the property values of this token contains any of the strings in the given set of strings.
 boolean propertiesContain(java.lang.String substring)
          Check whether any of the property values contains the given string.
 void removeProperty(int index)
          Remove the property value with given index.
 void removeProperty(java.lang.String name)
          Remove the property value with the given name.
 java.lang.String toString()
          Returns a string representation of this token containing token index and properties.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Token

public Token(int index)
Creates a new token with the given index.

Parameters:
index - the index of the token.
Method Detail

getIndex

public int getIndex()
Returns the index of the token.

Returns:
the index of the token.

getPropertyTypes

public java.util.Collection<TokenProperty> getPropertyTypes()
Return all token properties (the property names). To get the value of a property use getProperty(TokenProperty).

Returns:
a collection with token properties.

getProperty

public java.lang.String getProperty(TokenProperty property)
Get the value of the given property.

Parameters:
property - the property to get the value for.
Returns:
the value of the given property.

removeProperty

public void removeProperty(int index)
Remove the property value with given index.

Parameters:
index - the index of the property to remove.

removeProperty

public void removeProperty(java.lang.String name)
Remove the property value with the given name.

Parameters:
name - the name of the property to remove.

addProperty

public Token addProperty(java.lang.String name,
                         java.lang.String value)
Add a property with the given name and value.

Parameters:
name - the name of the property.
value - the value of the property.
Returns:
a pointer to this token.

addProperty

public void addProperty(int index,
                        java.lang.String property)
Add the property with name "Property [index]" and the given value.

Parameters:
index - the index of the property
property - the value of the property.

addProperty

public Token addProperty(TokenProperty property,
                         java.lang.String value)
Add a property with given value.

Parameters:
property - the property to add
value - the value of the property
Returns:
this token.

addProperty

public void addProperty(java.lang.String value)
Adds a property with the given value. The property name will be "Property i" where i this the current number of properties.

Parameters:
value - the value of the property.

getSortedProperties

public java.util.List<TokenProperty> getSortedProperties()
Sorts the properties by property level and name.

Returns:
a list of sorted token properties.

getPropertyValues

public java.util.Collection<java.lang.String> getPropertyValues()
Returns a collection of all property values.

Returns:
a collection of all property values.

propertiesContain

public boolean propertiesContain(java.lang.String substring)
Check whether any of the property values contains the given string.

Parameters:
substring - the string to check whether it is contained in any property value of this token.
Returns:
true iff there exists on property of this token for which substring is a substring of the corresponding property value.

propertiesContain

public boolean propertiesContain(java.util.Collection<java.lang.String> substrings,
                                 boolean wholeWord)
Check whether any of the property values of this token contains any of the strings in the given set of strings.

Parameters:
substrings - set of strings to check
wholeWord - should we check for complete words of is it enough for the given strings to be substrings of the token value.
Returns:
true iff a) if there is a property value equal to one of the strings in substrings (wholeword=true) or b) if there is a property value that contains one of the strings in substrings (wholeword=false).

equals

public boolean equals(java.lang.Object o)
Checks whether the two tokens have the same index. (Hence equality is only defined through the position of the token in the sentence.

Overrides:
equals in class java.lang.Object
Parameters:
o - the other token.
Returns:
index==((Token)o).index

hashCode

public int hashCode()
Returns the index of the token.

Overrides:
hashCode in class java.lang.Object
Returns:
the index of the token.

merge

public void merge(Token token)
Inserts all properties and values of the other token into this token. In case of clashes the value of the other token is taken.

Parameters:
token - the token to merge with.

compareTo

public int compareTo(Token o)
Compares the indices of both tokens.

Specified by:
compareTo in interface java.lang.Comparable<Token>
Parameters:
o - the other token.
Returns:
index - o.getIndex()

toString

public java.lang.String toString()
Returns a string representation of this token containing token index and properties.

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


Copyright © 2009. All Rights Reserved.