public class StanfordNLPService extends Object
StanfordCoreNLP
pipeline used to process user messages.
This class is configured with the addAnnotator(String)
method that allows to add NLP annotators used by
pre/post processors. Once fully configured the actual NLP service can be initialized with init()
.
This class should be used by all the pre/post processors relying on StanfordCoreNLP
in order to optimize
the memory consumption and the execution time.
Modifier and Type | Method and Description |
---|---|
void |
addAnnotator(String annotator)
Adds the provided
annotator to the service. |
void |
addAnnotators(List<String> annotators)
Adds the provided list of
annotators to the service. |
edu.stanford.nlp.pipeline.Annotation |
annotate(String input)
Annotates the provided
input with the specified annotators . |
static StanfordNLPService |
getInstance()
Returns the singleton instance of this class.
|
void |
init()
Initialize the underlying
StanfordCoreNLP pipeline with the provided annotators. |
public static StanfordNLPService getInstance()
public void init()
StanfordCoreNLP
pipeline with the provided annotators.
This method should be called once all the annotators have been specified. Adding annotators after
calling this method will throw an IllegalArgumentException
.
Note: this method does not re-initialize the underlying StanfordCoreNLP
if it has been
previously initialized.
public void addAnnotator(String annotator)
annotator
to the service.
The provided annotator
is added iff it has not been specified before.
The annotator is provided using its String representation, see the Stanford NLP documentation for more information.
annotator
- the annotator to add to the serviceIllegalArgumentException
- if the underlying NLP service is already startedpublic void addAnnotators(List<String> annotators)
annotators
to the service.
Each provided annotator
is added iff it has not been specified before.
These annotators are provided using their String representation, see the Stanford NLP documentation for more information.
annotators
- the list of annotators to add to the serviceIllegalArgumentException
- if the underlying NLP service is already startedpublic edu.stanford.nlp.pipeline.Annotation annotate(String input)
input
with the specified annotators
.
The annotators
used to annotate the provided input
are specified using
addAnnotator(String)
.
input
- the textual input to annotateAnnotation
Copyright © 2020 SOM Research Lab. All rights reserved.