Package opennlp.tools.depparse
Class DependencyParserME
java.lang.Object
opennlp.tools.depparse.DependencyParserME
- All Implemented Interfaces:
DependencyParser
A greedy transition-based
DependencyParser: a classifier picks the next
arc-standard Transition for each configuration until the parse is
complete, always taking the highest scoring transition that is applicable.
The parser holds an immutable model and no per-parse state, so one instance can be shared between threads.
- Since:
- 3.0.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DependencyContextGeneratorprivate final MaxentModelprivate final Transition[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate TransitionbestApplicable(ArcStandardState state, String[] tokens, String[] tags) Scores all outcomes for the current configuration and picks the best transition that is applicable; inapplicable outcomes are passed over regardless of score.private voidcheckTokensAndTags(String[] tokens, String[] tags) Validates the input ofparse(String[], String[]), with the same rules and messages asDependencySample.private Transition[]decodeOutcomes(MaxentModel model) Decodes the outcome inventory once, so that decoding a sentence indexes it instead of parsing an outcome string per configuration and outcome.Parses a sentence into aDependencyTree.static DependencyModeltrain(String languageCode, ObjectStream<DependencySample> samples, TrainingParameters parameters) Trains a greedy arc-standard parser model from dependency samples.
-
Field Details
-
model
-
contextGenerator
-
transitions
-
-
Constructor Details
-
DependencyParserME
Initializes aDependencyParserMEfrom aDependencyModel.- Parameters:
model- The model to parse with. Must not benull.- Throws:
IllegalArgumentException- Thrown ifmodelisnullor an outcome inventory is invalid or cannot parse a sentence.
-
-
Method Details
-
decodeOutcomes
Decodes the outcome inventory once, so that decoding a sentence indexes it instead of parsing an outcome string per configuration and outcome.- Parameters:
model- The transition classification model.- Returns:
- The transitions by outcome index. Never
null. - Throws:
IllegalArgumentException- Thrown if an outcome does not decode to a transition, which means the model is not a dependency parser model, a transition repeats, or the model has no SHIFT or no RIGHT_ARC action.
-
parse
Parses a sentence into aDependencyTree.- Specified by:
parsein interfaceDependencyParser- Parameters:
tokens- The input tokens. Must not benull, must contain at least one token, and must not containnullentries.tags- The part-of-speech tags aligned withtokens. Must not benull, must have the same length astokens, and must not containnullentries.- Returns:
- A
DependencyTreeover the given tokens. Nevernull. - Throws:
IllegalStateException- Thrown if the model returns scores that do not match its outcomes or are not finite.
-
checkTokensAndTags
Validates the input ofparse(String[], String[]), with the same rules and messages asDependencySample.- Parameters:
tokens- The token array. Must not benullor empty and must not containnullentries.tags- The part-of-speech tags aligned withtokens. Must not benull, must have the same length astokens, and must not containnullentries.- Throws:
IllegalArgumentException- Thrown if an array isnull,tokensis empty, the lengths do not match, or an entry isnull.
-
bestApplicable
Scores all outcomes for the current configuration and picks the best transition that is applicable; inapplicable outcomes are passed over regardless of score.- Parameters:
state- The current configuration.tokens- The sentence tokens.tags- The part-of-speech tags aligned withtokens.- Returns:
- The highest scoring applicable transition. Never
null. - Throws:
IllegalStateException- Thrown if the model returns a score count that does not match its outcomes, a non-finite score, or no applicable transition.
-
train
public static DependencyModel train(String languageCode, ObjectStream<DependencySample> samples, TrainingParameters parameters) throws IOException Trains a greedy arc-standard parser model from dependency samples.Non-projective samples have no arc-standard derivation and are skipped during event generation.
- Parameters:
languageCode- The ISO language code of the training data. Must not benull.samples- The training samples. Must not benull.parameters- TheTrainingParameters. Must not benulland must select an event model trainer.- Returns:
- A trained
DependencyModel. Nevernull. - Throws:
IOException- Thrown if reading the samples fails.IllegalArgumentException- Thrown if a parameter isnullor the configured trainer is not an event model trainer.
-