com.languagecomputer.api.text
Class DefaultDocument

java.lang.Object
  extended by com.languagecomputer.api.text.DefaultText
      extended by com.languagecomputer.api.text.DefaultDocument
All Implemented Interfaces:
Document, Text

public class DefaultDocument
extends DefaultText
implements Document

Default implementation of a Document.

Since:
1.0
Author:
Kirk Roberts
See Also:
DefaultText

Field Summary
 
Fields inherited from interface com.languagecomputer.api.text.Document
TYPE
 
Constructor Summary
DefaultDocument()
          Creates a new DefaultDocument.
 
Method Summary
 void addAnnotation(Text annotation)
          Adds a Text to the Document.
 void addMetaData(String key, String value)
          Adds meta information about the Document using a key-value pair.
 void addService(String serviceName)
          Adds the serviceName to the list of Services that have been processed this Document.
 Collection<Text> getAllAnnotations()
          Returns all the annotations on this Document.
 Map<String,Collection<String>> getAllMetaData()
          Returns all the meta-data values attached to this Document.
<T extends Text>
Collection<T>
getAnnotations(AnnotationType<T> annType)
          Returns all the annotations on this Document that correspond to the given AnnotationType.
 Document getDocument()
          Returns this DefaultDocument.
 String getDocumentID()
          Returns the Document ID that identifies this Text.
 int getEndCharOffset()
          Returns the (exclusive) end character offset for this Text object within the (processed) Document. This offset does not necessarily line up with the start character offset from the unprocessed document/file.
 Collection<String> getMetaData(String key)
          Returns the meta-data values for the given meta-data key.
 List<String> getServices()
          Returns the names of the Services that have processed this Document.
 int getStartCharOffset()
          Returns the start character offset for this Text object within the (processed) Document. This offset does not necessarily line up with the start character offset from the unprocessed document/file.
 void setAnnotationType(AnnotationType annType)
          Not necessary: defaults to Document.TYPE.
 void setDocument(Document document)
          Not allowed: getDocument() can only return this DefaultDocument.
 void setDocumentID(String docID)
          Sets the Document ID.
 void setEndCharOffset(int endCharOffset)
          Not allowed: computed from DefaultText.getRawString().
 void setStartCharOffset(int startCharOffset)
          Not allowed: must be 0 (hard-coded).
 String toString()
          Returns a String representation of a DefaultDocument.
 
Methods inherited from class com.languagecomputer.api.text.DefaultText
getAnnotationType, getCongruentAnnotations, getIntersectingAnnotations, getRawString, getSubAnnotations, getSuperAnnotations, setRawString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.languagecomputer.api.text.Text
getAnnotationType, getCongruentAnnotations, getIntersectingAnnotations, getRawString, getSubAnnotations, getSuperAnnotations
 

Constructor Detail

DefaultDocument

public DefaultDocument()
Creates a new DefaultDocument.

Method Detail

setDocumentID

public void setDocumentID(String docID)
Sets the Document ID.

Parameters:
docID - The document ID to use, cannot be null.
Throws:
IllegalArgumentException - If docID is null.
See Also:
Document.getDocumentID()

getDocumentID

public String getDocumentID()
Returns the Document ID that identifies this Text.

Specified by:
getDocumentID in interface Document
Specified by:
getDocumentID in interface Text
Overrides:
getDocumentID in class DefaultText
Returns:
The ID for the Document that contains this Text.

setDocument

public void setDocument(Document document)
Not allowed: getDocument() can only return this DefaultDocument.

Overrides:
setDocument in class DefaultText
Parameters:
document - (ignored)
Throws:
UnsupportedOperationException - Cannot be called.
See Also:
Text.getDocument()

getDocument

public Document getDocument()
Returns this DefaultDocument. Required for Document to extend Text.

Specified by:
getDocument in interface Text
Overrides:
getDocument in class DefaultText
Returns:
Returns this DefaultDocument.

addAnnotation

public void addAnnotation(Text annotation)
Adds a Text to the Document. If the annotation is a DefaultText, then DefaultText.setDocument(com.languagecomputer.api.text.Document) is called with this DefaultDocument.

Specified by:
addAnnotation in interface Document
Parameters:
annotation - The Text annotation to add.
See Also:
Document.getAllAnnotations()

getAllAnnotations

public Collection<Text> getAllAnnotations()
Returns all the annotations on this Document.

Specified by:
getAllAnnotations in interface Document
Returns:
A Collection of all Text objects that are attached to this Document. The annotations will be in a semi-sorted order. This means that non-intersecting objects will be sorted by their order in the document. No guarantee will be placed on the order of intersecting objects.

getAnnotations

public <T extends Text> Collection<T> getAnnotations(AnnotationType<T> annType)
Returns all the annotations on this Document that correspond to the given AnnotationType.

Specified by:
getAnnotations in interface Document
Type Parameters:
T - The Text sub-class corresponding to the given AnnotationType.
Parameters:
annType - The AnnotationType that all returned items will match.
Returns:
A Collection of objects matching the given AnnotationType. The annotations will be in a semi-sorted order. This means that non-intersecting objects will be sorted by their order in the document. No guarantee will be placed on the order of intersecting objects.

addService

public void addService(String serviceName)
Adds the serviceName to the list of Services that have been processed this Document. Services should not need to be run more than once, so this allows the Document to know which services it has been processed by. See Service#getName for the convention on naming services.

Specified by:
addService in interface Document
Parameters:
serviceName - String name for a Service.
See Also:
Service#getName, Document.getServices()

getServices

public List<String> getServices()
Returns the names of the Services that have processed this Document. Services should not need to be run more than once, so they can check this list to prevent redundant work. See Service#getName for the convention on naming services.

Specified by:
getServices in interface Document
Returns:
List of Service names that have processed this Document.
See Also:
Service#getName, Document.addService(String)

addMetaData

public void addMetaData(String key,
                        String value)
Adds meta information about the Document using a key-value pair. A Document may have multiple values for the same key.

Specified by:
addMetaData in interface Document
Parameters:
key - The identifier for the meta-data.
value - The value for the corresponding meta-data key.
See Also:
Document.getMetaData(String), Document.getAllMetaData()

getMetaData

public Collection<String> getMetaData(String key)
Returns the meta-data values for the given meta-data key. Multiple values may be associated with a given key, but the values are guaranteed to be neither ordered or unique.

Specified by:
getMetaData in interface Document
Parameters:
key - The identifier for the meta-data.
Returns:
A Collection of meta-data values that correspond to the given key. Returns null if the given key has no values.
See Also:
Document.addMetaData(String,String), Document.getAllMetaData()

getAllMetaData

public Map<String,Collection<String>> getAllMetaData()
Returns all the meta-data values attached to this Document. Note that meta-data may be used to provide information to the end user or to share information about the document between Services. Consumers of meta-data should therefore be mindful of how meta-data is used in a particular use case.

Specified by:
getAllMetaData in interface Document
Returns:
A Map of every meta-data key to its corresponding Collection of meta-data values.
See Also:
Document.addMetaData(String,String), Document.getMetaData(String)

setAnnotationType

public void setAnnotationType(AnnotationType annType)
Not necessary: defaults to Document.TYPE.

Overrides:
setAnnotationType in class DefaultText
Parameters:
annType - AnnotationType to use for this DefaultDocument.
See Also:
Text.getAnnotationType(), AnnotationType

setStartCharOffset

public final void setStartCharOffset(int startCharOffset)
Not allowed: must be 0 (hard-coded).

Overrides:
setStartCharOffset in class DefaultText
Parameters:
startCharOffset - (ignored)
Throws:
UnsupportedOperationException - Handled automatically.
See Also:
Text.getStartCharOffset()

getStartCharOffset

public int getStartCharOffset()
Returns the start character offset for this Text object within the (processed) Document. This offset does not necessarily line up with the start character offset from the unprocessed document/file.

Specified by:
getStartCharOffset in interface Text
Overrides:
getStartCharOffset in class DefaultText
Returns:
The inclusive start offset.

setEndCharOffset

public final void setEndCharOffset(int endCharOffset)
Not allowed: computed from DefaultText.getRawString().

Overrides:
setEndCharOffset in class DefaultText
Parameters:
endCharOffset - (ignored)
Throws:
UnsupportedOperationException - Handled automatically.
See Also:
Text.getEndCharOffset()

getEndCharOffset

public int getEndCharOffset()
Returns the (exclusive) end character offset for this Text object within the (processed) Document. This offset does not necessarily line up with the start character offset from the unprocessed document/file.

Specified by:
getEndCharOffset in interface Text
Overrides:
getEndCharOffset in class DefaultText
Returns:
The exclusive end offset.

toString

public String toString()
Returns a String representation of a DefaultDocument.

Overrides:
toString in class DefaultText


Copyright © 2009. All Rights Reserved.