edu.washington.cs.knowitall.sequence
Class BIOLayeredSequence

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

public class BIOLayeredSequence
extends SimpleLayeredSequence

Represents a layered sequence where some of the layers can be spans of tags, encoded using B/I/O prefixes. For example, the sequence of tags O B-X I-X O B-Y O B-Z B-Z I-Z represents four spans at positions 1-2, 4, 6, and 7-8.

Author:
afader

Constructor Summary
BIOLayeredSequence(int length)
          Constructs a new BIOLayeredSequence class.
 
Method Summary
 void addSpanLayer(String layerName, List<String> input)
          Adds a new layer to this sequence, but interprets it using B/I/O notation.
 void addSpanLayerRanges(String layerName, String tag, List<edu.washington.cs.knowitall.commonlib.Range> ranges)
          Adds a new span layer to this sequence.
 BIOLayeredSequence clone()
          Creates a copy of this object.
 List<edu.washington.cs.knowitall.commonlib.Range> getSpans(String layerName)
          Returns the ranges of all of the spans on the given layer.
 com.google.common.collect.ImmutableCollection<edu.washington.cs.knowitall.commonlib.Range> getSpans(String layerName, String type)
          Returns the ranges of all of the spans on the given layer that are of the given type (e.g.
 BIOLayeredSequence getSubSequence(int start, int length)
          Constructs a new subsequence from this instance.
 BIOLayeredSequence getSubSequence(edu.washington.cs.knowitall.commonlib.Range r)
          Constructs a new subsequence from this instance.
 com.google.common.collect.ImmutableList<String> getSubSequence(String layerName, int start, int length)
          Returns a subsequence of the given layer.
 com.google.common.collect.ImmutableList<String> getSubSequence(String layerName, edu.washington.cs.knowitall.commonlib.Range r)
          Returns a subsequence of the given layer.
protected  boolean isSpanLayer(String layerName)
           
 
Methods inherited from class edu.washington.cs.knowitall.sequence.SimpleLayeredSequence
addLayer, addLayer, addLayer, equals, get, getLayer, getLayerAsString, getLayerAsString, getLayerAsString, getLayerNames, getLength, getNumLayers, hashCode, hasLayer
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BIOLayeredSequence

public BIOLayeredSequence(int length)
Constructs a new BIOLayeredSequence class.

Parameters:
length -
Method Detail

clone

public BIOLayeredSequence clone()
Creates a copy of this object.

Overrides:
clone in class Object

getSpans

public List<edu.washington.cs.knowitall.commonlib.Range> getSpans(String layerName)
Returns the ranges of all of the spans on the given layer.

Parameters:
layerName -
Returns:
a list of ranges in order

getSpans

public com.google.common.collect.ImmutableCollection<edu.washington.cs.knowitall.commonlib.Range> getSpans(String layerName,
                                                                                                           String type)
Returns the ranges of all of the spans on the given layer that are of the given type (e.g. will return all B-X/I-X given X).

Parameters:
layerName -
type -
Returns:

addSpanLayer

public void addSpanLayer(String layerName,
                         List<String> input)
                  throws SequenceException
Adds a new layer to this sequence, but interprets it using B/I/O notation. This means that each tag must start with B-, I-, or equal O. Any tag that equals I-X for some string X must come immediately after either I-X or B-X.

Parameters:
layerName -
input -
Throws:
SequenceException - if unable to add a layer with the given name, or if input does not follow the B/I/O encoding.

addSpanLayerRanges

public void addSpanLayerRanges(String layerName,
                               String tag,
                               List<edu.washington.cs.knowitall.commonlib.Range> ranges)
                        throws SequenceException
Adds a new span layer to this sequence. The span layer encodes the given tag and the B/I/O encoding. For example, if tag = "NP" then this will add B-NP, I-NP, and O tags at the indexes covered by ranges. The ranges must not overlap.

Parameters:
layerName -
tag -
ranges -
Throws:
SequenceException - if any of the layers overlap, or if any of the ranges are outside of the range of this sequence

getSubSequence

public com.google.common.collect.ImmutableList<String> getSubSequence(String layerName,
                                                                      int start,
                                                                      int length)
Returns a subsequence of the given layer. If the given layer is a span layer with B/I/O tags, and the subsequence partially intersects a span (i.e. it starts with I-X), then this initial tag will be replaced with a B-X tag.

Overrides:
getSubSequence in class SimpleLayeredSequence
Returns:
an immutable subsequence of the layer

getSubSequence

public com.google.common.collect.ImmutableList<String> getSubSequence(String layerName,
                                                                      edu.washington.cs.knowitall.commonlib.Range r)
Returns a subsequence of the given layer. If the given layer is a span layer with B/I/O tags, and the subsequence partially intersects a span (i.e. it starts with I-X), then this initial tag will be replaced with a B-X tag.

Overrides:
getSubSequence in class SimpleLayeredSequence
Returns:
an immutable subsequence of the layer

getSubSequence

public BIOLayeredSequence getSubSequence(int start,
                                         int length)
Constructs a new subsequence from this instance. If the subsequence partially intersects a span (e.g. the subsequence starts at a I-X tag), then it will be replaced with a B-X tag.

Overrides:
getSubSequence in class SimpleLayeredSequence
Returns:

getSubSequence

public BIOLayeredSequence getSubSequence(edu.washington.cs.knowitall.commonlib.Range r)
Constructs a new subsequence from this instance. If the subsequence partially intersects a span (e.g. the subsequence starts at a I-X tag), then it will be replaced with a B-X tag.

Overrides:
getSubSequence in class SimpleLayeredSequence
Returns:

isSpanLayer

protected boolean isSpanLayer(String layerName)


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