edu.uchsc.ccp.knowtator
Class SpanUtil

java.lang.Object
  extended by edu.uchsc.ccp.knowtator.SpanUtil
All Implemented Interfaces:
TextSourceChangeListener

public class SpanUtil
extends Object
implements TextSourceChangeListener


Field Summary
static String GROW_ANNOTATION_LEFT
           
static String GROW_ANNOTATION_LEFT_WORD
           
static String GROW_ANNOTATION_RIGHT
           
static String GROW_ANNOTATION_RIGHT_WORD
           
static String SHRINK_ANNOTATION_LEFT
           
static String SHRINK_ANNOTATION_LEFT_WORD
           
static String SHRINK_ANNOTATION_RIGHT
           
static String SHRINK_ANNOTATION_RIGHT_WORD
           
 
Constructor Summary
SpanUtil(KnowtatorManager manager)
          Creates a new instance of SpanUtil
 
Method Summary
 boolean canGrowSpanLeft(Span span)
           
 boolean canGrowSpanRight(Span span)
           
 boolean canShrinkSpanLeft(Span span)
           
 boolean canShrinkSpanRight(Span span)
           
 Comparator<SimpleInstance> comparator(Comparator<SimpleInstance> noSpansComparator)
           
 void editSpans(List<Span> spans, SimpleInstance annotation, String editType)
           
static Span expandToSplits(String superString, Span substringSpan, int frontWindowSize, int rearWindowSize, Pattern splitPattern)
          The purpose of this method is to "expand" the substringSpan such that the start and end of the returned span are at splits in the string.
 Span getAReferencedSpan(SimpleInstance annotation)
           
 Span getFirstSpan(SimpleInstance annotation)
           
 Comparator lengthComparator()
           
static Span shrinkLeft(String superString, Span span, Pattern splitPattern)
           
static Span shrinkRight(String superString, Span span, Pattern splitPattern)
           
 int spansLength(List<Span> spans)
           
 void textSourceChanged(TextSourceChangeEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROW_ANNOTATION_LEFT

public static final String GROW_ANNOTATION_LEFT
See Also:
Constant Field Values

GROW_ANNOTATION_LEFT_WORD

public static final String GROW_ANNOTATION_LEFT_WORD
See Also:
Constant Field Values

GROW_ANNOTATION_RIGHT

public static final String GROW_ANNOTATION_RIGHT
See Also:
Constant Field Values

GROW_ANNOTATION_RIGHT_WORD

public static final String GROW_ANNOTATION_RIGHT_WORD
See Also:
Constant Field Values

SHRINK_ANNOTATION_LEFT

public static final String SHRINK_ANNOTATION_LEFT
See Also:
Constant Field Values

SHRINK_ANNOTATION_LEFT_WORD

public static final String SHRINK_ANNOTATION_LEFT_WORD
See Also:
Constant Field Values

SHRINK_ANNOTATION_RIGHT

public static final String SHRINK_ANNOTATION_RIGHT
See Also:
Constant Field Values

SHRINK_ANNOTATION_RIGHT_WORD

public static final String SHRINK_ANNOTATION_RIGHT_WORD
See Also:
Constant Field Values
Constructor Detail

SpanUtil

public SpanUtil(KnowtatorManager manager)
Creates a new instance of SpanUtil

Method Detail

textSourceChanged

public void textSourceChanged(TextSourceChangeEvent event)
Specified by:
textSourceChanged in interface TextSourceChangeListener

canGrowSpanRight

public boolean canGrowSpanRight(Span span)

canShrinkSpanRight

public boolean canShrinkSpanRight(Span span)

canGrowSpanLeft

public boolean canGrowSpanLeft(Span span)

canShrinkSpanLeft

public boolean canShrinkSpanLeft(Span span)

editSpans

public void editSpans(List<Span> spans,
                      SimpleInstance annotation,
                      String editType)
               throws InvalidSpanException,
                      TextSourceAccessException
Throws:
InvalidSpanException
TextSourceAccessException

expandToSplits

public static Span expandToSplits(String superString,
                                  Span substringSpan,
                                  int frontWindowSize,
                                  int rearWindowSize,
                                  Pattern splitPattern)
The purpose of this method is to "expand" the substringSpan such that the start and end of the returned span are at splits in the string.

Parameters:
superString - the string that is being looked at
substringSpan - a span that designates some arbitrary substring of the superString
frontWindowSize - the string that immediately precedes the substring is considered the frontwindow. This parameter sets the maximum size of the frontwindow (it may be smaller if the superstring doesn't have enough text that precedes the substring.)
rearWindowSize - the string that immediately follows the substring is considered the rearwindow. This parameter sets the maximum size of the rearwindow (it may be smaller if the superstring doesn't have enough text that follows the substring.)
splitPattern - a regular expression that defines a "split" or a word boundary. For example, you might pass in Pattern.compile(\\W+) to define a boundary as non-word characters.
Returns:
a span that is "expanded" to start and end at word boundaries. See the associated unit tests for examples. Typically the substring associated with the returned span will be larger than the substring associated with the substringSpan parameter. However, if the substring associated with the substringSpan begins or ends with the splitPattern, then the returned substring may be shorter.

shrinkRight

public static Span shrinkRight(String superString,
                               Span span,
                               Pattern splitPattern)

shrinkLeft

public static Span shrinkLeft(String superString,
                              Span span,
                              Pattern splitPattern)

comparator

public Comparator<SimpleInstance> comparator(Comparator<SimpleInstance> noSpansComparator)

lengthComparator

public Comparator lengthComparator()

spansLength

public int spansLength(List<Span> spans)

getAReferencedSpan

public Span getAReferencedSpan(SimpleInstance annotation)

getFirstSpan

public Span getFirstSpan(SimpleInstance annotation)
Parameters:
annotation -
Returns:
the span of the annotation that has the smallest start index. If no span exists for the annotation, then it will return the span with the smallest start index from all of the spans of all of the annotations (recursively) related annotations