org.itc.irst.tcc.sre.util
Class FeatureIndex

java.lang.Object
  extended by org.itc.irst.tcc.sre.util.FeatureIndex

public class FeatureIndex
extends java.lang.Object

An object that maps features to indexes. A FeatureIndex cannot contain duplicate features; each feature can map to at most one index.

Since:
1.0
Version:
%I%, %G%
Author:
Claudio Giuliano
See Also:
FeatureIndex

Field Summary
private  int count
          to do.
(package private) static org.apache.log4j.Logger logger
          Define a static logger variable so that it references the Logger instance named FeatureIndex.
private  java.util.SortedMap map
          to do.
private  boolean readOnly
          to do.
 
Constructor Summary
FeatureIndex(boolean readOnly)
          Constructs a FeatureIndex object.
FeatureIndex(boolean readOnly, int count)
          Constructs a FeatureIndex object.
 
Method Summary
 void clear()
           
 java.util.Set featureSet()
           
 int getIndex(java.lang.String feature)
          Returns the index of the specified feature and adds the feature to the index if it is not present yet.
 int put(java.lang.String feature)
          Returns the index of the specified feature and adds the feature to the index if it is not present yet.
 void read(java.io.Reader in)
          Reads the feature index from the specified input stream.
 int size()
           
 java.lang.String toString()
          Returns a String object representing this Word.
 void write(java.io.Writer out)
          Writes the feature index into the specified output stream in a format suitable for loading into a Map using the write method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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 FeatureIndex.


map

private java.util.SortedMap map
to do.


count

private int count
to do.


readOnly

private boolean readOnly
to do.

Constructor Detail

FeatureIndex

public FeatureIndex(boolean readOnly)
Constructs a FeatureIndex object.


FeatureIndex

public FeatureIndex(boolean readOnly,
                    int count)
Constructs a FeatureIndex object.

Method Detail

put

public int put(java.lang.String feature)
Returns the index of the specified feature and adds the feature to the index if it is not present yet.

Parameters:
feature - the feature.
Returns:
the index of the specified feature.

size

public int size()

getIndex

public int getIndex(java.lang.String feature)
Returns the index of the specified feature and adds the feature to the index if it is not present yet.

Parameters:
feature - the feature.
Returns:
the index of the specified feature.

featureSet

public java.util.Set featureSet()

clear

public void clear()

toString

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

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

write

public void write(java.io.Writer out)
           throws java.io.IOException
Writes the feature index into the specified output stream in a format suitable for loading into a Map using the write method.

Parameters:
out - a Writer object to provide the underlying stream.
Throws:
java.io.IOException - if writing this feature index to the specified output stream throws an IOException.

read

public void read(java.io.Reader in)
          throws java.io.IOException
Reads the feature index from the specified input stream.

This method processes input in features of lines. A natural line of input is terminated either by a set of line terminator characters (\n or \r or \r\n) or by the end of the file. A natural line may be either a blank line, a comment line, or hold some part of a id-feature pair. Lines are read from the input stream until end of file is reached.

A natural line that contains only white space characters is considered blank and is ignored. A comment line has an ASCII '#' as its first non-white space character; comment lines are also ignored and do not encode id-feature information.

The id contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first '\t'. All remaining characters on the line become part of the associated feature string; if there are no remaining characters, the feature is the empty string "".

Parameters:
in - a Reader object to provide the underlying stream.
Throws:
java.io.IOException - if reading this feature index from the specified input stream throws an IOException.