org.itc.irst.tcc.ties.data.patterns
Class Pattern

java.lang.Object
  extended byorg.itc.irst.tcc.ties.data.patterns.Pattern
All Implemented Interfaces:
java.io.Serializable

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

A Pattern object represents a specific sequence of features derived from the left or right context of a given example. The class implements the Serializable interface so that instances may be saved to disk if desired.

Since:
1.0
Version:
%I%, %G%
Author:
Claudio Giuliano
See Also:
Feature, Serialized Form

Field Summary
private  int hashCode
          The hash code value for this Pattern
(package private) static org.apache.log4j.Logger logger
          Define a static logger variable so that it references the Logger instance named Pattern.
private  java.util.List pattern
          The Pattern.
private  int pattType
          The Pattern type
static int PREFIX
          The prefix constant.
static int SUFFIX
          The suffix constant.
 
Constructor Summary
  Pattern(int pattType)
          Allocates a new Pattern object containing no tokens.
private Pattern(int pattType, java.util.List tokens, int hashCode)
          Allocates a new Pattern object that represents the sequence of tokens currently contained in the feat list argument.
 
Method Summary
 void addToken(Feature feat)
          Adds the specified feat in this Pattern, if the Pattern is a PREFIX inserts the specified feat at the first position and shifts the element currently at first position (if any) and any subsequent elements to the right (adds one to their indices); otherwise, if the Pattern is a SUFFIX adds the specified feat at the ending in this Pattern
private  void addToken(Feature feat, boolean b)
          Adds the specified feat in this Pattern, if the Pattern is a PREFIX inserts the specified feat at the first position and shifts the element currently at first position (if any) and any subsequent elements to the right (adds one to their indices); otherwise, if the Pattern is a SUFFIX adds the specified feat at the ending in this Pattern
 boolean containsAll(Feature feat)
          Returns true if this Pattern contains all the tokens equals to the specified feat.
 Pattern duplicate()
          Returns a copy of this Pattern.
 boolean endsWith(Pattern suffix)
          Tests if this Pattern ends with the specified suffix.
 boolean equals(java.lang.Object anObject)
          Compares this Pattern to the specified object.
 Feature firstElement()
          Returns the first component (the item at index 0) of this Pattern.
 Feature get(int index)
          Returns the Feature object at the specified index.
 int getPatternType()
          Returns the Pattern type.
 Feature getTokenAt(int index)
          Returns the Feature object at the specified index.
 java.util.List getTokens()
          Returns the Pattern as a list of Feature objects.
 int hashCode()
          Returns the hash code value for this Pattern.
 boolean isEmpty()
          Tests if this Pattern has no components.
 Feature lastElement()
          Returns the last component (the item at index Pattern.size() - 1) of this Pattern.
 int length()
          Returns the number of tokens in this Pattern.
static void main(java.lang.String[] args)
           
 void rehash()
          Forces to recompute the hash code value for this Pattern.
 void setTokenAt(Feature feat, int index)
          Sets the feat at the specified index of this Pattern to be the specified feat.
 boolean startsWith(Pattern prefix)
          Tests if this Pattern starts with the specified prefix.
 boolean startsWith(Pattern prefix, int toffset)
          Tests if this Pattern starts with the specified prefix.
 Pattern subpattern(int beginIndex)
          Returns a new Pattern that is a subpattern of this Pattern.
 Pattern subpattern(int beginIndex, int endIndex)
          Returns a new Pattern that is a subpattern of this Pattern.
 java.lang.String toString()
          Returns a String object representing this Pattern.
 java.lang.String toXML()
          Returns a String object representing this Pattern in XML.
 Pattern trim(Feature feat)
          Trims the specified argument from the begining and end of this Pattern.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger
Define a static logger variable so that it references the Logger instance named Pattern.


PREFIX

public static final int PREFIX
The prefix constant.

See Also:
Constant Field Values

SUFFIX

public static final int SUFFIX
The suffix constant.

See Also:
Constant Field Values

pattern

private java.util.List pattern
The Pattern.


hashCode

private int hashCode
The hash code value for this Pattern


pattType

private int pattType
The Pattern type

Constructor Detail

Pattern

public Pattern(int pattType)
Allocates a new Pattern object containing no tokens.

Parameters:
pattType - the Pattern type.

Pattern

private Pattern(int pattType,
                java.util.List tokens,
                int hashCode)
Allocates a new Pattern object that represents the sequence of tokens currently contained in the feat list argument.

Parameters:
pattType - the Pattern type.
tokens - the sequence of tokens.
hashCode - the hash code.
Method Detail

getTokens

public java.util.List getTokens()
Returns the Pattern as a list of Feature objects.

Returns:
a list of Feature objects.

getTokenAt

public Feature getTokenAt(int index)
Returns the Feature object at the specified index.

Parameters:
index - an index into this Pattern.
Returns:
the feat at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - index is out of range (index < 0 || index >= length()).

get

public Feature get(int index)
Returns the Feature object at the specified index.

Parameters:
index - an index into this Pattern.
Returns:
the feat at the specified index.
Throws:
java.lang.IndexOutOfBoundsException - index is out of range (index < 0 || index >= length()).

firstElement

public Feature firstElement()
Returns the first component (the item at index 0) of this Pattern.

Returns:
the first component of this Pattern.
Throws:
java.util.NoSuchElementException - if this Pattern has no components.

lastElement

public Feature lastElement()
Returns the last component (the item at index Pattern.size() - 1) of this Pattern.

Returns:
the last component of this Pattern.
Throws:
java.util.NoSuchElementException - if this Pattern has no components.

getPatternType

public int getPatternType()
Returns the Pattern type.

Returns:
the Pattern type.

trim

public Pattern trim(Feature feat)
Trims the specified argument from the begining and end of this Pattern.

Returns:
the trimmed Pattern.

containsAll

public boolean containsAll(Feature feat)
Returns true if this Pattern contains all the tokens equals to the specified feat.

Parameters:
feat - an index into this Pattern.
Returns:
true if this Pattern contains all the tokens equals to the specified feat; false otherwise;

startsWith

public boolean startsWith(Pattern prefix,
                          int toffset)
Tests if this Pattern starts with the specified prefix.

Parameters:
prefix - the prefix.
toffset - where to begin looking in the Pattern.
Returns:
true if the feat sequence represented by the argument is a prefix of the feat sequence represented by this Pattern; false otherwise.

startsWith

public boolean startsWith(Pattern prefix)
Tests if this Pattern starts with the specified prefix.

Parameters:
prefix - the prefix.
Returns:
true if the feat sequence represented by the argument is a prefix of the feat sequence represented by this Pattern; false otherwise.

endsWith

public boolean endsWith(Pattern suffix)
Tests if this Pattern ends with the specified suffix.

Parameters:
suffix - the suffix.
Returns:
true if the feat sequence represented by the argument is a suffix of the feat sequence represented by this object; false otherwise.

length

public int length()
Returns the number of tokens in this Pattern.

Returns:
the number of tokens in this Pattern.

addToken

public void addToken(Feature feat)
Adds the specified feat in this Pattern, if the Pattern is a PREFIX inserts the specified feat at the first position and shifts the element currently at first position (if any) and any subsequent elements to the right (adds one to their indices); otherwise, if the Pattern is a SUFFIX adds the specified feat at the ending in this Pattern

Parameters:
feat - the Pattern feat to be added.

addToken

private void addToken(Feature feat,
                      boolean b)
Adds the specified feat in this Pattern, if the Pattern is a PREFIX inserts the specified feat at the first position and shifts the element currently at first position (if any) and any subsequent elements to the right (adds one to their indices); otherwise, if the Pattern is a SUFFIX adds the specified feat at the ending in this Pattern

Parameters:
feat - the Pattern feat to be added.
b - true if the feat has to be added in reverse order.

rehash

public void rehash()
Forces to recompute the hash code value for this Pattern.


hashCode

public int hashCode()
Returns the hash code value for this Pattern.

Returns:
the hash code value for this Pattern.

equals

public boolean equals(java.lang.Object anObject)
Compares this Pattern to the specified object. The result is true if and only if the argument is not null and is a Pattern object that represents the same sequence of tokens as this object.

Parameters:
anObject - the object to compare this Pattern against.
Returns:
true if the Pattern are equal; false otherwise.

isEmpty

public final boolean isEmpty()
Tests if this Pattern has no components.

Returns:
true if this Pattern has no components; false otherwise.

setTokenAt

public void setTokenAt(Feature feat,
                       int index)
Sets the feat at the specified index of this Pattern to be the specified feat. The previous feat at that position is discarded.

The index must be a value greater than or equal to 0 and less than the current length of the Pattern.

Parameters:
feat - what the feat is to be set to.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

toString

public java.lang.String toString()
Returns a String object representing this Pattern.

Returns:
a string representation of the object.

toXML

public java.lang.String toXML()
Returns a String object representing this Pattern in XML.

Returns:
a string representation of the object in XML.

subpattern

public Pattern subpattern(int beginIndex)
Returns a new Pattern that is a subpattern of this Pattern. The subpattern begins with the feat at the specified index and extends to the end of this Pattern.

Parameters:
beginIndex - the beginning index, inclusive.
Returns:
the specified subpattern.
Throws:
java.lang.IndexOutOfBoundsException - if the beginIndex or the endIndex is out of range.

subpattern

public Pattern subpattern(int beginIndex,
                          int endIndex)
Returns a new Pattern that is a subpattern of this Pattern. The subpattern begins at the specified beginIndex and extends to the feat at index endIndex - 1.

Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified subpattern.
Throws:
java.lang.IndexOutOfBoundsException - if the beginIndex or the endIndex is out of range.

duplicate

public Pattern duplicate()
Returns a copy of this Pattern.

Returns:
a copy of this Pattern.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception