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 View s
requested. |
TextAnnotation |
createAnnotatedTextAnnotation(String corpusId,
String textId,
String text,
Tokenizer.Tokenization tokenization)
A convenience method for creating a
TextAnnotation and adding
all the View s 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 View s
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
View s
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.AnnotatorException
public 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 objectsAnnotatorException
public 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.AnnotatorException
public 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 AnnotatorService
corpusId
- The name of the data set to associate with this textdocId
- document id to associate with this texttext
- The raw textAnnotatorException
public 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 AnnotatorService
corpusId
- 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 AnnotatorService
corpusId
- 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 View
s
should be added.AnnotatorException
public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization) throws AnnotatorException
TextAnnotation
and adding
all the View
s 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 AnnotatorService
text
- The raw texttokenization
- An instance of
Tokenizer.Tokenization
which contains
tokens, character offsets, and sentence boundaries to be used while constructing the
TextAnnotation
.AnnotatorException
public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Tokenizer.Tokenization tokenization, Set<String> viewNames) throws AnnotatorException
createAnnotatedTextAnnotation(String, String, String)
that
adds only the View
s
requested. Note that this method works only with
BasicTextAnnotationBuilder
.createAnnotatedTextAnnotation
in interface AnnotatorService
text
- 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 addAnnotatorException
public 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 AnnotatorService
annotator
- the Annotator
to be added.{@link
- AnnotatorException} if the annotator requires views that cannot be satisfied.AnnotatorException
public Set<String> getAvailableViews()
View
s
that this service can provide.getAvailableViews
in interface AnnotatorService
public TextAnnotation annotateTextAnnotation(TextAnnotation ta, boolean replaceExistingViews) throws AnnotatorException
annotateTextAnnotation
in interface AnnotatorService
ta
- The TextAnnotation
to annotatereplaceExistingViews
- if 'true', annotate a
View
even if
it is already present in the ta argument, replacing the original corresponding View.AnnotatorException
public boolean addView(TextAnnotation textAnnotation, String viewName) throws AnnotatorException
addView
in interface AnnotatorService
textAnnotation
- textAnnotation to be modifiedviewName
- name of view to be addedAnnotatorException
protected void throwNotCachedException(String corpusId, String docId, String text) throws AnnotatorException
AnnotatorException
public TextAnnotation createAnnotatedTextAnnotation(String corpusId, String textId, String text, Set<String> viewsToAnnotate) throws AnnotatorException
AnnotatorService
AnnotatorService.createAnnotatedTextAnnotation(String, String, String)
that
adds only the View
s
requested.createAnnotatedTextAnnotation
in interface AnnotatorService
text
- The raw text used to build the
TextAnnotation
where all the View
s
should be added.viewsToAnnotate
- Views to addAnnotatorException
- If none of the viewProviders
supports this
viewName
public 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
- AnnotatorException
Copyright © 2017. All rights reserved.