edu.washington.cs.knowitall.sequence
Class SimpleLayeredSequence

java.lang.Object
  extended by edu.washington.cs.knowitall.sequence.SimpleLayeredSequence
All Implemented Interfaces:
LayeredSequence
Direct Known Subclasses:
BIOLayeredSequence, NormalizedField

public class SimpleLayeredSequence
extends Object
implements LayeredSequence

An immutable implementation of LayeredSequence. This class represents a sequence with multiple layers (e.g. a sentence with words and part-of-speech tags). In this implementation, the length of the sequence is fixed and the values at each position in the sequence cannot be changed. New layers can be added.

Author:
afader

Constructor Summary
SimpleLayeredSequence(int length)
          Constructs a new layered sequence with the given length
 
Method Summary
 void addLayer(String layerName, com.google.common.collect.ImmutableList<String> layer)
          Adds a new layer to the sequence
 void addLayer(String layerName, List<String> layer)
          Adds a new layer to the sequence.
 void addLayer(String layerName, String[] layer)
          Adds a new layer to the sequence
 boolean equals(Object obj)
           
 String get(String layerName, int index)
           
 com.google.common.collect.ImmutableList<String> getLayer(String layerName)
           
 String getLayerAsString(String layerName)
           
 String getLayerAsString(String layerName, int start, int length)
           
 String getLayerAsString(String layerName, edu.washington.cs.knowitall.commonlib.Range r)
           
 Collection<String> getLayerNames()
           
 int getLength()
           
 int getNumLayers()
           
 SimpleLayeredSequence getSubSequence(int start, int length)
          Returns the subsequence of this layered sequence starting at the given position with the given length
 SimpleLayeredSequence getSubSequence(edu.washington.cs.knowitall.commonlib.Range r)
          Returns the subsequence of this layered sequence starting at the given position with the given length
 com.google.common.collect.ImmutableList<String> getSubSequence(String layerName, int start, int length)
           
 List<String> getSubSequence(String layerName, edu.washington.cs.knowitall.commonlib.Range r)
           
 int hashCode()
           
 boolean hasLayer(String layerName)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleLayeredSequence

public SimpleLayeredSequence(int length)
Constructs a new layered sequence with the given length

Parameters:
length -
Method Detail

getLayer

public com.google.common.collect.ImmutableList<String> getLayer(String layerName)
Parameters:
layerName -
Returns:
an immutable list of the layer

getNumLayers

public int getNumLayers()
Specified by:
getNumLayers in interface LayeredSequence
Returns:
the number of layers

getLength

public int getLength()
Specified by:
getLength in interface LayeredSequence
Returns:
the length of the sequence

addLayer

public void addLayer(String layerName,
                     com.google.common.collect.ImmutableList<String> layer)
              throws SequenceException
Adds a new layer to the sequence

Parameters:
layerName -
layer -
Throws:
SequenceException - if a layer with layerName already exists or the given layer has the incorrect length

addLayer

public void addLayer(String layerName,
                     List<String> layer)
Adds a new layer to the sequence. An immutable list will be instantiated around layer.

Parameters:
layerName -
layer -
Throws:
SequenceException - if a layer with layerName already exists or the given layer has the incorrect length

addLayer

public void addLayer(String layerName,
                     String[] layer)
              throws SequenceException
Adds a new layer to the sequence

Parameters:
layerName -
layer -
Throws:
SequenceException - if a layer with layerName already exists or the given layer has the incorrect length

hasLayer

public boolean hasLayer(String layerName)
Specified by:
hasLayer in interface LayeredSequence
Parameters:
layerName -
Returns:
true if this sequence has a layer with the given name

get

public String get(String layerName,
                  int index)
Specified by:
get in interface LayeredSequence
Returns:
the value of the given layer at the given index

getSubSequence

public com.google.common.collect.ImmutableList<String> getSubSequence(String layerName,
                                                                      int start,
                                                                      int length)
Parameters:
layerName -
start -
length -
Returns:
an immutable subsequence of the layer

getSubSequence

public List<String> getSubSequence(String layerName,
                                   edu.washington.cs.knowitall.commonlib.Range r)
Parameters:
layerName -
r -
Returns:
an immutable subsequence of the layer

getSubSequence

public SimpleLayeredSequence getSubSequence(int start,
                                            int length)
Returns the subsequence of this layered sequence starting at the given position with the given length

Parameters:
start -
length -
Returns:

getSubSequence

public SimpleLayeredSequence getSubSequence(edu.washington.cs.knowitall.commonlib.Range r)
Returns the subsequence of this layered sequence starting at the given position with the given length

Parameters:
r -
Returns:

getLayerNames

public Collection<String> getLayerNames()
Specified by:
getLayerNames in interface LayeredSequence
Returns:
the layer names

getLayerAsString

public String getLayerAsString(String layerName)
Parameters:
layerName -
Returns:
the tokens in the given layer name, joined by spaces

getLayerAsString

public String getLayerAsString(String layerName,
                               edu.washington.cs.knowitall.commonlib.Range r)
Parameters:
layerName -
r -
Returns:
the tokens in the given layer name in the given range, joined by spaces

getLayerAsString

public String getLayerAsString(String layerName,
                               int start,
                               int length)
Parameters:
layerName -
start -
length -
Returns:
returns the tokens of the given layer name, joined by spaces, starting at the start position and ending at start+length

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 2010-2012 University of Washington CSE. All Rights Reserved.