public class BasicAnnotatorService extends Object implements AnnotatorService
Many Annotators are likely to be singletons to avoid memory overload. AnnotatorService can be subclassed to provide homespun views without creating Annotator classes, though probably the latter is the better way to go. There is at least one use case that motivates this design -- backward compatibility with Curator to replace CuratorClient/CachingCuratorClient.
| Modifier and Type | Field and Description |
|---|---|
protected TextAnnotationCache |
annotationCache |
protected boolean |
disableCache |
protected boolean |
forceUpdate |
protected TextAnnotationBuilder |
textAnnotationBuilder
provides tokenization and sentence splitting to create a basic TextAnnotation object from
plain text String.
|
protected boolean |
throwExceptionIfNotCached
used when processing a corpus and then using it in experiments -- if 'true', you will know in
the experimental run that a data element is missing.
|
protected Map<String,Annotator> |
viewProviders
A way to define externally provided views.
|
| Constructor and Description |
|---|
BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder,
Map<String,Annotator> viewProviders)
constructor that uses AnnotatorServiceConfigurator default configuration
|
BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder,
Map<String,Annotator> viewProviders,
ResourceManager rm)
constructor with ResourceManager properties for caching behavior
|
BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder,
Map<String,Annotator> viewProviders,
String cacheFile,
boolean throwExceptionIfNotCached,
boolean disableCache,
boolean forceUpdate)
Populates the AnnotatorService with
View providers and initializes cache manager, if caching enabled. |
| Modifier and Type | Method and Description |
|---|---|
void |
addAnnotator(Annotator annotator)
Add a new
Annotator to the service. |
boolean |
addView(TextAnnotation textAnnotation,
String viewName)
DOES NOT CACHE THE ADDED VIEW!!!
|
TextAnnotation |
addViewsAndCache(TextAnnotation ta,
Set<String> viewsToAnnotate,
boolean clientForceUpdate)
add all the specified views to the specified
TextAnnotation and cache it. |
TextAnnotation |
annotateTextAnnotation(TextAnnotation ta,
boolean replaceExistingViews)
Add the specified views to the TextAnnotation argument.
|
TextAnnotation |
createAnnotatedTextAnnotation(String corpusId,
String textId,
String text)
Creates a
TextAnnotation with all annotators provided to this AnnotatorService. |
TextAnnotation |
createAnnotatedTextAnnotation(String corpusId,
String textId,
String text,
Set<String> viewsToAnnotate)
An overloaded version of
AnnotatorService.createAnnotatedTextAnnotation(String, String, String) that
adds only the Views
requested. |
TextAnnotation |
createAnnotatedTextAnnotation(String corpusId,
String textId,
String text,
Tokenizer.Tokenization tokenization)
A convenience method for creating a
TextAnnotation and adding
all the Views supported by
this AnnotatorService. |
TextAnnotation |
createAnnotatedTextAnnotation(String corpusId,
String textId,
String text,
Tokenizer.Tokenization tokenization,
Set<String> viewNames)
An overloaded version of
createAnnotatedTextAnnotation(String, String, String) that
adds only the Views
requested. |
TextAnnotation |
createBasicTextAnnotation(String corpusId,
String docId,
String text)
Creates a basic
TextAnnotation with sentence and token views with the pre-tokenized
text by using the TextAnnotationBuilder. |
TextAnnotation |
createBasicTextAnnotation(String corpusId,
String docId,
String text,
Tokenizer.Tokenization tokenization)
A convenience method for creating a
TextAnnotation while
respecting the pre-tokenization of text passed in the form of
Tokenizer.Tokenization. |
Set<String> |
getAvailableViews()
Return a set containing the names of all
Views
that this service can provide. |
protected void |
throwNotCachedException(String corpusId,
String docId,
String text) |
protected TextAnnotationCache annotationCache
protected boolean disableCache
protected boolean throwExceptionIfNotCached
protected TextAnnotationBuilder textAnnotationBuilder
protected Map<String,Annotator> viewProviders
Annotator.protected boolean forceUpdate
public BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder, Map<String,Annotator> viewProviders, ResourceManager rm) throws AnnotatorException
textAnnotationBuilder - tokenizes and sentence splits input text.viewProviders - Annotators that populate a View with the same name as the corresponding
Annotator key.rm - A ResourceManager containing cache configuration options.AnnotatorExceptionpublic BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder, Map<String,Annotator> viewProviders) throws AnnotatorException
textAnnotationBuilder - object that will build basic TextAnnotation objectsviewProviders - annotators that will populate views in new TextAnnotation objectsAnnotatorExceptionpublic BasicAnnotatorService(TextAnnotationBuilder textAnnotationBuilder, Map<String,Annotator> viewProviders, String cacheFile, boolean throwExceptionIfNotCached, boolean disableCache, boolean forceUpdate) throws AnnotatorException
View providers and initializes cache manager, if caching enabled.textAnnotationBuilder - tokenizes and sentence splits input text.viewProviders - Annotators that populate a View with the same name as the corresponding
Annotator key.cacheFile - Where the AnnotatorService should write the cache. IMPORTANT: multiple
VMs may NOT share a single cache location.throwExceptionIfNotCached - if 'true', throw an exception if no cached value is found.AnnotatorExceptionpublic TextAnnotation createBasicTextAnnotation(String corpusId, String docId, String text) throws AnnotatorException
TextAnnotation with sentence and token views with the pre-tokenized
text by using the TextAnnotationBuilder. Note that
this method works only with
BasicTextAnnotationBuilder.
DOES NOT CACHE THIS BASIC TEXT ANNOTATION.createBasicTextAnnotation in interface AnnotatorServicecorpusId - The name of the data set to associate with this textdocId - document id to associate with this texttext - The raw textAnnotatorExceptionpublic TextAnnotation createBasicTextAnnotation(String corpusId, String docId, String text, Tokenizer.Tokenization tokenization) throws AnnotatorException
TextAnnotation while
respecting the pre-tokenization of text passed in the form of
Tokenizer.Tokenization.createBasicTextAnnotation in interface AnnotatorServicecorpusId - docId - text - The raw texttokenization - An instance of
Tokenizer.Tokenization which contains
tokens, character offsets, and sentence boundaries to be used while constructing the
TextAnnotation. @throws AnnotatorException If the service cannot create requested objectAnnotatorException - If the service cannot create requested objectpublic TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text) throws AnnotatorException
TextAnnotation with all annotators provided to this AnnotatorService.createAnnotatedTextAnnotation in interface AnnotatorServicecorpusId - corpus name to associate with this text/TextAnnotation.textId - document id to associate with this text/TextAnnotation.text - The raw text used to build the
TextAnnotation
where all the Views
should be added.AnnotatorExceptionpublic TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization) throws AnnotatorException
TextAnnotation and adding
all the Views supported by
this AnnotatorService. This amounts to calling
createBasicTextAnnotation(String, String, String, Tokenizer.Tokenization) and
successive calls of
addView(edu.illinois.cs.cogcomp.core.datastructures.textannotation.TextAnnotation, String)
. Note that this method works only with
BasicTextAnnotationBuilder.createAnnotatedTextAnnotation in interface AnnotatorServicetext - The raw texttokenization - An instance of
Tokenizer.Tokenization which contains
tokens, character offsets, and sentence boundaries to be used while constructing the
TextAnnotation.AnnotatorExceptionpublic TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization, Set<String> viewNames) throws AnnotatorException
createAnnotatedTextAnnotation(String, String, String) that
adds only the Views
requested. Note that this method works only with
BasicTextAnnotationBuilder.createAnnotatedTextAnnotation in interface AnnotatorServicetext - The raw texttokenization - An instance of
Tokenizer.Tokenization which contains
tokens, character offsets, and sentence boundaries to be used while constructing the
TextAnnotation.viewNames - Views to addAnnotatorExceptionpublic void addAnnotator(Annotator annotator) throws AnnotatorException
Annotator to the service. All prerequisite views must already be provided by other annotators
known to this AnnotatorService.addAnnotator in interface AnnotatorServiceannotator - the Annotator to be added.{@link - AnnotatorException} if the annotator requires views that cannot be satisfied.AnnotatorExceptionpublic Set<String> getAvailableViews()
Views
that this service can provide.getAvailableViews in interface AnnotatorServicepublic TextAnnotation annotateTextAnnotation(TextAnnotation ta, boolean replaceExistingViews) throws AnnotatorException
annotateTextAnnotation in interface AnnotatorServiceta - The TextAnnotation to annotatereplaceExistingViews - if 'true', annotate a
View even if
it is already present in the ta argument, replacing the original corresponding View.AnnotatorExceptionpublic boolean addView(TextAnnotation textAnnotation, String viewName) throws AnnotatorException
addView in interface AnnotatorServicetextAnnotation - textAnnotation to be modifiedviewName - name of view to be addedAnnotatorExceptionprotected void throwNotCachedException(String corpusId, String docId, String text) throws AnnotatorException
AnnotatorExceptionpublic TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewsToAnnotate) throws AnnotatorException
AnnotatorServiceAnnotatorService.createAnnotatedTextAnnotation(String, String, String) that
adds only the Views
requested.createAnnotatedTextAnnotation in interface AnnotatorServicetext - The raw text used to build the
TextAnnotation
where all the Views
should be added.viewsToAnnotate - Views to addAnnotatorException - If none of the viewProviders supports this
viewNamepublic TextAnnotation addViewsAndCache(TextAnnotation ta, Set<String> viewsToAnnotate, boolean clientForceUpdate) throws AnnotatorException
TextAnnotation and cache it. Will overwrite if so configured.
IMPORTANT: if the corresponding TextAnnotation has already been cached, the argument
is ignored. The client should ALWAYS use the returned TextAnnotation.ta - viewsToAnnotate - AnnotatorExceptionCopyright © 2017. All rights reserved.