edu.cmu.minorthird.text
Class BasicTextLabels

java.lang.Object
  extended by edu.cmu.minorthird.text.BasicTextLabels
All Implemented Interfaces:
MonotonicTextLabels, MutableTextLabels, TextLabels, Visible, Saveable, java.io.Serializable

public class BasicTextLabels
extends java.lang.Object
implements MutableTextLabels, java.io.Serializable, Visible, Saveable

Maintains assertions about 'types' and 'properties' of contiguous Spans of these TextToken's.

Author:
William Cohen
See Also:
Serialized Form

Field Summary
 Trie trie
           
 
Constructor Summary
BasicTextLabels()
          Creates an empty TextLabels not associated with a TextBase
BasicTextLabels(java.lang.String s)
          A convenience method which creates empty labels containing a single string.
BasicTextLabels(TextBase textBase)
          Creates an empty TextLabels associated with the specified TextBase
 
Method Summary
 void addToType(Span span, java.lang.String type)
          Assert that a span has a given type.
 void addToType(Span span, java.lang.String type, Details details)
          Assert that a span has a given type, and associate that assertion with some detailed information.
static void annotateWith(MonotonicTextLabels labels, java.lang.String annotationType, java.lang.String fileToLoad)
           
 void annotateWith(java.lang.String annotationType, java.lang.String fileToLoad)
          Annotate labels with annotator named fileToLoad
 void closeTypeInside(java.lang.String type, Span s)
          Make it the case that there are no spans of the given type contained by the given span, other than those already inserted to exist.
 java.util.Iterator<Span> closureIterator(java.lang.String type)
          Returns the spans s for in the given type is 'closed'.
 java.util.Iterator<Span> closureIterator(java.lang.String type, java.lang.String documentId)
          Returns the spans S inside the given document in which the given type is 'closed'.
 void declareType(java.lang.String type)
          Declare a new type, without asserting any spans as members.
 void defineDictionary(java.lang.String dictName, java.util.List<java.lang.String> fileNames, boolean ignoreCase)
          Associate a dictionary from this file
 void defineDictionary(java.lang.String dictName, java.util.Set<java.lang.String> dictionary)
          Associate a dictionary with this labeling.
 void defineTrie(java.util.List<java.lang.String> phraseList)
          Define a trie
 void defineTypeInside(java.lang.String type, Span s, java.util.Iterator<Span> i)
          Make it the case that there are no spans whatsoever of the given type contained by the given span, other than those described by the given span looper.
static void doRequire(MonotonicTextLabels labels, java.lang.String annotationType, java.lang.String fileToLoad, AnnotatorLoader theLoader)
           
 AnnotatorLoader getAnnotatorLoader()
          Returns the current loader used to locate annotators.
 Details getDetails(Span span, java.lang.String type)
          Retrieve additional information associated with an assertion 'span S has type T'.
 java.lang.String getExtensionFor(java.lang.String s)
          Recomended extension for the format with the given name.
 java.lang.String[] getFormatNames()
          List of formats in which the object can be saved.
 java.lang.String getProperty(Span span, java.lang.String prop)
          Get the property value associated with this Span.
 java.lang.String getProperty(Token token, java.lang.String prop)
          Get the property value associated with this Token.
 java.util.Set<java.lang.String> getSpanProperties()
          Get a set of all properties.
 java.util.Iterator<Span> getSpansWithProperty(java.lang.String prop)
          Find all spans that have a non-null value for this property.
 java.util.Iterator<Span> getSpansWithProperty(java.lang.String prop, java.lang.String id)
          Find all spans that have a non-null value for this property.
 TextBase getTextBase()
          Returns the TextBase associated with this labels set or NULL if it has not been set.
 java.util.Set<java.lang.String> getTokenProperties()
          Get a set of all properties.
 Trie getTrie()
          Return a trie if defined
 java.util.Set<java.lang.String> getTypes()
          Return a set of all type names.
 java.util.Set<Span> getTypeSet(java.lang.String type, java.lang.String documentId)
          Return the Set of all Spans with a given type in a given document
 boolean hasDictionary(java.lang.String dictionary)
          Returns whether this labels set knows about the specified dictionary
 boolean hasType(Span span, java.lang.String type)
          Query if a span has a given type.
 boolean inDict(Token token, java.lang.String dictName)
          Returns true if the value of the Token is in the named dictionary.
 java.util.Iterator<Span> instanceIterator(java.lang.String type)
          Get all instances of a given type.
 java.util.Iterator<Span> instanceIterator(java.lang.String type, java.lang.String documentId)
          Get all instances of a given type.
 boolean isAnnotatedBy(java.lang.String s)
          Returns whether or not this labels set has been annotated to include the specified type.
 boolean isType(java.lang.String type)
          True if the given string names a type.
protected  java.util.Set<Span> lookupTypeSet(java.lang.String type, java.lang.String documentId)
           
 void require(java.lang.String annotationType, java.lang.String fileToLoad)
          Ensure that this TextLabels contains a particular type of annotation.
 void require(java.lang.String annotationType, java.lang.String fileToLoad, AnnotatorLoader theLoader)
          Ensure that this TextLabels contains a particular type of annotation.
 java.lang.Object restore(java.io.File file)
          Restore the object from a file.
 void saveAs(java.io.File file, java.lang.String format)
          Save this object to the given file, in the given format.
 void setAnnotatedBy(java.lang.String s)
          Adds the specified type to the list of annotation types that this labels set has been annotated to contain.
 void setAnnotatorLoader(AnnotatorLoader newLoader)
          Sets the loader used to locate annotators.
 void setProperty(Span span, java.lang.String prop, java.lang.String value)
          Assert that Span span has the given value of the given property
 void setProperty(Span span, java.lang.String prop, java.lang.String value, Details details)
          Assert that Span span has the given value of the given property, and associate that with some detailed information
 void setProperty(Token textToken, java.lang.String prop, java.lang.String value)
          Assert that Token textToken has the given value of the given property
 void setProperty(Token textToken, java.lang.String prop, java.lang.String value, Details details)
          Assert that Token textToken has the given value of the given property, and associate that with some detailed information
 void setTextBase(TextBase textBase)
          Sets the TextBase associated with this labels set.
 java.lang.String showTokenProp(TextBase base, java.lang.String prop)
          Dump of all strings that have textTokenuence with the given property
 Viewer toGUI()
          Create a view of this object
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trie

public Trie trie
Constructor Detail

BasicTextLabels

public BasicTextLabels()
Creates an empty TextLabels not associated with a TextBase


BasicTextLabels

public BasicTextLabels(TextBase textBase)
Creates an empty TextLabels associated with the specified TextBase


BasicTextLabels

public BasicTextLabels(java.lang.String s)
A convenience method which creates empty labels containing a single string.

Method Detail

getTextBase

public TextBase getTextBase()
Returns the TextBase associated with this labels set or NULL if it has not been set.

Specified by:
getTextBase in interface TextLabels

hasDictionary

public boolean hasDictionary(java.lang.String dictionary)
Returns whether this labels set knows about the specified dictionary

Specified by:
hasDictionary in interface TextLabels
Parameters:
dictionary - String name of the dictionary
Returns:
true if the dictionary is defined for these labels

setTextBase

public void setTextBase(TextBase textBase)
Sets the TextBase associated with this labels set.

Specified by:
setTextBase in interface MutableTextLabels
Throws:
java.lang.IllegalStateException - If the TextBase has already been set.

isAnnotatedBy

public boolean isAnnotatedBy(java.lang.String s)
Returns whether or not this labels set has been annotated to include the specified type.

Specified by:
isAnnotatedBy in interface TextLabels

setAnnotatedBy

public void setAnnotatedBy(java.lang.String s)
Adds the specified type to the list of annotation types that this labels set has been annotated to contain.

Specified by:
setAnnotatedBy in interface MonotonicTextLabels

setAnnotatorLoader

public void setAnnotatorLoader(AnnotatorLoader newLoader)
Sets the loader used to locate annotators.

Specified by:
setAnnotatorLoader in interface MonotonicTextLabels

getAnnotatorLoader

public AnnotatorLoader getAnnotatorLoader()
Returns the current loader used to locate annotators.

Specified by:
getAnnotatorLoader in interface MonotonicTextLabels

require

public void require(java.lang.String annotationType,
                    java.lang.String fileToLoad)
Description copied from interface: TextLabels
Ensure that this TextLabels contains a particular type of annotation. If the annotation is not present, then either load it (if possible) or throw an error.

Specified by:
require in interface TextLabels

require

public void require(java.lang.String annotationType,
                    java.lang.String fileToLoad,
                    AnnotatorLoader theLoader)
Description copied from interface: TextLabels
Ensure that this TextLabels contains a particular type of annotation. If the annotation is not present, then either load it (if possible) or throw an error. Use the provided annotatorLoader to find annotators rather than the default one.

Specified by:
require in interface TextLabels

doRequire

public static void doRequire(MonotonicTextLabels labels,
                             java.lang.String annotationType,
                             java.lang.String fileToLoad,
                             AnnotatorLoader theLoader)

annotateWith

public void annotateWith(java.lang.String annotationType,
                         java.lang.String fileToLoad)
Description copied from interface: TextLabels
Annotate labels with annotator named fileToLoad

Specified by:
annotateWith in interface TextLabels

annotateWith

public static void annotateWith(MonotonicTextLabels labels,
                                java.lang.String annotationType,
                                java.lang.String fileToLoad)

inDict

public boolean inDict(Token token,
                      java.lang.String dictName)
Returns true if the value of the Token is in the named dictionary.

Specified by:
inDict in interface TextLabels

defineDictionary

public void defineDictionary(java.lang.String dictName,
                             java.util.Set<java.lang.String> dictionary)
Associate a dictionary with this labeling.

Specified by:
defineDictionary in interface MonotonicTextLabels

defineDictionary

public void defineDictionary(java.lang.String dictName,
                             java.util.List<java.lang.String> fileNames,
                             boolean ignoreCase)
Associate a dictionary from this file

Specified by:
defineDictionary in interface MonotonicTextLabels

getTrie

public Trie getTrie()
Return a trie if defined

Specified by:
getTrie in interface MonotonicTextLabels

defineTrie

public void defineTrie(java.util.List<java.lang.String> phraseList)
Define a trie

Specified by:
defineTrie in interface MonotonicTextLabels

getProperty

public java.lang.String getProperty(Token token,
                                    java.lang.String prop)
Get the property value associated with this Token.

Specified by:
getProperty in interface TextLabels

getTokenProperties

public java.util.Set<java.lang.String> getTokenProperties()
Get a set of all properties.

Specified by:
getTokenProperties in interface TextLabels

setProperty

public void setProperty(Token textToken,
                        java.lang.String prop,
                        java.lang.String value)
Assert that Token textToken has the given value of the given property

Specified by:
setProperty in interface MonotonicTextLabels

setProperty

public void setProperty(Token textToken,
                        java.lang.String prop,
                        java.lang.String value,
                        Details details)
Assert that Token textToken has the given value of the given property, and associate that with some detailed information

Specified by:
setProperty in interface MonotonicTextLabels

getProperty

public java.lang.String getProperty(Span span,
                                    java.lang.String prop)
Get the property value associated with this Span.

Specified by:
getProperty in interface TextLabels

getSpanProperties

public java.util.Set<java.lang.String> getSpanProperties()
Get a set of all properties.

Specified by:
getSpanProperties in interface TextLabels

getSpansWithProperty

public java.util.Iterator<Span> getSpansWithProperty(java.lang.String prop)
Find all spans that have a non-null value for this property.

Specified by:
getSpansWithProperty in interface TextLabels

getSpansWithProperty

public java.util.Iterator<Span> getSpansWithProperty(java.lang.String prop,
                                                     java.lang.String id)
Find all spans that have a non-null value for this property.

Specified by:
getSpansWithProperty in interface TextLabels

setProperty

public void setProperty(Span span,
                        java.lang.String prop,
                        java.lang.String value)
Assert that Span span has the given value of the given property

Specified by:
setProperty in interface MonotonicTextLabels

setProperty

public void setProperty(Span span,
                        java.lang.String prop,
                        java.lang.String value,
                        Details details)
Description copied from interface: MonotonicTextLabels
Assert that Span span has the given value of the given property, and associate that with some detailed information

Specified by:
setProperty in interface MonotonicTextLabels

hasType

public boolean hasType(Span span,
                       java.lang.String type)
Description copied from interface: TextLabels
Query if a span has a given type.

Specified by:
hasType in interface TextLabels

addToType

public void addToType(Span span,
                      java.lang.String type)
Description copied from interface: MonotonicTextLabels
Assert that a span has a given type.

Specified by:
addToType in interface MonotonicTextLabels

addToType

public void addToType(Span span,
                      java.lang.String type,
                      Details details)
Description copied from interface: MonotonicTextLabels
Assert that a span has a given type, and associate that assertion with some detailed information. If details==null, this should have the same effect as addToType(span,type).

Specified by:
addToType in interface MonotonicTextLabels

getTypes

public java.util.Set<java.lang.String> getTypes()
Description copied from interface: TextLabels
Return a set of all type names.

Specified by:
getTypes in interface TextLabels

isType

public boolean isType(java.lang.String type)
Description copied from interface: TextLabels
True if the given string names a type.

Specified by:
isType in interface TextLabels

declareType

public void declareType(java.lang.String type)
Description copied from interface: MonotonicTextLabels
Declare a new type, without asserting any spans as members.

Specified by:
declareType in interface MonotonicTextLabels

instanceIterator

public java.util.Iterator<Span> instanceIterator(java.lang.String type)
Description copied from interface: TextLabels
Get all instances of a given type.

Specified by:
instanceIterator in interface TextLabels

instanceIterator

public java.util.Iterator<Span> instanceIterator(java.lang.String type,
                                                 java.lang.String documentId)
Description copied from interface: TextLabels
Get all instances of a given type.

Specified by:
instanceIterator in interface TextLabels

defineTypeInside

public void defineTypeInside(java.lang.String type,
                             Span s,
                             java.util.Iterator<Span> i)
Description copied from interface: MutableTextLabels
Make it the case that there are no spans whatsoever of the given type contained by the given span, other than those described by the given span looper.

Specified by:
defineTypeInside in interface MutableTextLabels

getDetails

public Details getDetails(Span span,
                          java.lang.String type)
Description copied from interface: TextLabels
Retrieve additional information associated with an assertion 'span S has type T'. Returns null if the span doesn't have the stated type.

Specified by:
getDetails in interface TextLabels

lookupTypeSet

protected java.util.Set<Span> lookupTypeSet(java.lang.String type,
                                            java.lang.String documentId)

getTypeSet

public java.util.Set<Span> getTypeSet(java.lang.String type,
                                      java.lang.String documentId)
Description copied from interface: TextLabels
Return the Set of all Spans with a given type in a given document

Specified by:
getTypeSet in interface TextLabels

closureIterator

public java.util.Iterator<Span> closureIterator(java.lang.String type)
Description copied from interface: TextLabels
Returns the spans s for in the given type is 'closed'. If type T is close inside S, this means that one can apply the 'closed world assumption' and assume that the known set of spans of type T is complete, except for areas of the text that are not contained by any closure span S.

Specified by:
closureIterator in interface TextLabels

closureIterator

public java.util.Iterator<Span> closureIterator(java.lang.String type,
                                                java.lang.String documentId)
Description copied from interface: TextLabels
Returns the spans S inside the given document in which the given type is 'closed'.

Specified by:
closureIterator in interface TextLabels

closeTypeInside

public void closeTypeInside(java.lang.String type,
                            Span s)
Description copied from interface: MutableTextLabels
Make it the case that there are no spans of the given type contained by the given span, other than those already inserted to exist.

Specified by:
closeTypeInside in interface MutableTextLabels

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

showTokenProp

public java.lang.String showTokenProp(TextBase base,
                                      java.lang.String prop)
Dump of all strings that have textTokenuence with the given property

Specified by:
showTokenProp in interface TextLabels

toGUI

public Viewer toGUI()
Description copied from interface: Visible
Create a view of this object

Specified by:
toGUI in interface Visible

getFormatNames

public java.lang.String[] getFormatNames()
Description copied from interface: Saveable
List of formats in which the object can be saved.

Specified by:
getFormatNames in interface Saveable

getExtensionFor

public java.lang.String getExtensionFor(java.lang.String s)
Description copied from interface: Saveable
Recomended extension for the format with the given name.

Specified by:
getExtensionFor in interface Saveable

saveAs

public void saveAs(java.io.File file,
                   java.lang.String format)
            throws java.io.IOException
Description copied from interface: Saveable
Save this object to the given file, in the given format.

Specified by:
saveAs in interface Saveable
Throws:
java.io.IOException

restore

public java.lang.Object restore(java.io.File file)
                         throws java.io.IOException
Description copied from interface: Saveable
Restore the object from a file.

Specified by:
restore in interface Saveable
Throws:
java.io.IOException