You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jz...@apache.org on 2022/11/23 16:10:06 UTC
[opennlp] branch master updated: OPENNLP-1394 Reduce compiler warnings during build (#432)
This is an automated email from the ASF dual-hosted git repository.
jzemerick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/master by this push:
new 986aa66c OPENNLP-1394 Reduce compiler warnings during build (#432)
986aa66c is described below
commit 986aa66c17b6eaa275041cc903d6f3146ff6d52d
Author: Martin Wiesner <ma...@users.noreply.github.com>
AuthorDate: Wed Nov 23 17:09:58 2022 +0100
OPENNLP-1394 Reduce compiler warnings during build (#432)
* OPENNLP-1394 Reduce compiler warnings during build
- eliminates several compiler warnings by more consequent use of generic types
- reduces use of deprecated api calls to external deps
- introduces Sample interface as a marker for similar impl classes
- introduces Trainer interface as a marker for similar impl classes
- adapts previously deprecated methods in AbstractTrainer
- removes deprecated constructor 'TrainingParameters(Map<String,String> map)' in favor of 'public TrainingParameters(Map<String,Object> map)'
- removes deprecated methods in TrainingParameters
* OPENNLP-1394 Reduce compiler warnings during build
- eliminates more compiler warnings related to raw use of parameterized types
- reduces use of deprecated api calls to external deps
- removes orphaned methods / constructors that where not used or not required anymore
- fixes typos and improves JavaDoc
* OPENNLP-1361 - Upgrade JUnit 4 to version 5 (#431)
* Revert "OPENNLP-1361 - Upgrade JUnit 4 to version 5 (#431)"
This reverts commit ced4854ee55a268dce162e93c135969c6af78d75.
* OPENNLP-1394 Reduce compiler warnings during build
- adapts to changes brought by OPENNLP-1361 (-> JUnit5), fixes compile error
---
opennlp-dl/pom.xml | 2 +-
.../cmdline/builder/XMLDictionaryToTableTool.java | 3 +-
.../java/opennlp/tools/chunker/ChunkSample.java | 5 +-
.../tools/chunker/ChunkSampleSequenceStream.java | 6 +-
.../main/java/opennlp/tools/chunker/ChunkerME.java | 8 +--
.../java/opennlp/tools/chunker/ChunkerModel.java | 1 +
.../tools/cmdline/AbstractConverterTool.java | 8 +--
.../tools/cmdline/AbstractEvaluatorTool.java | 2 +-
.../tools/cmdline/AbstractTypedParamTool.java | 4 +-
.../java/opennlp/tools/cmdline/ArgumentParser.java | 10 ++-
.../src/main/java/opennlp/tools/cmdline/CLI.java | 4 +-
.../opennlp/tools/cmdline/GenerateManualTool.java | 6 +-
.../opennlp/tools/cmdline/ObjectStreamFactory.java | 4 +-
.../tools/cmdline/StreamFactoryRegistry.java | 45 ++++++------
.../opennlp/tools/cmdline/TypedCmdLineTool.java | 13 ++--
.../cmdline/chunker/ChunkerConverterTool.java | 3 +-
.../tools/cmdline/doccat/DoccatConverterTool.java | 3 +-
.../langdetect/LanguageDetectorConverterTool.java | 3 +-
.../namefind/TokenNameFinderConverterTool.java | 3 +-
.../namefind/TokenNameFinderTrainerTool.java | 4 +-
.../tools/cmdline/parser/ModelUpdaterTool.java | 2 +-
.../tools/cmdline/parser/ParserConverterTool.java | 3 +-
.../tools/cmdline/parser/ParserTrainerTool.java | 6 +-
.../cmdline/postag/POSTaggerConverterTool.java | 3 +-
.../sentdetect/SentenceDetectorConverterTool.java | 3 +-
.../cmdline/tokenizer/TokenizerConverterTool.java | 3 +-
.../Sample.java} | 14 ++--
.../Trainer.java} | 14 ++--
.../package-info.java} | 15 ++--
.../java/opennlp/tools/doccat/DocumentSample.java | 6 +-
.../opennlp/tools/entitylinker/LinkedSpan.java | 5 +-
.../tools/formats/AbstractSampleStreamFactory.java | 10 +--
.../formats/BioNLP2004NameSampleStreamFactory.java | 6 +-
.../tools/formats/ChunkerSampleStreamFactory.java | 6 +-
.../formats/Conll02NameSampleStreamFactory.java | 6 +-
.../formats/Conll03NameSampleStreamFactory.java | 6 +-
.../formats/ConllXPOSSampleStreamFactory.java | 8 +--
.../formats/ConllXSentenceSampleStreamFactory.java | 9 +--
.../formats/ConllXTokenSampleStreamFactory.java | 6 +-
.../formats/DetokenizerSampleStreamFactory.java | 4 +-
.../tools/formats/DocumentSampleStreamFactory.java | 6 +-
.../formats/EvalitaNameSampleStreamFactory.java | 6 +-
.../LanguageDetectorSampleStreamFactory.java | 8 +--
.../tools/formats/LanguageSampleStreamFactory.java | 4 +-
.../formats/LemmatizerSampleStreamFactory.java | 6 +-
.../tools/formats/NameSampleDataStreamFactory.java | 8 +--
.../tools/formats/ParseSampleStreamFactory.java | 6 +-
.../tools/formats/SentenceSampleStreamFactory.java | 6 +-
.../tools/formats/TokenSampleStreamFactory.java | 6 +-
.../TwentyNewsgroupSampleStreamFactory.java | 6 +-
.../tools/formats/WordTagSampleStreamFactory.java | 8 +--
.../formats/ad/ADChunkSampleStreamFactory.java | 6 +-
.../formats/ad/ADNameSampleStreamFactory.java | 6 +-
.../tools/formats/ad/ADPOSSampleStreamFactory.java | 8 +--
.../formats/ad/ADSentenceSampleStreamFactory.java | 8 +--
.../formats/ad/ADTokenSampleStreamFactory.java | 8 +--
.../formats/brat/BratNameSampleStreamFactory.java | 3 +-
.../conllu/ConlluLemmaSampleStreamFactory.java | 6 +-
.../conllu/ConlluPOSSampleStreamFactory.java | 6 +-
.../conllu/ConlluSentenceSampleStreamFactory.java | 6 +-
.../conllu/ConlluTokenSampleStreamFactory.java | 6 +-
.../convert/NameToSentenceSampleStreamFactory.java | 6 +-
.../convert/NameToTokenSampleStreamFactory.java | 6 +-
.../convert/POSToSentenceSampleStreamFactory.java | 6 +-
.../convert/POSToTokenSampleStreamFactory.java | 6 +-
.../convert/ParseToPOSSampleStreamFactory.java | 3 +-
.../ParseToSentenceSampleStreamFactory.java | 3 +-
.../convert/ParseToTokenSampleStreamFactory.java | 3 +-
.../ConstitParseSampleStreamFactory.java | 3 +-
.../IrishSentenceBankSentenceStreamFactory.java | 7 +-
.../IrishSentenceBankTokenSampleStreamFactory.java | 7 +-
.../LeipzigLanguageSampleStreamFactory.java | 10 +--
.../letsmt/LetsmtSentenceStreamFactory.java | 6 +-
.../masc/MascNamedEntitySampleStreamFactory.java | 6 +-
.../formats/masc/MascPOSSampleStreamFactory.java | 6 +-
.../tools/formats/masc/MascPennTagParser.java | 10 +--
.../opennlp/tools/formats/masc/MascSentence.java | 8 ++-
.../masc/MascSentenceSampleStreamFactory.java | 6 +-
.../java/opennlp/tools/formats/masc/MascToken.java | 1 +
.../formats/masc/MascTokenSampleStreamFactory.java | 6 +-
.../java/opennlp/tools/formats/masc/MascWord.java | 1 +
.../moses/MosesSentenceSampleStreamFactory.java | 6 +-
.../formats/muc/Muc6NameSampleStreamFactory.java | 3 +-
.../nkjp/NKJPSentenceSampleStreamFactory.java | 9 ++-
.../OntoNotesNameSampleStreamFactory.java | 2 +-
.../ontonotes/OntoNotesPOSSampleStreamFactory.java | 3 +-
.../OntoNotesParseSampleStreamFactory.java | 3 +-
.../java/opennlp/tools/langdetect/Language.java | 2 +
.../opennlp/tools/langdetect/LanguageSample.java | 1 +
.../java/opennlp/tools/lemmatizer/LemmaSample.java | 11 +--
.../lemmatizer/LemmaSampleSequenceStream.java | 6 +-
.../opennlp/tools/lemmatizer/LemmatizerME.java | 10 +--
.../opennlp/tools/lemmatizer/LemmatizerModel.java | 3 +-
.../opennlp/tools/ml/AbstractSequenceTrainer.java | 42 ------------
.../java/opennlp/tools/ml/AbstractTrainer.java | 5 +-
.../tools/ml/EventModelSequenceTrainer.java | 9 +--
.../main/java/opennlp/tools/ml/EventTrainer.java | 6 +-
.../java/opennlp/tools/ml/SequenceTrainer.java | 5 +-
.../main/java/opennlp/tools/ml/TrainerFactory.java | 37 +++++-----
.../tools/ml/maxent/quasinewton/QNTrainer.java | 5 +-
.../opennlp/tools/ml/model/SequenceStream.java | 10 +--
.../tools/ml/model/SequenceStreamEventStream.java | 6 +-
.../SimplePerceptronSequenceTrainer.java | 9 ++-
.../tools/namefind/NameFinderEventStream.java | 4 --
.../java/opennlp/tools/namefind/NameFinderME.java | 2 +-
.../java/opennlp/tools/namefind/NameSample.java | 5 +-
.../tools/namefind/NameSampleSequenceStream.java | 15 ++--
.../tools/namefind/TokenNameFinderModel.java | 4 +-
.../java/opennlp/tools/postag/POSDictionary.java | 16 -----
.../main/java/opennlp/tools/postag/POSModel.java | 1 +
.../main/java/opennlp/tools/postag/POSSample.java | 11 ++-
.../tools/postag/POSSampleSequenceStream.java | 14 ++--
.../opennlp/tools/sentdetect/SentenceModel.java | 2 +-
.../opennlp/tools/sentdetect/SentenceSample.java | 1 +
.../java/opennlp/tools/tokenize/TokenSample.java | 1 +
.../opennlp/tools/tokenize/TokenizerModel.java | 2 +-
.../java/opennlp/tools/util/BaseToolFactory.java | 13 ++--
.../src/main/java/opennlp/tools/util/Cache.java | 4 +-
.../main/java/opennlp/tools/util/DownloadUtil.java | 4 +-
.../src/main/java/opennlp/tools/util/Span.java | 1 +
.../opennlp/tools/util/TrainingParameters.java | 79 +---------------------
.../tools/util/featuregen/GeneratorFactory.java | 6 +-
.../java/opennlp/tools/util/model/BaseModel.java | 6 +-
.../tools/util/model/DictionarySerializer.java | 2 +-
.../tools/util/model/GenericModelSerializer.java | 2 +-
.../tools/util/model/PropertiesSerializer.java | 2 +-
.../AggregateCharSequenceNormalizer.java | 1 +
.../normalizer/EmojiCharSequenceNormalizer.java | 2 +
.../normalizer/NumberCharSequenceNormalizer.java | 2 +
.../normalizer/ShrinkCharSequenceNormalizer.java | 2 +
.../normalizer/TwitterCharSequenceNormalizer.java | 2 +
.../util/normalizer/UrlCharSequenceNormalizer.java | 1 +
.../test/java/opennlp/tools/cmdline/CLITest.java | 3 +
.../convert/FileToStringSampleStreamTest.java | 5 +-
.../tools/formats/ad/ADTokenSampleStreamTest.java | 6 +-
.../opennlp/tools/langdetect/DummyFactory.java | 21 +++---
.../langdetect/LanguageDetectorFactoryTest.java | 2 +-
.../languagemodel/NgramLanguageModelTest.java | 38 ++++++-----
.../test/java/opennlp/tools/ml/ArrayMathTest.java | 9 +--
.../java/opennlp/tools/ml/MockEventTrainer.java | 6 +-
.../java/opennlp/tools/ml/MockSequenceTrainer.java | 9 ++-
.../tools/namefind/NameFinderEventStreamTest.java | 5 +-
.../opennlp/tools/postag/POSTaggerFactoryTest.java | 4 +-
.../opennlp/tools/util/TrainingParametersTest.java | 30 ++++----
.../src/main/java/opennlp/uima/parser/Parser.java | 6 +-
145 files changed, 475 insertions(+), 584 deletions(-)
diff --git a/opennlp-dl/pom.xml b/opennlp-dl/pom.xml
index 214c0be4..ecc56984 100644
--- a/opennlp-dl/pom.xml
+++ b/opennlp-dl/pom.xml
@@ -29,7 +29,7 @@
</parent>
<groupId>org.apache.opennlp</groupId>
<artifactId>opennlp-dl</artifactId>
- <name>opennlp-dl</name>
+ <name>Apache OpenNLP DL</name>
<dependencies>
<dependency>
<groupId>org.apache.opennlp</groupId>
diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
index 43c85cea..23c43b6e 100644
--- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
+++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java
@@ -62,7 +62,7 @@ public class XMLDictionaryToTableTool extends BasicCmdLineTool {
tagDictionary = POSDictionary.create(new FileInputStream(dictInFile));
} catch (IOException e) {
throw new TerminateToolException(-1,
- "Error while loading XML POS Dictionay: " + e.getMessage(), e);
+ "Error while loading XML POS Dictionary: " + e.getMessage(), e);
}
Iterator<String> iterator = tagDictionary.iterator();
@@ -78,7 +78,6 @@ public class XMLDictionaryToTableTool extends BasicCmdLineTool {
}
}
}
- writer.close();
System.out.println("Created dictionary: " + dictOutFile.toPath());
} catch (IOException e) {
throw new TerminateToolException(-1, "Error while writing output: "
diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
index f7036214..216114e5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
@@ -17,20 +17,21 @@
package opennlp.tools.chunker;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import opennlp.tools.commons.Sample;
import opennlp.tools.util.Span;
/**
* Class for holding chunks for a single unit of text.
*/
-public class ChunkSample implements Serializable {
+public class ChunkSample implements Sample {
+ private static final long serialVersionUID = -3092850871020409815L;
private final List<String> sentence;
private final List<String> tags;
private final List<String> preds;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java
index eb42aa93..4a6d2d51 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java
@@ -25,7 +25,7 @@ import opennlp.tools.ml.model.Sequence;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.ObjectStream;
-public class ChunkSampleSequenceStream implements SequenceStream {
+public class ChunkSampleSequenceStream implements SequenceStream<ChunkSample> {
private final ObjectStream<ChunkSample> samples;
private final ChunkerContextGenerator contextGenerator;
@@ -37,7 +37,7 @@ public class ChunkSampleSequenceStream implements SequenceStream {
}
@Override
- public Sequence read() throws IOException {
+ public Sequence<ChunkSample> read() throws IOException {
ChunkSample sample = samples.read();
if (sample != null) {
@@ -60,7 +60,7 @@ public class ChunkSampleSequenceStream implements SequenceStream {
}
@Override
- public Event[] updateContext(Sequence sequence, AbstractModel model) {
+ public Event[] updateContext(Sequence<ChunkSample> sequence, AbstractModel model) {
// TODO: Should be implemented for Perceptron sequence learning ...
return null;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java
index 507b3497..212a1ec0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java
@@ -39,7 +39,7 @@ import opennlp.tools.util.TokenTag;
import opennlp.tools.util.TrainingParameters;
/**
- * The class represents a maximum-entropy-based chunker. Such a chunker can be used to
+ * The class represents a maximum-entropy-based chunker. Such a chunker can be used to
* find flat structures based on sequence inputs such as noun phrases or named entities.
*/
public class ChunkerME implements Chunker {
@@ -53,8 +53,8 @@ public class ChunkerME implements Chunker {
*/
protected SequenceClassificationModel<TokenTag> model;
- private ChunkerContextGenerator contextGenerator;
- private SequenceValidator<TokenTag> sequenceValidator;
+ private final ChunkerContextGenerator contextGenerator;
+ private final SequenceValidator<TokenTag> sequenceValidator;
/**
* Initializes the current instance with the specified model and
@@ -195,7 +195,7 @@ public class ChunkerME implements Chunker {
chunkerModel = trainer.train(es);
}
else if (TrainerType.SEQUENCE_TRAINER.equals(trainerType)) {
- SequenceTrainer trainer = TrainerFactory.getSequenceModelTrainer(
+ SequenceTrainer<ChunkSample> trainer = TrainerFactory.getSequenceModelTrainer(
mlParams, manifestInfoEntries);
// TODO: This will probably cause issue, since the feature generator uses the outcomes array
diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
index 393c2faf..4ab01012 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerModel.java
@@ -43,6 +43,7 @@ import opennlp.tools.util.model.BaseModel;
*/
public class ChunkerModel extends BaseModel {
+ private static final long serialVersionUID = 1608653769616498232L;
private static final String COMPONENT_NAME = "ChunkerME";
private static final String CHUNKER_MODEL_ENTRY_NAME = "chunker.model";
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractConverterTool.java
index bcc61a9d..f031d7d7 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractConverterTool.java
@@ -28,7 +28,7 @@ import opennlp.tools.util.ObjectStream;
* @param <T> class of data sample the tool converts, for example {@link opennlp.tools.postag
* .POSSample}
*/
-public abstract class AbstractConverterTool<T> extends TypedCmdLineTool<T> {
+public abstract class AbstractConverterTool<T,P> extends TypedCmdLineTool<T,P> {
/**
* Constructor with type parameter.
@@ -40,7 +40,7 @@ public abstract class AbstractConverterTool<T> extends TypedCmdLineTool<T> {
}
public String getShortDescription() {
- Map<String, ObjectStreamFactory<T>> factories = StreamFactoryRegistry.getFactories(type);
+ Map<String, ObjectStreamFactory<T,P>> factories = StreamFactoryRegistry.getFactories(type);
StringBuilder help = new StringBuilder();
if (2 == factories.keySet().size()) { //opennlp + foreign
for (String format : factories.keySet()) {
@@ -68,7 +68,7 @@ public abstract class AbstractConverterTool<T> extends TypedCmdLineTool<T> {
}
public String getHelp() {
- Map<String, ObjectStreamFactory<T>> factories = StreamFactoryRegistry.getFactories(type);
+ Map<String, ObjectStreamFactory<T,P>> factories = StreamFactoryRegistry.getFactories(type);
StringBuilder help = new StringBuilder("help|");
for (String formatName : factories.keySet()) {
if (!StreamFactoryRegistry.DEFAULT_FORMAT.equals(formatName)) {
@@ -87,7 +87,7 @@ public abstract class AbstractConverterTool<T> extends TypedCmdLineTool<T> {
System.out.println(getHelp());
} else {
format = args[0];
- ObjectStreamFactory<T> streamFactory = getStreamFactory(format);
+ ObjectStreamFactory<T,P> streamFactory = getStreamFactory(format);
String[] formatArgs = new String[args.length - 1];
System.arraycopy(args, 1, formatArgs, 0, formatArgs.length);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractEvaluatorTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractEvaluatorTool.java
index 46301cea..b72f2876 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractEvaluatorTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractEvaluatorTool.java
@@ -25,7 +25,7 @@ import opennlp.tools.util.ObjectStream;
public class AbstractEvaluatorTool<T, P> extends AbstractTypedParamTool<T, P> {
protected P params;
- protected ObjectStreamFactory<T> factory;
+ protected ObjectStreamFactory<T, P> factory;
protected ObjectStream<T> sampleStream;
/**
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
index 2a84f897..e2fe648d 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/AbstractTypedParamTool.java
@@ -20,7 +20,7 @@ package opennlp.tools.cmdline;
/**
* Base class for tools which take additional parameters. For example, trainers or evaluators.
*/
-public abstract class AbstractTypedParamTool<T, P> extends TypedCmdLineTool<T> {
+public abstract class AbstractTypedParamTool<T, P> extends TypedCmdLineTool<T, P> {
/**
* variable to access the parameters
@@ -43,7 +43,7 @@ public abstract class AbstractTypedParamTool<T, P> extends TypedCmdLineTool<T> {
return getBasicHelp(paramsClass,
StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT).getParameters());
} else {
- ObjectStreamFactory<T> factory = StreamFactoryRegistry.getFactory(type, format);
+ ObjectStreamFactory<T,P> factory = StreamFactoryRegistry.getFactory(type, format);
if (null == factory) {
throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp());
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
index 3cd98b87..beee3cfe 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java
@@ -220,9 +220,8 @@ public class ArgumentParser {
* @param argProxyInterface interface with parameter descriptions
* @return the help message usage string
*/
- @SuppressWarnings({"unchecked"})
public static <T> String createUsage(Class<T> argProxyInterface) {
- return createUsage(new Class[]{argProxyInterface});
+ return createUsage(new Class<?>[]{argProxyInterface});
}
/**
@@ -384,9 +383,8 @@ public class ArgumentParser {
* @param argProxyInterface interface with parameters description
* @return true, if arguments are valid
*/
- @SuppressWarnings({"unchecked"})
public static <T> boolean validateArguments(String[] args, Class<T> argProxyInterface) {
- return validateArguments(args, new Class[]{argProxyInterface});
+ return validateArguments(args, new Class<?>[]{argProxyInterface});
}
/**
@@ -410,7 +408,7 @@ public class ArgumentParser {
* @return null, if arguments are valid or error message otherwise
*/
public static String validateArgumentsLoudly(String[] args, Class<?> argProxyInterface) {
- return validateArgumentsLoudly(args, new Class[]{argProxyInterface});
+ return validateArgumentsLoudly(args, new Class<?>[]{argProxyInterface});
}
/**
@@ -521,7 +519,7 @@ public class ArgumentParser {
return (T) java.lang.reflect.Proxy.newProxyInstance(
argProxyInterface.getClassLoader(),
- new Class[]{argProxyInterface},
+ new Class<?>[]{argProxyInterface},
new ArgumentProxy(arguments));
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
index 06fe227a..fad0a351 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java
@@ -244,7 +244,7 @@ public final class CLI {
if ((0 == toolArguments.length && tool.hasParams()) ||
0 < toolArguments.length && "help".equals(toolArguments[0])) {
if (tool instanceof TypedCmdLineTool) {
- System.out.println(((TypedCmdLineTool<?>) tool).getHelp(formatName));
+ System.out.println(((TypedCmdLineTool<?,?>) tool).getHelp(formatName));
} else if (tool instanceof BasicCmdLineTool) {
System.out.println(tool.getHelp());
}
@@ -253,7 +253,7 @@ public final class CLI {
}
if (tool instanceof TypedCmdLineTool) {
- ((TypedCmdLineTool<?>) tool).run(formatName, toolArguments);
+ ((TypedCmdLineTool<?,?>) tool).run(formatName, toolArguments);
} else if (tool instanceof BasicCmdLineTool) {
if (-1 == idx) {
((BasicCmdLineTool) tool).run(toolArguments);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
index 8fd5fd32..7fcdfc5b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java
@@ -120,13 +120,13 @@ public class GenerateManualTool {
appendCode(tool.getHelp(), sb);
if (TypedCmdLineTool.class.isAssignableFrom(tool.getClass())) {
- appendHelpForTool((TypedCmdLineTool<?>) tool, sb);
+ appendHelpForTool((TypedCmdLineTool<?,?>) tool, sb);
}
sb.append("</section>\n\n");
}
- private static void appendHelpForTool(TypedCmdLineTool<?> tool,
+ private static void appendHelpForTool(TypedCmdLineTool<?,?> tool,
StringBuilder sb) {
Class<?> type = tool.type;
@@ -135,7 +135,7 @@ public class GenerateManualTool {
Map<String, List<Argument>> formatArguments = new LinkedHashMap<>();
for (String formatName : formats) {
if (!StreamFactoryRegistry.DEFAULT_FORMAT.equals(formatName)) {
- ObjectStreamFactory<?> format = tool.getStreamFactory(formatName);
+ ObjectStreamFactory<?,?> format = tool.getStreamFactory(formatName);
formatArguments.put(formatName,
ArgumentParser.createArguments(format.getParameters()));
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java
index 4f48bbf3..b2f9fb19 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ObjectStreamFactory.java
@@ -19,7 +19,7 @@ package opennlp.tools.cmdline;
import opennlp.tools.util.ObjectStream;
-public interface ObjectStreamFactory<T> {
+public interface ObjectStreamFactory<T,P> {
/**
* Returns interface with parameters description.
@@ -28,7 +28,7 @@ public interface ObjectStreamFactory<T> {
*
* @return interface with parameters description
*/
- <P> Class<P> getParameters();
+ Class<P> getParameters();
/**
* Creates the <code>ObjectStream</code>.
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java
index 215c80b5..957ee4ca 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java
@@ -71,11 +71,11 @@ import opennlp.tools.formats.ontonotes.OntoNotesPOSSampleStreamFactory;
import opennlp.tools.formats.ontonotes.OntoNotesParseSampleStreamFactory;
/**
- * Registry for object stream factories.
+ * Registry for {@link ObjectStreamFactory object stream factories}.
*/
public final class StreamFactoryRegistry {
- private static final Map<Class, Map<String, ObjectStreamFactory>> registry = new HashMap<>();
+ private static final Map<Class<?>, Map<String, ObjectStreamFactory<?,?>>> registry = new HashMap<>();
static {
ChunkerSampleStreamFactory.registerFactory();
@@ -148,19 +148,19 @@ public final class StreamFactoryRegistry {
}
/**
- * Registers <code>factory</code> which reads format named <code>formatName</code> and
- * instantiates streams producing objects of <code>sampleClass</code> class.
+ * Registers <code>factory</code> which reads format named {@code formatName} and
+ * instantiates streams producing objects of {@code sampleClass} class.
*
* @param sampleClass class of the objects, produced by the streams instantiated by the factory
* @param formatName name of the format
* @param factory instance of the factory
* @return true if the factory was successfully registered
*/
- public static boolean registerFactory(Class sampleClass,
+ public static <T, P> boolean registerFactory(Class<T> sampleClass,
String formatName,
- ObjectStreamFactory factory) {
+ ObjectStreamFactory<T, P> factory) {
boolean result;
- Map<String, ObjectStreamFactory> formats = registry.get(sampleClass);
+ Map<String, ObjectStreamFactory<?,?>> formats = registry.get(sampleClass);
if (null == formats) {
formats = new HashMap<>();
}
@@ -175,49 +175,46 @@ public final class StreamFactoryRegistry {
}
/**
- * Unregisters a factory which reads format named <code>formatName</code> and
- * instantiates streams producing objects of <code>sampleClass</code> class.
+ * Unregisters a factory which reads format named {@code formatName} and
+ * instantiates streams producing objects of {@code sampleClass} class.
*
* @param sampleClass class of the objects, produced by the streams instantiated by the factory
* @param formatName name of the format
*/
- public static void unregisterFactory(Class sampleClass, String formatName) {
- Map<String, ObjectStreamFactory> formats = registry.get(sampleClass);
+ public static <T> void unregisterFactory(Class<T> sampleClass, String formatName) {
+ Map<String, ObjectStreamFactory<?, ?>> formats = registry.get(sampleClass);
if (null != formats) {
- if (formats.containsKey(formatName)) {
- formats.remove(formatName);
- }
+ formats.remove(formatName);
}
}
/**
- * Returns all factories which produce objects of <code>sampleClass</code> class.
+ * Returns all factories which produce objects of {@code sampleClass} class.
*
* @param sampleClass class of the objects, produced by the streams instantiated by the factory
* @return formats mapped to factories
*/
@SuppressWarnings("unchecked")
- public static <T> Map<String, ObjectStreamFactory<T>> getFactories(Class<T> sampleClass) {
- return (Map<String, ObjectStreamFactory<T>>) (Object) registry.get(sampleClass);
+ public static <T,P> Map<String, ObjectStreamFactory<T,P>> getFactories(Class<T> sampleClass) {
+ return (Map<String, ObjectStreamFactory<T,P>>) (Object) registry.get(sampleClass);
}
/**
- * Returns a factory which reads format named <code>formatName</code> and
- * instantiates streams producing objects of <code>sampleClass</code> class.
+ * Returns a factory which reads format named {@code formatName} and
+ * instantiates streams producing objects of {@code sampleClass} class.
*
* @param sampleClass class of the objects, produced by the streams instantiated by the factory
* @param formatName name of the format, if null, assumes OpenNLP format
* @return factory instance
*/
@SuppressWarnings("unchecked")
- public static <T> ObjectStreamFactory<T> getFactory(Class<T> sampleClass,
- String formatName) {
+ public static <T,P> ObjectStreamFactory<T,P> getFactory(Class<T> sampleClass, String formatName) {
if (null == formatName) {
formatName = DEFAULT_FORMAT;
}
- ObjectStreamFactory<T> factory = registry.containsKey(sampleClass) ?
- registry.get(sampleClass).get(formatName) : null;
+ ObjectStreamFactory<T,P> factory = registry.containsKey(sampleClass) ?
+ (ObjectStreamFactory<T, P>) registry.get(sampleClass).get(formatName) : null;
if (factory != null) {
return factory;
@@ -230,7 +227,7 @@ public final class StreamFactoryRegistry {
// Otherwise there will be class cast exceptions later in the flow
try {
- return (ObjectStreamFactory<T>) factoryClazz.newInstance();
+ return (ObjectStreamFactory<T,P>) factoryClazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
return null;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/TypedCmdLineTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/TypedCmdLineTool.java
index 85ab2cb4..529e0f9c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/TypedCmdLineTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/TypedCmdLineTool.java
@@ -23,7 +23,7 @@ import java.util.Map;
* Base class for tools which support processing of samples of some type T
* coming from a stream of a certain format.
*/
-public abstract class TypedCmdLineTool<T>
+public abstract class TypedCmdLineTool<T, P>
extends CmdLineTool {
/**
@@ -46,8 +46,8 @@ public abstract class TypedCmdLineTool<T>
* @param format data format name
* @return stream factory for the type of this tool for the format
*/
- protected ObjectStreamFactory<T> getStreamFactory(String format) {
- ObjectStreamFactory<T> factory = StreamFactoryRegistry.getFactory(type, format);
+ protected ObjectStreamFactory<T, P> getStreamFactory(String format) {
+ ObjectStreamFactory<T, P> factory = StreamFactoryRegistry.getFactory(type, format);
if (null != factory) {
return factory;
} else {
@@ -64,9 +64,8 @@ public abstract class TypedCmdLineTool<T>
* @param format data format name
* @param <A> A
*/
- @SuppressWarnings({"unchecked"})
protected <A> void validateAllArgs(String[] args, Class<A> argProxyInterface, String format) {
- ObjectStreamFactory<T> factory = getStreamFactory(format);
+ ObjectStreamFactory<T, P> factory = getStreamFactory(format);
String errMessage = ArgumentParser.validateArgumentsLoudly(args, argProxyInterface,
factory.<A>getParameters());
if (null != errMessage) {
@@ -79,7 +78,7 @@ public abstract class TypedCmdLineTool<T>
* @param factory a stream factory
* @param args arguments
*/
- protected void validateFactoryArgs(ObjectStreamFactory<T> factory, String[] args) {
+ protected void validateFactoryArgs(ObjectStreamFactory<T, P> factory, String[] args) {
String errMessage = ArgumentParser.validateArgumentsLoudly(args, factory.getParameters());
if (null != errMessage) {
throw new TerminateToolException(1, "Format parameters are invalid: " + errMessage + "\n" +
@@ -89,7 +88,7 @@ public abstract class TypedCmdLineTool<T>
@Override
protected String getBasicHelp(Class<?>... argProxyInterfaces) {
- Map<String, ObjectStreamFactory<T>> factories = StreamFactoryRegistry.getFactories(type);
+ Map<String, ObjectStreamFactory<T, P>> factories = StreamFactoryRegistry.getFactories(type);
String formatsHelp = " ";
if (1 < factories.size()) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerConverterTool.java
index 60e72ed3..f001f290 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerConverterTool.java
@@ -19,12 +19,13 @@ package opennlp.tools.cmdline.chunker;
import opennlp.tools.chunker.ChunkSample;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
/**
* Tool to convert multiple data formats into native OpenNLP chunker training
* format.
*/
-public class ChunkerConverterTool extends AbstractConverterTool<ChunkSample> {
+public class ChunkerConverterTool extends AbstractConverterTool<ChunkSample, BasicFormatParams> {
public ChunkerConverterTool() {
super(ChunkSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatConverterTool.java
index eb54a747..d7c25c94 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.doccat;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.doccat.DocumentSample;
-public class DoccatConverterTool extends AbstractConverterTool<DocumentSample> {
+public class DoccatConverterTool extends AbstractConverterTool<DocumentSample, BasicFormatParams> {
public DoccatConverterTool() {
super(DocumentSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/langdetect/LanguageDetectorConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/langdetect/LanguageDetectorConverterTool.java
index 69d9db78..a78e5805 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/langdetect/LanguageDetectorConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/langdetect/LanguageDetectorConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.langdetect;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.langdetect.LanguageSample;
-public class LanguageDetectorConverterTool extends AbstractConverterTool<LanguageSample> {
+public class LanguageDetectorConverterTool extends AbstractConverterTool<LanguageSample, BasicFormatParams> {
public LanguageDetectorConverterTool() {
super(LanguageSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderConverterTool.java
index 777f6042..18b71ad9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderConverterTool.java
@@ -18,13 +18,14 @@
package opennlp.tools.cmdline.namefind;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.namefind.NameSample;
/**
* Tool to convert multiple data formats into native OpenNLP name finder training
* format.
*/
-public class TokenNameFinderConverterTool extends AbstractConverterTool<NameSample> {
+public class TokenNameFinderConverterTool extends AbstractConverterTool<NameSample, BasicFormatParams> {
public TokenNameFinderConverterTool() {
super(NameSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTrainerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTrainerTool.java
index f3cef488..bc2acbac 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTrainerTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTrainerTool.java
@@ -90,7 +90,7 @@ public final class TokenNameFinderTrainerTool
Map<String, Object> resources = new HashMap<>();
if (resourcePath != null) {
- Map<String, ArtifactSerializer> artifactSerializers = new HashMap<>();
+ Map<String, ArtifactSerializer<?>> artifactSerializers = new HashMap<>();
if (featureGenDescriptor != null) {
@@ -100,7 +100,7 @@ public final class TokenNameFinderTrainerTool
}
}
- for (Map.Entry<String, ArtifactSerializer> serializerMapping : artifactSerializers.entrySet()) {
+ for (Map.Entry<String, ArtifactSerializer<?>> serializerMapping : artifactSerializers.entrySet()) {
String resourceName = serializerMapping.getKey();
try (InputStream resourceIn = CmdLineUtil.openInFile(new File(resourcePath, resourceName))) {
resources.put(resourceName, serializerMapping.getValue().create(resourceIn));
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ModelUpdaterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ModelUpdaterTool.java
index c3ef2257..8ebf3bb1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ModelUpdaterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ModelUpdaterTool.java
@@ -55,7 +55,7 @@ abstract class ModelUpdaterTool
File modelFile = params.getModel();
ParserModel originalParserModel = new ParserModelLoader().load(modelFile);
- ObjectStreamFactory<Parse> factory = getStreamFactory(format);
+ ObjectStreamFactory<Parse,ModelUpdaterParams> factory = getStreamFactory(format);
String[] fargs = ArgumentParser.filter(args, factory.getParameters());
validateFactoryArgs(factory, fargs);
ObjectStream<Parse> sampleStream = factory.create(fargs);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
index 63b21235..220e2a4a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.parser;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.parser.Parse;
-public class ParserConverterTool extends AbstractConverterTool<Parse> {
+public class ParserConverterTool extends AbstractConverterTool<Parse, BasicFormatParams> {
public ParserConverterTool() {
super(Parse.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserTrainerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserTrainerTool.java
index 2709fd59..956bba61 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserTrainerTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserTrainerTool.java
@@ -81,9 +81,9 @@ public final class ParserTrainerTool extends AbstractTrainerTool<Parse, TrainerT
return type;
}
- static HeadRules creaeHeadRules(TrainerToolParams params) throws IOException {
+ static HeadRules createHeadRules(TrainerToolParams params) throws IOException {
- ArtifactSerializer headRulesSerializer;
+ ArtifactSerializer<?> headRulesSerializer;
if (params.getHeadRulesSerializerImpl() != null) {
headRulesSerializer = ExtensionLoader.instantiateExtension(ArtifactSerializer.class,
@@ -150,7 +150,7 @@ public final class ParserTrainerTool extends AbstractTrainerTool<Parse, TrainerT
ParserModel model;
try {
- HeadRules rules = creaeHeadRules(params);
+ HeadRules rules = createHeadRules(params);
ParserType type = parseParserType(params.getParserType());
if (params.getFun()) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerConverterTool.java
index b99888b6..463f026f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.postag;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.postag.POSSample;
-public class POSTaggerConverterTool extends AbstractConverterTool<POSSample> {
+public class POSTaggerConverterTool extends AbstractConverterTool<POSSample, BasicFormatParams> {
public POSTaggerConverterTool() {
super(POSSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorConverterTool.java
index de85d0c3..5bbe711e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.sentdetect;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.sentdetect.SentenceSample;
-public class SentenceDetectorConverterTool extends AbstractConverterTool<SentenceSample> {
+public class SentenceDetectorConverterTool extends AbstractConverterTool<SentenceSample, BasicFormatParams> {
public SentenceDetectorConverterTool() {
super(SentenceSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/TokenizerConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/TokenizerConverterTool.java
index 808fa599..9f4f1c30 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/TokenizerConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/TokenizerConverterTool.java
@@ -18,9 +18,10 @@
package opennlp.tools.cmdline.tokenizer;
import opennlp.tools.cmdline.AbstractConverterTool;
+import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.tokenize.TokenSample;
-public class TokenizerConverterTool extends AbstractConverterTool<TokenSample> {
+public class TokenizerConverterTool extends AbstractConverterTool<TokenSample, BasicFormatParams> {
public TokenizerConverterTool() {
super(TokenSample.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/commons/Sample.java
similarity index 75%
copy from opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
copy to opennlp-tools/src/main/java/opennlp/tools/commons/Sample.java
index 63b21235..2252c349 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/commons/Sample.java
@@ -15,14 +15,12 @@
* limitations under the License.
*/
-package opennlp.tools.cmdline.parser;
+package opennlp.tools.commons;
-import opennlp.tools.cmdline.AbstractConverterTool;
-import opennlp.tools.parser.Parse;
+import java.io.Serializable;
-public class ParserConverterTool extends AbstractConverterTool<Parse> {
-
- public ParserConverterTool() {
- super(Parse.class);
- }
+/**
+ * Represents a generic type of processable elements.
+ */
+public interface Sample extends Serializable {
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/commons/Trainer.java
similarity index 75%
copy from opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
copy to opennlp-tools/src/main/java/opennlp/tools/commons/Trainer.java
index 63b21235..490727ea 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/commons/Trainer.java
@@ -15,14 +15,10 @@
* limitations under the License.
*/
-package opennlp.tools.cmdline.parser;
+package opennlp.tools.commons;
-import opennlp.tools.cmdline.AbstractConverterTool;
-import opennlp.tools.parser.Parse;
-
-public class ParserConverterTool extends AbstractConverterTool<Parse> {
-
- public ParserConverterTool() {
- super(Parse.class);
- }
+/**
+ * Represents a common base for training implementations.
+ */
+public interface Trainer {
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java b/opennlp-tools/src/main/java/opennlp/tools/commons/package-info.java
similarity index 75%
copy from opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
copy to opennlp-tools/src/main/java/opennlp/tools/commons/package-info.java
index 63b21235..b3c9dc3b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/parser/ParserConverterTool.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/commons/package-info.java
@@ -15,14 +15,7 @@
* limitations under the License.
*/
-package opennlp.tools.cmdline.parser;
-
-import opennlp.tools.cmdline.AbstractConverterTool;
-import opennlp.tools.parser.Parse;
-
-public class ParserConverterTool extends AbstractConverterTool<Parse> {
-
- public ParserConverterTool() {
- super(Parse.class);
- }
-}
+/**
+ * Package related to common interfaces used in different contexts.
+ */
+package opennlp.tools.commons;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java
index 3f149ede..560a9b62 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java
@@ -17,7 +17,6 @@
package opennlp.tools.doccat;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -25,11 +24,14 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
+import opennlp.tools.commons.Sample;
+
/**
* Class which holds a classified document and its category.
*/
-public class DocumentSample implements Serializable {
+public class DocumentSample implements Sample {
+ private static final long serialVersionUID = -1775688015002177141L;
private final String category;
private final List<String> text;
private final Map<String, Object> extraInformation;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java
index 74d9f34e..f735c3de 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java
@@ -22,8 +22,7 @@ import java.util.Objects;
import opennlp.tools.util.Span;
/**
- * An "default" extended span that holds additional information about the Span
- *
+ * A "default" extended span that holds additional information about the Span
*
* @param <T>
*/
@@ -129,7 +128,7 @@ public class LinkedSpan<T extends BaseLink> extends Span {
}
if (obj instanceof LinkedSpan) {
- final LinkedSpan<T> other = (LinkedSpan<T>) obj;
+ final LinkedSpan<?> other = (LinkedSpan<?>) obj;
return Objects.equals(this.linkedEntries, other.linkedEntries)
&& this.sentenceid == other.sentenceid
&& Objects.equals(this.searchTerm, other.searchTerm);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/AbstractSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/AbstractSampleStreamFactory.java
index 33d0f95a..5e1429b9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/AbstractSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/AbstractSampleStreamFactory.java
@@ -22,14 +22,14 @@ import opennlp.tools.cmdline.ObjectStreamFactory;
/**
* Base class for sample stream factories.
*/
-public abstract class AbstractSampleStreamFactory<T> implements ObjectStreamFactory<T> {
+public abstract class AbstractSampleStreamFactory<T,P> implements ObjectStreamFactory<T,P> {
- protected Class params;
+ protected Class<P> params;
private AbstractSampleStreamFactory() {
}
- protected <P> AbstractSampleStreamFactory(Class<P> params) {
+ protected AbstractSampleStreamFactory(Class<P> params) {
this.params = params;
}
@@ -37,8 +37,8 @@ public abstract class AbstractSampleStreamFactory<T> implements ObjectStreamFact
return "eng";
}
- @SuppressWarnings({"unchecked"})
- public <P> Class<P> getParameters() {
+ // FIXME
+ public Class<P> getParameters() {
return params;
}
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStreamFactory.java
index 6445a4d9..2fd378df 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStreamFactory.java
@@ -27,7 +27,7 @@ import opennlp.tools.cmdline.params.BasicFormatParams;
import opennlp.tools.namefind.NameSample;
import opennlp.tools.util.ObjectStream;
-public class BioNLP2004NameSampleStreamFactory extends AbstractSampleStreamFactory<NameSample> {
+public class BioNLP2004NameSampleStreamFactory<P> extends AbstractSampleStreamFactory<NameSample, P> {
interface Parameters extends BasicFormatParams {
@ParameterDescription(valueName = "DNA,protein,cell_type,cell_line,RNA")
@@ -36,10 +36,10 @@ public class BioNLP2004NameSampleStreamFactory extends AbstractSampleStreamFacto
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- "bionlp2004", new BioNLP2004NameSampleStreamFactory(Parameters.class));
+ "bionlp2004", new BioNLP2004NameSampleStreamFactory<>(Parameters.class));
}
- protected <P> BioNLP2004NameSampleStreamFactory(Class<P> params) {
+ protected BioNLP2004NameSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ChunkerSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ChunkerSampleStreamFactory.java
index a95fe3db..4b1dfb87 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ChunkerSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ChunkerSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link ChunkSampleStream}s.
*/
-public class ChunkerSampleStreamFactory extends AbstractSampleStreamFactory<ChunkSample> {
+public class ChunkerSampleStreamFactory<P> extends AbstractSampleStreamFactory<ChunkSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(ChunkSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new ChunkerSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new ChunkerSampleStreamFactory<>(Parameters.class));
}
- protected <P> ChunkerSampleStreamFactory(Class<P> params) {
+ protected ChunkerSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStreamFactory.java
index f19328a2..246d3dce 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStreamFactory.java
@@ -32,7 +32,7 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class Conll02NameSampleStreamFactory extends LanguageSampleStreamFactory<NameSample> {
+public class Conll02NameSampleStreamFactory<P> extends LanguageSampleStreamFactory<NameSample, P> {
interface Parameters extends BasicFormatParams {
@ParameterDescription(valueName = "spa|nld")
@@ -44,10 +44,10 @@ public class Conll02NameSampleStreamFactory extends LanguageSampleStreamFactory<
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- "conll02", new Conll02NameSampleStreamFactory(Parameters.class));
+ "conll02", new Conll02NameSampleStreamFactory<>(Parameters.class));
}
- protected <P> Conll02NameSampleStreamFactory(Class<P> params) {
+ protected Conll02NameSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStreamFactory.java
index 599d48a2..75d4b082 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStreamFactory.java
@@ -29,7 +29,7 @@ import opennlp.tools.formats.Conll03NameSampleStream.LANGUAGE;
import opennlp.tools.namefind.NameSample;
import opennlp.tools.util.ObjectStream;
-public class Conll03NameSampleStreamFactory extends LanguageSampleStreamFactory<NameSample> {
+public class Conll03NameSampleStreamFactory<P> extends LanguageSampleStreamFactory<NameSample, P> {
interface Parameters extends BasicFormatParams {
@ParameterDescription(valueName = "eng|deu")
@@ -41,10 +41,10 @@ public class Conll03NameSampleStreamFactory extends LanguageSampleStreamFactory<
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- "conll03", new Conll03NameSampleStreamFactory(Parameters.class));
+ "conll03", new Conll03NameSampleStreamFactory<>(Parameters.class));
}
- protected <P> Conll03NameSampleStreamFactory(Class<P> params) {
+ protected Conll03NameSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStreamFactory.java
index 3923dfcf..d60507dc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStreamFactory.java
@@ -34,7 +34,7 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ConllXPOSSampleStreamFactory extends AbstractSampleStreamFactory<POSSample> {
+public class ConllXPOSSampleStreamFactory<P> extends AbstractSampleStreamFactory<POSSample, P> {
public static final String CONLLX_FORMAT = "conllx";
@@ -43,10 +43,10 @@ public class ConllXPOSSampleStreamFactory extends AbstractSampleStreamFactory<PO
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(POSSample.class,
- CONLLX_FORMAT, new ConllXPOSSampleStreamFactory(Parameters.class));
+ CONLLX_FORMAT, new ConllXPOSSampleStreamFactory<>(Parameters.class));
}
- protected <P> ConllXPOSSampleStreamFactory(Class<P> params) {
+ protected ConllXPOSSampleStreamFactory(Class<P> params) {
super(params);
}
@@ -57,7 +57,7 @@ public class ConllXPOSSampleStreamFactory extends AbstractSampleStreamFactory<PO
CmdLineUtil.createInputStreamFactory(params.getData());
try {
- System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8.name()));
+ System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8));
return new ConllXPOSSampleStream(inFactory, StandardCharsets.UTF_8);
} catch (UnsupportedEncodingException e) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXSentenceSampleStreamFactory.java
index 4e2dde85..06af7989 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXSentenceSampleStreamFactory.java
@@ -28,8 +28,8 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ConllXSentenceSampleStreamFactory extends
- DetokenizerSampleStreamFactory<SentenceSample> {
+public class ConllXSentenceSampleStreamFactory<P> extends
+ DetokenizerSampleStreamFactory<SentenceSample, P> {
interface Parameters extends ConllXPOSSampleStreamFactory.Parameters, DetokenizerParameter {
// TODO: make chunk size configurable
@@ -37,10 +37,11 @@ public class ConllXSentenceSampleStreamFactory extends
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- ConllXPOSSampleStreamFactory.CONLLX_FORMAT, new ConllXSentenceSampleStreamFactory(Parameters.class));
+ ConllXPOSSampleStreamFactory.CONLLX_FORMAT,
+ new ConllXSentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> ConllXSentenceSampleStreamFactory(Class<P> params) {
+ protected ConllXSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXTokenSampleStreamFactory.java
index d9d53033..ef9b3fc6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXTokenSampleStreamFactory.java
@@ -28,17 +28,17 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ConllXTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample> {
+public class ConllXTokenSampleStreamFactory<P> extends DetokenizerSampleStreamFactory<TokenSample, P> {
interface Parameters extends ConllXPOSSampleStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
- ConllXPOSSampleStreamFactory.CONLLX_FORMAT, new ConllXTokenSampleStreamFactory(Parameters.class));
+ ConllXPOSSampleStreamFactory.CONLLX_FORMAT, new ConllXTokenSampleStreamFactory<>(Parameters.class));
}
- protected <P> ConllXTokenSampleStreamFactory(Class<P> params) {
+ protected ConllXTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/DetokenizerSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/DetokenizerSampleStreamFactory.java
index cb68348b..33663dc8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/DetokenizerSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/DetokenizerSampleStreamFactory.java
@@ -30,9 +30,9 @@ import opennlp.tools.tokenize.DictionaryDetokenizer;
/**
* Base class for factories which need detokenizer.
*/
-public abstract class DetokenizerSampleStreamFactory<T> extends AbstractSampleStreamFactory<T> {
+public abstract class DetokenizerSampleStreamFactory<T, P> extends AbstractSampleStreamFactory<T, P> {
- protected <P> DetokenizerSampleStreamFactory(Class<P> params) {
+ protected DetokenizerSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/DocumentSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/DocumentSampleStreamFactory.java
index 2d8564bc..c359f1a6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/DocumentSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/DocumentSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link DocumentSampleStream}s.
*/
-public class DocumentSampleStreamFactory extends AbstractSampleStreamFactory<DocumentSample> {
+public class DocumentSampleStreamFactory<P> extends AbstractSampleStreamFactory<DocumentSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(DocumentSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new DocumentSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new DocumentSampleStreamFactory<>(Parameters.class));
}
- protected <P> DocumentSampleStreamFactory(Class<P> params) {
+ protected DocumentSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/EvalitaNameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/EvalitaNameSampleStreamFactory.java
index 673df386..2b680511 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/EvalitaNameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/EvalitaNameSampleStreamFactory.java
@@ -32,7 +32,7 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class EvalitaNameSampleStreamFactory extends LanguageSampleStreamFactory<NameSample> {
+public class EvalitaNameSampleStreamFactory<P> extends LanguageSampleStreamFactory<NameSample, P> {
interface Parameters extends BasicFormatParams {
@ParameterDescription(valueName = "it")
@@ -44,10 +44,10 @@ public class EvalitaNameSampleStreamFactory extends LanguageSampleStreamFactory<
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- "evalita", new EvalitaNameSampleStreamFactory(Parameters.class));
+ "evalita", new EvalitaNameSampleStreamFactory<>(Parameters.class));
}
- protected <P> EvalitaNameSampleStreamFactory(Class<P> params) {
+ protected EvalitaNameSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageDetectorSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageDetectorSampleStreamFactory.java
index ef600638..43ad0d7b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageDetectorSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageDetectorSampleStreamFactory.java
@@ -33,8 +33,8 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link DocumentSampleStream}s.
*/
-public class LanguageDetectorSampleStreamFactory
- extends AbstractSampleStreamFactory<LanguageSample> {
+public class LanguageDetectorSampleStreamFactory<P>
+ extends AbstractSampleStreamFactory<LanguageSample, P> {
interface Parameters extends BasicFormatParams {
}
@@ -42,10 +42,10 @@ public class LanguageDetectorSampleStreamFactory
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(LanguageSample.class,
StreamFactoryRegistry.DEFAULT_FORMAT,
- new LanguageDetectorSampleStreamFactory(Parameters.class));
+ new LanguageDetectorSampleStreamFactory<>(Parameters.class));
}
- protected <P> LanguageDetectorSampleStreamFactory(Class<P> params) {
+ protected LanguageDetectorSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageSampleStreamFactory.java
index 8c7a681a..738f276a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/LanguageSampleStreamFactory.java
@@ -20,11 +20,11 @@ package opennlp.tools.formats;
/**
* Stream factory for those streams which carry language.
*/
-public abstract class LanguageSampleStreamFactory<T> extends AbstractSampleStreamFactory<T> {
+public abstract class LanguageSampleStreamFactory<T, P> extends AbstractSampleStreamFactory<T, P> {
protected String language;
- protected <P> LanguageSampleStreamFactory(Class<P> params) {
+ protected LanguageSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/LemmatizerSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/LemmatizerSampleStreamFactory.java
index 3635bafc..b91e87d6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/LemmatizerSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/LemmatizerSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link LemmaSampleStream}s.
*/
-public class LemmatizerSampleStreamFactory extends AbstractSampleStreamFactory<LemmaSample> {
+public class LemmatizerSampleStreamFactory<P> extends AbstractSampleStreamFactory<LemmaSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(LemmaSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new LemmatizerSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new LemmatizerSampleStreamFactory<>(Parameters.class));
}
- protected <P> LemmatizerSampleStreamFactory(Class<P> params) {
+ protected LemmatizerSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/NameSampleDataStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/NameSampleDataStreamFactory.java
index e6072391..5454b799 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/NameSampleDataStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/NameSampleDataStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link NameSampleDataStream}s.
*/
-public class NameSampleDataStreamFactory extends AbstractSampleStreamFactory<NameSample> {
+public class NameSampleDataStreamFactory<P> extends AbstractSampleStreamFactory<NameSample, P> {
- public static interface Parameters extends BasicFormatParams {
+ public interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new NameSampleDataStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new NameSampleDataStreamFactory<>(Parameters.class));
}
- protected <P> NameSampleDataStreamFactory(Class<P> params) {
+ protected NameSampleDataStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ParseSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ParseSampleStreamFactory.java
index 765b9eb0..dab05057 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ParseSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ParseSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link ParseSampleStream}s.
*/
-public class ParseSampleStreamFactory extends AbstractSampleStreamFactory<Parse> {
+public class ParseSampleStreamFactory<P> extends AbstractSampleStreamFactory<Parse, P> {
public interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(Parse.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new ParseSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new ParseSampleStreamFactory<>(Parameters.class));
}
- protected <P> ParseSampleStreamFactory(Class<P> params) {
+ protected ParseSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/SentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/SentenceSampleStreamFactory.java
index 2292ed85..51ba2ce4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/SentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/SentenceSampleStreamFactory.java
@@ -33,17 +33,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link SentenceSampleStream}s.
*/
-public class SentenceSampleStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class SentenceSampleStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new SentenceSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new SentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> SentenceSampleStreamFactory(Class<P> params) {
+ protected SentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/TokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/TokenSampleStreamFactory.java
index a0a13153..bad46bf9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/TokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/TokenSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link TokenSampleStream}s.
*/
-public class TokenSampleStreamFactory extends LanguageSampleStreamFactory<TokenSample> {
+public class TokenSampleStreamFactory<P> extends LanguageSampleStreamFactory<TokenSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new TokenSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new TokenSampleStreamFactory<>(Parameters.class));
}
- protected <P> TokenSampleStreamFactory(Class<P> params) {
+ protected TokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/TwentyNewsgroupSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/TwentyNewsgroupSampleStreamFactory.java
index 5583c7c6..827d2096 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/TwentyNewsgroupSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/TwentyNewsgroupSampleStreamFactory.java
@@ -32,15 +32,15 @@ import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import opennlp.tools.util.ObjectStream;
-public class TwentyNewsgroupSampleStreamFactory extends AbstractSampleStreamFactory<DocumentSample> {
+public class TwentyNewsgroupSampleStreamFactory<P> extends AbstractSampleStreamFactory<DocumentSample,P> {
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(DocumentSample.class,
"20newsgroup",
- new TwentyNewsgroupSampleStreamFactory(TwentyNewsgroupSampleStreamFactory.Parameters.class));
+ new TwentyNewsgroupSampleStreamFactory<>(TwentyNewsgroupSampleStreamFactory.Parameters.class));
}
- protected <P> TwentyNewsgroupSampleStreamFactory(Class<P> params) {
+ protected TwentyNewsgroupSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/WordTagSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/WordTagSampleStreamFactory.java
index c52e55fe..c8d171d9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/WordTagSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/WordTagSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class WordTagSampleStreamFactory extends AbstractSampleStreamFactory<POSSample> {
+public class WordTagSampleStreamFactory<P> extends AbstractSampleStreamFactory<POSSample, P> {
- public static interface Parameters extends BasicFormatParams {
+ public interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(POSSample.class,
- StreamFactoryRegistry.DEFAULT_FORMAT, new WordTagSampleStreamFactory(Parameters.class));
+ StreamFactoryRegistry.DEFAULT_FORMAT, new WordTagSampleStreamFactory<>(Parameters.class));
}
- protected <P> WordTagSampleStreamFactory(Class<P> params) {
+ protected WordTagSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStreamFactory.java
index 1f55fe4c..42a6ee28 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStreamFactory.java
@@ -38,7 +38,7 @@ import opennlp.tools.util.PlainTextByLineStream;
* <p>
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ADChunkSampleStreamFactory extends LanguageSampleStreamFactory<ChunkSample> {
+public class ADChunkSampleStreamFactory<P> extends LanguageSampleStreamFactory<ChunkSample, P> {
interface Parameters {
//all have to be repeated, because encoding is not optional,
@@ -64,10 +64,10 @@ public class ADChunkSampleStreamFactory extends LanguageSampleStreamFactory<Chun
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(ChunkSample.class,
- "ad", new ADChunkSampleStreamFactory(Parameters.class));
+ "ad", new ADChunkSampleStreamFactory<>(Parameters.class));
}
- protected <P> ADChunkSampleStreamFactory(Class<P> params) {
+ protected ADChunkSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStreamFactory.java
index e9603a88..ca371c28 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStreamFactory.java
@@ -38,7 +38,7 @@ import opennlp.tools.util.PlainTextByLineStream;
* <p>
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ADNameSampleStreamFactory extends LanguageSampleStreamFactory<NameSample> {
+public class ADNameSampleStreamFactory<P> extends LanguageSampleStreamFactory<NameSample, P> {
interface Parameters {
//all have to be repeated, because encoding is not optional,
@@ -61,10 +61,10 @@ public class ADNameSampleStreamFactory extends LanguageSampleStreamFactory<NameS
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
- "ad", new ADNameSampleStreamFactory(Parameters.class));
+ "ad", new ADNameSampleStreamFactory<>(Parameters.class));
}
- protected <P> ADNameSampleStreamFactory(Class<P> params) {
+ protected ADNameSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java
index ab97ae2d..71fbce5e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java
@@ -35,8 +35,8 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ADPOSSampleStreamFactory extends
- LanguageSampleStreamFactory<POSSample> {
+public class ADPOSSampleStreamFactory<P> extends
+ LanguageSampleStreamFactory<POSSample, P> {
interface Parameters {
@ParameterDescription(valueName = "charsetName",
@@ -61,10 +61,10 @@ public class ADPOSSampleStreamFactory extends
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(POSSample.class, "ad",
- new ADPOSSampleStreamFactory(Parameters.class));
+ new ADPOSSampleStreamFactory<>(Parameters.class));
}
- protected <P> ADPOSSampleStreamFactory(Class<P> params) {
+ protected ADPOSSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java
index 59ebe460..ba8a11d1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java
@@ -35,8 +35,8 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ADSentenceSampleStreamFactory extends
- LanguageSampleStreamFactory<SentenceSample> {
+public class ADSentenceSampleStreamFactory<P> extends
+ LanguageSampleStreamFactory<SentenceSample, P> {
interface Parameters {
@ParameterDescription(valueName = "charsetName", description = "encoding for reading and writing text.")
@@ -56,10 +56,10 @@ public class ADSentenceSampleStreamFactory extends
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class, "ad",
- new ADSentenceSampleStreamFactory(Parameters.class));
+ new ADSentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> ADSentenceSampleStreamFactory(Class<P> params) {
+ protected ADSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADTokenSampleStreamFactory.java
index 10ee300a..ddddd498 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADTokenSampleStreamFactory.java
@@ -29,18 +29,18 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ADTokenSampleStreamFactory extends
- DetokenizerSampleStreamFactory<TokenSample> {
+public class ADTokenSampleStreamFactory<P> extends
+ DetokenizerSampleStreamFactory<TokenSample, P> {
interface Parameters extends ADNameSampleStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class, "ad",
- new ADTokenSampleStreamFactory(Parameters.class));
+ new ADTokenSampleStreamFactory<>(Parameters.class));
}
- protected <P> ADTokenSampleStreamFactory(Class<P> params) {
+ protected ADTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStreamFactory.java
index 87a0c616..e915b052 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStreamFactory.java
@@ -41,7 +41,8 @@ import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import opennlp.tools.util.ObjectStream;
-public class BratNameSampleStreamFactory extends AbstractSampleStreamFactory<NameSample> {
+public class BratNameSampleStreamFactory
+ extends AbstractSampleStreamFactory<NameSample, BratNameSampleStreamFactory.Parameters> {
interface Parameters {
@ParameterDescription(valueName = "bratDataDir", description = "location of brat data dir")
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluLemmaSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluLemmaSampleStreamFactory.java
index 3204d7ee..0647b5f8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluLemmaSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluLemmaSampleStreamFactory.java
@@ -32,7 +32,7 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ConlluLemmaSampleStreamFactory extends AbstractSampleStreamFactory<LemmaSample> {
+public class ConlluLemmaSampleStreamFactory<P> extends AbstractSampleStreamFactory<LemmaSample, P> {
interface Parameters extends BasicFormatParams {
@ArgumentParser.ParameterDescription(valueName = "tagset",
@@ -44,10 +44,10 @@ public class ConlluLemmaSampleStreamFactory extends AbstractSampleStreamFactory<
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(LemmaSample.class,
ConlluPOSSampleStreamFactory.CONLLU_FORMAT,
- new ConlluLemmaSampleStreamFactory(Parameters.class));
+ new ConlluLemmaSampleStreamFactory<>(Parameters.class));
}
- protected <P> ConlluLemmaSampleStreamFactory(Class<P> params) {
+ protected ConlluLemmaSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluPOSSampleStreamFactory.java
index 0f9d5f35..d8c64da2 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluPOSSampleStreamFactory.java
@@ -32,7 +32,7 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ConlluPOSSampleStreamFactory extends AbstractSampleStreamFactory<POSSample> {
+public class ConlluPOSSampleStreamFactory<P> extends AbstractSampleStreamFactory<POSSample, P> {
public static final String CONLLU_FORMAT = "conllu";
@@ -45,10 +45,10 @@ public class ConlluPOSSampleStreamFactory extends AbstractSampleStreamFactory<PO
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(POSSample.class,
- CONLLU_FORMAT, new ConlluPOSSampleStreamFactory(Parameters.class));
+ CONLLU_FORMAT, new ConlluPOSSampleStreamFactory<>(Parameters.class));
}
- protected <P> ConlluPOSSampleStreamFactory(Class<P> params) {
+ protected ConlluPOSSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluSentenceSampleStreamFactory.java
index 000af277..d1b9ea0d 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluSentenceSampleStreamFactory.java
@@ -28,7 +28,7 @@ import opennlp.tools.sentdetect.SentenceSample;
import opennlp.tools.util.InputStreamFactory;
import opennlp.tools.util.ObjectStream;
-public class ConlluSentenceSampleStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class ConlluSentenceSampleStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
@ArgumentParser.ParameterDescription(valueName = "sentencesPerSample",
@@ -39,10 +39,10 @@ public class ConlluSentenceSampleStreamFactory extends AbstractSampleStreamFacto
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
ConlluPOSSampleStreamFactory.CONLLU_FORMAT,
- new ConlluSentenceSampleStreamFactory(ConlluSentenceSampleStreamFactory.Parameters.class));
+ new ConlluSentenceSampleStreamFactory<>(ConlluSentenceSampleStreamFactory.Parameters.class));
}
- protected <P> ConlluSentenceSampleStreamFactory(Class<P> params) {
+ protected ConlluSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluTokenSampleStreamFactory.java
index 5db04079..413ac755 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/conllu/ConlluTokenSampleStreamFactory.java
@@ -28,7 +28,7 @@ import opennlp.tools.tokenize.TokenSample;
import opennlp.tools.util.InputStreamFactory;
import opennlp.tools.util.ObjectStream;
-public class ConlluTokenSampleStreamFactory extends AbstractSampleStreamFactory<TokenSample> {
+public class ConlluTokenSampleStreamFactory<P> extends AbstractSampleStreamFactory<TokenSample, P> {
interface Parameters extends BasicFormatParams {
}
@@ -36,10 +36,10 @@ public class ConlluTokenSampleStreamFactory extends AbstractSampleStreamFactory<
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
ConlluPOSSampleStreamFactory.CONLLU_FORMAT,
- new ConlluTokenSampleStreamFactory(ConlluTokenSampleStreamFactory.Parameters.class));
+ new ConlluTokenSampleStreamFactory<>(ConlluTokenSampleStreamFactory.Parameters.class));
}
- protected <P> ConlluTokenSampleStreamFactory(Class<P> params) {
+ protected ConlluTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToSentenceSampleStreamFactory.java
index 8a398170..5a387af8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToSentenceSampleStreamFactory.java
@@ -29,17 +29,17 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class NameToSentenceSampleStreamFactory extends DetokenizerSampleStreamFactory<SentenceSample> {
+public class NameToSentenceSampleStreamFactory<P> extends DetokenizerSampleStreamFactory<SentenceSample, P> {
interface Parameters extends NameSampleDataStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "namefinder", new NameToSentenceSampleStreamFactory(Parameters.class));
+ "namefinder", new NameToSentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> NameToSentenceSampleStreamFactory(Class<P> params) {
+ protected NameToSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToTokenSampleStreamFactory.java
index 7b2d4989..667845ea 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/NameToTokenSampleStreamFactory.java
@@ -29,17 +29,17 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class NameToTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample> {
+public class NameToTokenSampleStreamFactory<P> extends DetokenizerSampleStreamFactory<TokenSample, P> {
interface Parameters extends NameSampleDataStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
- "namefinder", new NameToTokenSampleStreamFactory(Parameters.class));
+ "namefinder", new NameToTokenSampleStreamFactory<>(Parameters.class));
}
- protected <P> NameToTokenSampleStreamFactory(Class<P> params) {
+ protected NameToTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToSentenceSampleStreamFactory.java
index e39bb345..f84331dc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToSentenceSampleStreamFactory.java
@@ -29,17 +29,17 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class POSToSentenceSampleStreamFactory extends DetokenizerSampleStreamFactory<SentenceSample> {
+public class POSToSentenceSampleStreamFactory<P> extends DetokenizerSampleStreamFactory<SentenceSample, P> {
interface Parameters extends WordTagSampleStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "pos", new POSToSentenceSampleStreamFactory(Parameters.class));
+ "pos", new POSToSentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> POSToSentenceSampleStreamFactory(Class<P> params) {
+ protected POSToSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToTokenSampleStreamFactory.java
index 0fb42820..c8a7aa89 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/POSToTokenSampleStreamFactory.java
@@ -29,17 +29,17 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class POSToTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample> {
+public class POSToTokenSampleStreamFactory<P> extends DetokenizerSampleStreamFactory<TokenSample, P> {
interface Parameters extends WordTagSampleStreamFactory.Parameters, DetokenizerParameter {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
- "pos", new POSToTokenSampleStreamFactory(Parameters.class));
+ "pos", new POSToTokenSampleStreamFactory<>(Parameters.class));
}
- protected <P> POSToTokenSampleStreamFactory(Class<P> params) {
+ protected POSToTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStreamFactory.java
index a18dff50..2db7aa16 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStreamFactory.java
@@ -28,7 +28,8 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ParseToPOSSampleStreamFactory extends LanguageSampleStreamFactory<POSSample> {
+public class ParseToPOSSampleStreamFactory
+ extends LanguageSampleStreamFactory<POSSample, ParseSampleStreamFactory.Parameters> {
private ParseToPOSSampleStreamFactory() {
super(ParseSampleStreamFactory.Parameters.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToSentenceSampleStreamFactory.java
index 33450ca3..6b929741 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToSentenceSampleStreamFactory.java
@@ -29,7 +29,8 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ParseToSentenceSampleStreamFactory extends DetokenizerSampleStreamFactory<SentenceSample> {
+public class ParseToSentenceSampleStreamFactory extends DetokenizerSampleStreamFactory
+ <SentenceSample, ParseToSentenceSampleStreamFactory.Parameters> {
interface Parameters extends ParseSampleStreamFactory.Parameters, DetokenizerParameter {
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToTokenSampleStreamFactory.java
index 318b5628..b825aad6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToTokenSampleStreamFactory.java
@@ -30,7 +30,8 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class ParseToTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample> {
+public class ParseToTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample,
+ ParseToTokenSampleStreamFactory.Parameters> {
interface Parameters extends ParseSampleStreamFactory.Parameters, DetokenizerParameter {
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamFactory.java
index 6985a304..bd39c16e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/frenchtreebank/ConstitParseSampleStreamFactory.java
@@ -26,7 +26,8 @@ import opennlp.tools.formats.convert.FileToByteArraySampleStream;
import opennlp.tools.parser.Parse;
import opennlp.tools.util.ObjectStream;
-public class ConstitParseSampleStreamFactory extends AbstractSampleStreamFactory<Parse> {
+public class ConstitParseSampleStreamFactory
+ extends AbstractSampleStreamFactory<Parse, ConstitParseSampleStreamFactory.Parameters> {
// TODO: The parameters have an encoding, but the data is in xml
interface Parameters extends BasicFormatParams {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankSentenceStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankSentenceStreamFactory.java
index e26dc561..488e3b6f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankSentenceStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankSentenceStreamFactory.java
@@ -27,18 +27,19 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.sentdetect.SentenceSample;
import opennlp.tools.util.ObjectStream;
-public class IrishSentenceBankSentenceStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class IrishSentenceBankSentenceStreamFactory<P>
+ extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "irishsentencebank", new IrishSentenceBankSentenceStreamFactory(
+ "irishsentencebank", new IrishSentenceBankSentenceStreamFactory<>(
IrishSentenceBankSentenceStreamFactory.Parameters.class));
}
- protected <P> IrishSentenceBankSentenceStreamFactory(Class<P> params) {
+ protected IrishSentenceBankSentenceStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankTokenSampleStreamFactory.java
index 86d12256..9b7429a6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/irishsentencebank/IrishSentenceBankTokenSampleStreamFactory.java
@@ -27,18 +27,19 @@ import opennlp.tools.formats.DetokenizerSampleStreamFactory;
import opennlp.tools.tokenize.TokenSample;
import opennlp.tools.util.ObjectStream;
-public class IrishSentenceBankTokenSampleStreamFactory extends DetokenizerSampleStreamFactory<TokenSample> {
+public class IrishSentenceBankTokenSampleStreamFactory<P>
+ extends DetokenizerSampleStreamFactory<TokenSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
- "irishsentencebank", new IrishSentenceBankTokenSampleStreamFactory(
+ "irishsentencebank", new IrishSentenceBankTokenSampleStreamFactory<>(
IrishSentenceBankTokenSampleStreamFactory.Parameters.class));
}
- protected <P> IrishSentenceBankTokenSampleStreamFactory(Class<P> params) {
+ protected IrishSentenceBankTokenSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/leipzig/LeipzigLanguageSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/leipzig/LeipzigLanguageSampleStreamFactory.java
index 968d00d8..ea6c5c3b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/leipzig/LeipzigLanguageSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/leipzig/LeipzigLanguageSampleStreamFactory.java
@@ -33,8 +33,8 @@ import opennlp.tools.util.ObjectStream;
/**
* <b>Note:</b> Do not use this class, internal use only!
*/
-public class LeipzigLanguageSampleStreamFactory
- extends AbstractSampleStreamFactory<LanguageSample> {
+public class LeipzigLanguageSampleStreamFactory<P>
+ extends AbstractSampleStreamFactory<LanguageSample, P> {
interface Parameters extends EncodingParameter {
@ParameterDescription(valueName = "sentencesDir",
@@ -55,13 +55,13 @@ public class LeipzigLanguageSampleStreamFactory
String getSamplesToSkip();
}
- protected <P> LeipzigLanguageSampleStreamFactory(Class<P> params) {
+ protected LeipzigLanguageSampleStreamFactory(Class<P> params) {
super(params);
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(LanguageSample.class,
- "leipzig", new LeipzigLanguageSampleStreamFactory(Parameters.class));
+ "leipzig", new LeipzigLanguageSampleStreamFactory<>(Parameters.class));
}
public ObjectStream<LanguageSample> create(String[] args) {
@@ -70,7 +70,7 @@ public class LeipzigLanguageSampleStreamFactory
File sentencesFileDir = params.getSentencesDir();
try {
- return new SampleSkipStream(new SampleShuffleStream(
+ return new SampleSkipStream<>(new SampleShuffleStream<>(
new LeipzigLanguageSampleStream(sentencesFileDir,
Integer.parseInt(params.getSentencesPerSample()),
Integer.parseInt(params.getSamplesPerLanguage()) + Integer.parseInt(params.getSamplesToSkip()))),
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/letsmt/LetsmtSentenceStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/letsmt/LetsmtSentenceStreamFactory.java
index 48eaffd9..8c83e2fc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/letsmt/LetsmtSentenceStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/letsmt/LetsmtSentenceStreamFactory.java
@@ -32,7 +32,7 @@ import opennlp.tools.tokenize.Detokenizer;
import opennlp.tools.tokenize.DictionaryDetokenizer;
import opennlp.tools.util.ObjectStream;
-public class LetsmtSentenceStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class LetsmtSentenceStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
@ArgumentParser.ParameterDescription(valueName = "dictionary",
@@ -43,11 +43,11 @@ public class LetsmtSentenceStreamFactory extends AbstractSampleStreamFactory<Sen
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "letsmt", new LetsmtSentenceStreamFactory(
+ "letsmt", new LetsmtSentenceStreamFactory<>(
LetsmtSentenceStreamFactory.Parameters.class));
}
- protected <P> LetsmtSentenceStreamFactory(Class<P> params) {
+ protected LetsmtSentenceStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascNamedEntitySampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascNamedEntitySampleStreamFactory.java
index 49bf94b0..258cac96 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascNamedEntitySampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascNamedEntitySampleStreamFactory.java
@@ -28,17 +28,17 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.namefind.NameSample;
import opennlp.tools.util.ObjectStream;
-public class MascNamedEntitySampleStreamFactory extends AbstractSampleStreamFactory<NameSample> {
+public class MascNamedEntitySampleStreamFactory<P> extends AbstractSampleStreamFactory<NameSample, P> {
public static final String MASC_FORMAT = "masc";
- protected <P> MascNamedEntitySampleStreamFactory(Class<P> params) {
+ protected MascNamedEntitySampleStreamFactory(Class<P> params) {
super(params);
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(NameSample.class,
MASC_FORMAT,
- new opennlp.tools.formats.masc.MascNamedEntitySampleStreamFactory(
+ new opennlp.tools.formats.masc.MascNamedEntitySampleStreamFactory<>(
opennlp.tools.formats.masc.MascNamedEntitySampleStreamFactory.Parameters.class));
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPOSSampleStreamFactory.java
index c3aa2164..85aba5d5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPOSSampleStreamFactory.java
@@ -28,17 +28,17 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.postag.POSSample;
import opennlp.tools.util.ObjectStream;
-public class MascPOSSampleStreamFactory extends AbstractSampleStreamFactory<POSSample> {
+public class MascPOSSampleStreamFactory<P> extends AbstractSampleStreamFactory<POSSample, P> {
public static final String MASC_FORMAT = "masc";
- protected <P> MascPOSSampleStreamFactory(Class<P> params) {
+ protected MascPOSSampleStreamFactory(Class<P> params) {
super(params);
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(POSSample.class,
MASC_FORMAT,
- new opennlp.tools.formats.masc.MascPOSSampleStreamFactory(
+ new opennlp.tools.formats.masc.MascPOSSampleStreamFactory<>(
opennlp.tools.formats.masc.MascPOSSampleStreamFactory.Parameters.class));
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPennTagParser.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPennTagParser.java
index 9ca44a03..3356df32 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPennTagParser.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascPennTagParser.java
@@ -30,11 +30,11 @@ import org.xml.sax.helpers.DefaultHandler;
*/
public class MascPennTagParser extends DefaultHandler {
- private Map<Integer, int[]> tokenToQuarks = new HashMap<Integer, int[]>();
- private Map<Integer, String> tokenToTag = new HashMap<Integer, String>();
- private Map<Integer, String> tokenToBase = new HashMap<Integer, String>();
- private Stack<Integer> tokenStack = new Stack();
- private Stack<Integer> tokenStackTag = new Stack();
+ private final Map<Integer, int[]> tokenToQuarks = new HashMap<>();
+ private final Map<Integer, String> tokenToTag = new HashMap<>();
+ private final Map<Integer, String> tokenToBase = new HashMap<>();
+ private final Stack<Integer> tokenStack = new Stack<>();
+ private final Stack<Integer> tokenStackTag = new Stack<>();
public Map<Integer, String> getTags() {
return tokenToTag;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentence.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentence.java
index 0ba40924..ba4a1ad9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentence.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentence.java
@@ -31,7 +31,9 @@ import opennlp.tools.util.Span;
public class MascSentence extends Span {
- private class QuarkExtractor {
+ private static final long serialVersionUID = -3963079332759345419L;
+
+ private static class QuarkExtractor {
private final Map<Integer, MascWord> wordsById;
private final List<MascWord> allDocumentWords;
@@ -77,7 +79,7 @@ public class MascSentence extends Span {
private final List<MascWord> words;
private final Map<Integer, MascWord> wordsById;
private List<MascToken> sentenceTokens = null;
- private Map<Integer, Integer> tokensById = new HashMap<>();
+ private final Map<Integer, Integer> tokensById = new HashMap<>();
private List<Span> namedEntities = new ArrayList<>();
/**
@@ -227,7 +229,7 @@ public class MascSentence extends Span {
Comparator<Span> compareByStart = Comparator.comparingInt(Span::getStart);
namedEntities.sort(compareByStart);
- Set<Integer> overlaps = new HashSet();
+ Set<Integer> overlaps = new HashSet<>();
int leftIndex = 0;
int rightIndex = leftIndex + 1;
while (rightIndex < namedEntities.size()) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentenceSampleStreamFactory.java
index a445167a..ce55cfe3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascSentenceSampleStreamFactory.java
@@ -28,18 +28,18 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.sentdetect.SentenceSample;
import opennlp.tools.util.ObjectStream;
-public class MascSentenceSampleStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class MascSentenceSampleStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
public static final String MASC_FORMAT = "masc";
- protected <P> MascSentenceSampleStreamFactory(Class<P> params) {
+ protected MascSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
MASC_FORMAT,
- new opennlp.tools.formats.masc.MascSentenceSampleStreamFactory(
+ new opennlp.tools.formats.masc.MascSentenceSampleStreamFactory<>(
opennlp.tools.formats.masc.MascSentenceSampleStreamFactory.Parameters.class));
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascToken.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascToken.java
index 5d17a409..593315cf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascToken.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascToken.java
@@ -21,6 +21,7 @@ import opennlp.tools.util.Span;
public class MascToken extends Span {
+ private static final long serialVersionUID = -780646706788037041L;
private final String pos;
private final String base;
private final int tokenId;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascTokenSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascTokenSampleStreamFactory.java
index 655be154..99bf1f58 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascTokenSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascTokenSampleStreamFactory.java
@@ -28,19 +28,19 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.tokenize.TokenSample;
import opennlp.tools.util.ObjectStream;
-public class MascTokenSampleStreamFactory extends AbstractSampleStreamFactory<TokenSample> {
+public class MascTokenSampleStreamFactory<P> extends AbstractSampleStreamFactory<TokenSample, P> {
public static final String MASC_FORMAT = "masc";
- protected <P> MascTokenSampleStreamFactory(Class<P> params) {
+ protected MascTokenSampleStreamFactory(Class<P> params) {
super(params);
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(TokenSample.class,
MASC_FORMAT,
- new opennlp.tools.formats.masc.MascTokenSampleStreamFactory(
+ new opennlp.tools.formats.masc.MascTokenSampleStreamFactory<>(
opennlp.tools.formats.masc.MascTokenSampleStreamFactory.Parameters.class));
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascWord.java b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascWord.java
index a75dce73..1f3cffc3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascWord.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/masc/MascWord.java
@@ -21,6 +21,7 @@ import opennlp.tools.util.Span;
public class MascWord extends Span {
+ private static final long serialVersionUID = 2133473549058189775L;
private final int id;
/**
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/moses/MosesSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/moses/MosesSentenceSampleStreamFactory.java
index 164a4ee9..a04c4028 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/moses/MosesSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/moses/MosesSentenceSampleStreamFactory.java
@@ -32,17 +32,17 @@ import opennlp.tools.util.PlainTextByLineStream;
/**
* Factory producing OpenNLP {@link MosesSentenceSampleStream}s.
*/
-public class MosesSentenceSampleStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class MosesSentenceSampleStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
}
public static void registerFactory() {
StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "moses", new MosesSentenceSampleStreamFactory(Parameters.class));
+ "moses", new MosesSentenceSampleStreamFactory<>(Parameters.class));
}
- protected <P> MosesSentenceSampleStreamFactory(Class<P> params) {
+ protected MosesSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/muc/Muc6NameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/muc/Muc6NameSampleStreamFactory.java
index 5e9ca82c..95957d00 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/muc/Muc6NameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/muc/Muc6NameSampleStreamFactory.java
@@ -35,7 +35,8 @@ import opennlp.tools.tokenize.TokenizerModel;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.StringUtil;
-public class Muc6NameSampleStreamFactory extends AbstractSampleStreamFactory<NameSample> {
+public class Muc6NameSampleStreamFactory
+ extends AbstractSampleStreamFactory<NameSample, Muc6NameSampleStreamFactory.Parameters> {
protected Muc6NameSampleStreamFactory() {
super(Parameters.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/nkjp/NKJPSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/nkjp/NKJPSentenceSampleStreamFactory.java
index 9a944588..d126d21e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/nkjp/NKJPSentenceSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/nkjp/NKJPSentenceSampleStreamFactory.java
@@ -28,7 +28,7 @@ import opennlp.tools.formats.AbstractSampleStreamFactory;
import opennlp.tools.sentdetect.SentenceSample;
import opennlp.tools.util.ObjectStream;
-public class NKJPSentenceSampleStreamFactory extends AbstractSampleStreamFactory<SentenceSample> {
+public class NKJPSentenceSampleStreamFactory<P> extends AbstractSampleStreamFactory<SentenceSample, P> {
interface Parameters extends BasicFormatParams {
@ArgumentParser.ParameterDescription(valueName = "text",
@@ -37,12 +37,11 @@ public class NKJPSentenceSampleStreamFactory extends AbstractSampleStreamFactory
}
public static void registerFactory() {
- StreamFactoryRegistry.registerFactory(SentenceSample.class,
- "nkjp", new NKJPSentenceSampleStreamFactory(
- NKJPSentenceSampleStreamFactory.Parameters.class));
+ StreamFactoryRegistry.registerFactory(SentenceSample.class, "nkjp",
+ new NKJPSentenceSampleStreamFactory<>(NKJPSentenceSampleStreamFactory.Parameters.class));
}
- protected <P> NKJPSentenceSampleStreamFactory(Class<P> params) {
+ protected NKJPSentenceSampleStreamFactory(Class<P> params) {
super(params);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesNameSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesNameSampleStreamFactory.java
index 6ffba155..b552bdcf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesNameSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesNameSampleStreamFactory.java
@@ -29,7 +29,7 @@ import opennlp.tools.namefind.NameSample;
import opennlp.tools.util.ObjectStream;
public class OntoNotesNameSampleStreamFactory extends
- AbstractSampleStreamFactory<NameSample> {
+ AbstractSampleStreamFactory<NameSample, OntoNotesFormatParameters> {
public OntoNotesNameSampleStreamFactory() {
super(OntoNotesFormatParameters.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesPOSSampleStreamFactory.java
index e81cfcb3..d5b9125a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesPOSSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesPOSSampleStreamFactory.java
@@ -24,7 +24,8 @@ import opennlp.tools.parser.Parse;
import opennlp.tools.postag.POSSample;
import opennlp.tools.util.ObjectStream;
-public class OntoNotesPOSSampleStreamFactory extends AbstractSampleStreamFactory<POSSample> {
+public class OntoNotesPOSSampleStreamFactory
+ extends AbstractSampleStreamFactory<POSSample, OntoNotesFormatParameters> {
private OntoNotesParseSampleStreamFactory parseSampleStreamFactory =
new OntoNotesParseSampleStreamFactory();
diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesParseSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesParseSampleStreamFactory.java
index 4d4dc56a..ba94c716 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesParseSampleStreamFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ontonotes/OntoNotesParseSampleStreamFactory.java
@@ -28,7 +28,8 @@ import opennlp.tools.formats.convert.FileToStringSampleStream;
import opennlp.tools.parser.Parse;
import opennlp.tools.util.ObjectStream;
-public class OntoNotesParseSampleStreamFactory extends AbstractSampleStreamFactory<Parse> {
+public class OntoNotesParseSampleStreamFactory
+ extends AbstractSampleStreamFactory<Parse, OntoNotesFormatParameters> {
protected OntoNotesParseSampleStreamFactory() {
super(OntoNotesFormatParameters.class);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/langdetect/Language.java b/opennlp-tools/src/main/java/opennlp/tools/langdetect/Language.java
index 43ad71b2..05f40dcd 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/langdetect/Language.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/langdetect/Language.java
@@ -24,6 +24,8 @@ import java.util.Objects;
* Class for holding the document language and its confidence
*/
public class Language implements Serializable {
+
+ private static final long serialVersionUID = -2692630786925291644L;
private final String lang;
private final double confidence;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/langdetect/LanguageSample.java b/opennlp-tools/src/main/java/opennlp/tools/langdetect/LanguageSample.java
index 634718f5..041d5966 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/langdetect/LanguageSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/langdetect/LanguageSample.java
@@ -25,6 +25,7 @@ import java.util.Objects;
*/
public class LanguageSample implements Serializable {
+ private static final long serialVersionUID = -5206320996868984440L;
private final Language language;
private final CharSequence context;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java
index f5c24343..fea5f3b5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java
@@ -17,21 +17,24 @@
package opennlp.tools.lemmatizer;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import opennlp.tools.commons.Sample;
+
/**
* Represents an lemmatized sentence.
*/
-public class LemmaSample implements Serializable {
+public class LemmaSample implements Sample {
+
+ private static final long serialVersionUID = -7956607496164605337L;
- private List<String> tokens;
+ private final List<String> tokens;
- private List<String> tags;
+ private final List<String> tags;
private final List<String> lemmas;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java
index a4d5c8c0..48c5e3e5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java
@@ -25,7 +25,7 @@ import opennlp.tools.ml.model.Sequence;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.ObjectStream;
-public class LemmaSampleSequenceStream implements SequenceStream {
+public class LemmaSampleSequenceStream implements SequenceStream<LemmaSample> {
private final ObjectStream<LemmaSample> samples;
private final LemmatizerContextGenerator contextGenerator;
@@ -37,7 +37,7 @@ public class LemmaSampleSequenceStream implements SequenceStream {
}
@Override
- public Sequence read() throws IOException {
+ public Sequence<LemmaSample> read() throws IOException {
LemmaSample sample = samples.read();
if (sample != null) {
@@ -60,7 +60,7 @@ public class LemmaSampleSequenceStream implements SequenceStream {
}
@Override
- public Event[] updateContext(Sequence sequence, AbstractModel model) {
+ public Event[] updateContext(Sequence<LemmaSample> sequence, AbstractModel model) {
// TODO: Should be implemented for Perceptron sequence learning ...
return null;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerME.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerME.java
index 6dc35910..5b59b874 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerME.java
@@ -40,7 +40,7 @@ import opennlp.tools.util.StringUtil;
import opennlp.tools.util.TrainingParameters;
/**
- * A probabilistic lemmatizer. Tries to predict the induced permutation class
+ * A probabilistic {@link Lemmatizer}. Tries to predict the induced permutation class
* for each word depending on its surrounding context. Based on
* Grzegorz Chrupała. 2008. Towards a Machine-Learning Architecture
* for Lexical Functional Grammar Parsing. PhD dissertation, Dublin City University.
@@ -53,10 +53,10 @@ public class LemmatizerME implements Lemmatizer {
protected int beamSize;
private Sequence bestSequence;
- private SequenceClassificationModel<String> model;
+ private final SequenceClassificationModel<String> model;
- private LemmatizerContextGenerator contextGenerator;
- private SequenceValidator<String> sequenceValidator;
+ private final LemmatizerContextGenerator contextGenerator;
+ private final SequenceValidator<String> sequenceValidator;
/**
* Initializes the current instance with the provided model
@@ -226,7 +226,7 @@ public class LemmatizerME implements Lemmatizer {
lemmatizerModel = trainer.train(ss);
}
else if (TrainerType.SEQUENCE_TRAINER.equals(trainerType)) {
- SequenceTrainer trainer = TrainerFactory.getSequenceModelTrainer(
+ SequenceTrainer<LemmaSample> trainer = TrainerFactory.getSequenceModelTrainer(
trainParams, manifestInfoEntries);
// TODO: This will probably cause issue, since the feature generator uses the outcomes array
diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
index cb11e8b4..a4f7c556 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerModel.java
@@ -41,6 +41,7 @@ import opennlp.tools.util.model.BaseModel;
*/
public class LemmatizerModel extends BaseModel {
+ private static final long serialVersionUID = -3362902631186156673L;
private static final String COMPONENT_NAME = "StatisticalLemmatizer";
private static final String LEMMATIZER_MODEL_ENTRY_NAME = "lemmatizer.model";
@@ -110,7 +111,7 @@ public class LemmatizerModel extends BaseModel {
return new BeamSearch<>(beamSize, (MaxentModel) artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME));
}
else if (artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME) instanceof SequenceClassificationModel) {
- return (SequenceClassificationModel) artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME);
+ return (SequenceClassificationModel<String>) artifactMap.get(LEMMATIZER_MODEL_ENTRY_NAME);
}
else {
return null;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractSequenceTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractSequenceTrainer.java
deleted file mode 100644
index 19ecc4b7..00000000
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractSequenceTrainer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package opennlp.tools.ml;
-
-import java.io.IOException;
-
-import opennlp.tools.ml.model.SequenceClassificationModel;
-import opennlp.tools.ml.model.SequenceStream;
-
-public abstract class AbstractSequenceTrainer extends AbstractTrainer implements
- SequenceTrainer {
-
- public AbstractSequenceTrainer() {
- }
-
- public abstract SequenceClassificationModel<String> doTrain(SequenceStream events)
- throws IOException;
-
- public final SequenceClassificationModel<String> train(SequenceStream events) throws IOException {
- validate();
-
- SequenceClassificationModel<String> model = doTrain(events);
- addToReport(AbstractTrainer.TRAINER_TYPE_PARAM, SequenceTrainer.SEQUENCE_VALUE);
- return model;
- }
-
-}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractTrainer.java
index 32c5df68..c3aad2a6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/AbstractTrainer.java
@@ -56,9 +56,8 @@ public abstract class AbstractTrainer {
this.reportMap = reportMap;
printMessages = trainingParameters.getBooleanParameter(VERBOSE_PARAM, VERBOSE_DEFAULT);
}
-
- @Deprecated
- public void init(Map<String, String> trainParams, Map<String, String> reportMap) {
+
+ public void init(Map<String, Object> trainParams, Map<String, String> reportMap) {
init(new TrainingParameters(trainParams),reportMap);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/EventModelSequenceTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/EventModelSequenceTrainer.java
index 676490c0..a6f07dee 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/EventModelSequenceTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/EventModelSequenceTrainer.java
@@ -20,18 +20,19 @@ package opennlp.tools.ml;
import java.io.IOException;
import java.util.Map;
+import opennlp.tools.commons.Sample;
+import opennlp.tools.commons.Trainer;
import opennlp.tools.ml.model.MaxentModel;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.TrainingParameters;
-public interface EventModelSequenceTrainer {
+public interface EventModelSequenceTrainer extends Trainer {
String SEQUENCE_VALUE = "EventModelSequence";
- @Deprecated
- void init(Map<String, String> trainParams, Map<String, String> reportMap);
+ void init(Map<String, Object> trainParams, Map<String, String> reportMap);
void init(TrainingParameters trainParams, Map<String, String> reportMap);
- MaxentModel train(SequenceStream events) throws IOException;
+ MaxentModel train(SequenceStream<? extends Sample> events) throws IOException;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/EventTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/EventTrainer.java
index 2a98b864..2cb15ff2 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/EventTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/EventTrainer.java
@@ -20,18 +20,18 @@ package opennlp.tools.ml;
import java.io.IOException;
import java.util.Map;
+import opennlp.tools.commons.Trainer;
import opennlp.tools.ml.model.DataIndexer;
import opennlp.tools.ml.model.Event;
import opennlp.tools.ml.model.MaxentModel;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.TrainingParameters;
-public interface EventTrainer {
+public interface EventTrainer extends Trainer {
String EVENT_VALUE = "Event";
- @Deprecated
- void init(Map<String, String> trainParams, Map<String, String> reportMap);
+ void init(Map<String, Object> trainParams, Map<String, String> reportMap);
void init(TrainingParameters trainingParams, Map<String, String> reportMap);
MaxentModel train(ObjectStream<Event> events) throws IOException;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/SequenceTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/SequenceTrainer.java
index 3eedea49..263682a0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/SequenceTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/SequenceTrainer.java
@@ -20,11 +20,12 @@ package opennlp.tools.ml;
import java.io.IOException;
import java.util.Map;
+import opennlp.tools.commons.Trainer;
import opennlp.tools.ml.model.SequenceClassificationModel;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.TrainingParameters;
-public interface SequenceTrainer {
+public interface SequenceTrainer<T> extends Trainer {
String SEQUENCE_VALUE = "Sequence";
@@ -32,5 +33,5 @@ public interface SequenceTrainer {
void init(Map<String, String> trainParams, Map<String, String> reportMap);
void init(TrainingParameters trainParams, Map<String, String> reportMap);
- SequenceClassificationModel<String> train(SequenceStream events) throws IOException;
+ SequenceClassificationModel<String> train(SequenceStream<T> events) throws IOException;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
index 302035b6..a7604cb4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java
@@ -18,10 +18,10 @@
package opennlp.tools.ml;
import java.lang.reflect.Constructor;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
+import opennlp.tools.commons.Sample;
+import opennlp.tools.commons.Trainer;
import opennlp.tools.ml.maxent.GISTrainer;
import opennlp.tools.ml.maxent.quasinewton.QNTrainer;
import opennlp.tools.ml.naivebayes.NaiveBayesTrainer;
@@ -43,15 +43,12 @@ public class TrainerFactory {
private static final Map<String, Class> BUILTIN_TRAINERS;
static {
- Map<String, Class> _trainers = new HashMap<>();
- _trainers.put(GISTrainer.MAXENT_VALUE, GISTrainer.class);
- _trainers.put(QNTrainer.MAXENT_QN_VALUE, QNTrainer.class);
- _trainers.put(PerceptronTrainer.PERCEPTRON_VALUE, PerceptronTrainer.class);
- _trainers.put(SimplePerceptronSequenceTrainer.PERCEPTRON_SEQUENCE_VALUE,
- SimplePerceptronSequenceTrainer.class);
- _trainers.put(NaiveBayesTrainer.NAIVE_BAYES_VALUE, NaiveBayesTrainer.class);
-
- BUILTIN_TRAINERS = Collections.unmodifiableMap(_trainers);
+ BUILTIN_TRAINERS = Map.of(
+ GISTrainer.MAXENT_VALUE, GISTrainer.class,
+ QNTrainer.MAXENT_QN_VALUE, QNTrainer.class,
+ PerceptronTrainer.PERCEPTRON_VALUE, PerceptronTrainer.class,
+ SimplePerceptronSequenceTrainer.PERCEPTRON_SEQUENCE_VALUE, SimplePerceptronSequenceTrainer.class,
+ NaiveBayesTrainer.NAIVE_BAYES_VALUE, NaiveBayesTrainer.class);
}
/**
@@ -69,7 +66,7 @@ public class TrainerFactory {
return TrainerType.EVENT_MODEL_TRAINER;
}
- Class<?> trainerClass = BUILTIN_TRAINERS.get(algorithmValue);
+ Class<? extends Trainer> trainerClass = BUILTIN_TRAINERS.get(algorithmValue);
if (trainerClass != null) {
@@ -119,12 +116,12 @@ public class TrainerFactory {
if (trainerType != null) {
if (BUILTIN_TRAINERS.containsKey(trainerType)) {
- SequenceTrainer trainer = TrainerFactory.<SequenceTrainer>createBuiltinTrainer(
- BUILTIN_TRAINERS.get(trainerType));
+ SequenceTrainer<? extends Sample> trainer = TrainerFactory.
+ <SequenceTrainer>createBuiltinTrainer(BUILTIN_TRAINERS.get(trainerType));
trainer.init(trainParams, reportMap);
return trainer;
} else {
- SequenceTrainer trainer =
+ SequenceTrainer<? extends Sample> trainer =
ExtensionLoader.instantiateExtension(SequenceTrainer.class, trainerType);
trainer.init(trainParams, reportMap);
return trainer;
@@ -141,8 +138,8 @@ public class TrainerFactory {
if (trainerType != null) {
if (BUILTIN_TRAINERS.containsKey(trainerType)) {
- EventModelSequenceTrainer trainer = TrainerFactory.<EventModelSequenceTrainer>createBuiltinTrainer(
- BUILTIN_TRAINERS.get(trainerType));
+ EventModelSequenceTrainer trainer = TrainerFactory.
+ <EventModelSequenceTrainer>createBuiltinTrainer(BUILTIN_TRAINERS.get(trainerType));
trainer.init(trainParams, reportMap);
return trainer;
} else {
@@ -165,8 +162,8 @@ public class TrainerFactory {
trainParams.getStringParameter(AbstractTrainer.ALGORITHM_PARAM, GISTrainer.MAXENT_VALUE);
if (BUILTIN_TRAINERS.containsKey(trainerType)) {
- EventTrainer trainer = TrainerFactory.<EventTrainer>createBuiltinTrainer(
- BUILTIN_TRAINERS.get(trainerType));
+ EventTrainer trainer = TrainerFactory.
+ <EventTrainer>createBuiltinTrainer(BUILTIN_TRAINERS.get(trainerType));
trainer.init(trainParams, reportMap);
return trainer;
} else {
@@ -205,7 +202,7 @@ public class TrainerFactory {
return true;
}
- private static <T> T createBuiltinTrainer(Class<T> trainerClass) {
+ private static <T extends Trainer> T createBuiltinTrainer(Class<T> trainerClass) {
T theTrainer = null;
if (trainerClass != null) {
try {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
index 8faa1931..59ac3a45 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/QNTrainer.java
@@ -109,10 +109,9 @@ public class QNTrainer extends AbstractEventTrainer {
this.l1Cost = trainingParameters.getDoubleParameter(L1COST_PARAM, L1COST_DEFAULT);
this.l2Cost = trainingParameters.getDoubleParameter(L2COST_PARAM, L2COST_DEFAULT);
}
-
+
@Override
- @Deprecated
- public void init(Map<String, String> trainParams, Map<String, String> reportMap) {
+ public void init(Map<String, Object> trainParams, Map<String, String> reportMap) {
init(new TrainingParameters(trainParams),reportMap);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java
index b56e276a..31793c73 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java
@@ -20,16 +20,16 @@ package opennlp.tools.ml.model;
import opennlp.tools.util.ObjectStream;
/**
- * Interface for streams of sequences used to train sequence models.
+ * Interface for streams of {@link Sequence sequences} used to train sequence models.
*/
-public interface SequenceStream extends ObjectStream<Sequence> {
+public interface SequenceStream<S> extends ObjectStream<Sequence<S>> {
/**
* Creates a new event array based on the outcomes predicted by the specified parameters
- * for the specified sequence.
+ * for the specified {@link Sequence}.
* @param sequence The sequence to be evaluated.
- * @return event array
+ * @return {@link Event} array
*/
- Event[] updateContext(Sequence sequence, AbstractModel model);
+ Event[] updateContext(Sequence<S> sequence, AbstractModel model);
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStreamEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStreamEventStream.java
index f402eb9a..0ee4fdf3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStreamEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStreamEventStream.java
@@ -25,15 +25,15 @@ import java.util.Iterator;
import opennlp.tools.util.ObjectStream;
/**
- * Class which turns a sequence stream into an event stream.
+ * Class which turns a {@link SequenceStream} into an event stream.
*/
public class SequenceStreamEventStream implements ObjectStream<Event> {
- private final SequenceStream sequenceStream;
+ private final SequenceStream<Event> sequenceStream;
private Iterator<Event> eventIt = Collections.emptyListIterator();
- public SequenceStreamEventStream(SequenceStream sequenceStream) {
+ public SequenceStreamEventStream(SequenceStream<Event> sequenceStream) {
this.sequenceStream = sequenceStream;
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SimplePerceptronSequenceTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SimplePerceptronSequenceTrainer.java
index 6b94b708..f168553f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SimplePerceptronSequenceTrainer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SimplePerceptronSequenceTrainer.java
@@ -48,7 +48,7 @@ public class SimplePerceptronSequenceTrainer extends AbstractEventModelSequenceT
public static final String PERCEPTRON_SEQUENCE_VALUE = "PERCEPTRON_SEQUENCE";
private int iterations;
- private SequenceStream sequenceStream;
+ private SequenceStream<Event> sequenceStream;
/** Number of events in the event set. */
private int numEvents;
@@ -118,7 +118,7 @@ public class SimplePerceptronSequenceTrainer extends AbstractEventModelSequenceT
// << members related to AbstractSequenceTrainer
- public AbstractModel trainModel(int iterations, SequenceStream sequenceStream,
+ public AbstractModel trainModel(int iterations, SequenceStream<Event> sequenceStream,
int cutoff, boolean useAverage) throws IOException {
this.iterations = iterations;
this.sequenceStream = sequenceStream;
@@ -185,7 +185,6 @@ public class SimplePerceptronSequenceTrainer extends AbstractEventModelSequenceT
if (useAverage) averageParams[pi].setParameter(aoi, 0.0);
}
}
- double[] modelDistribution = new double[numOutcomes];
display("Computing model parameters...\n");
findParameters(iterations);
@@ -234,7 +233,7 @@ public class SimplePerceptronSequenceTrainer extends AbstractEventModelSequenceT
sequenceStream.reset();
- Sequence sequence;
+ Sequence<Event> sequence;
while ((sequence = sequenceStream.read()) != null) {
Event[] taggerEvents = sequenceStream.updateContext(sequence, model);
Event[] events = sequence.getEvents();
@@ -356,7 +355,7 @@ public class SimplePerceptronSequenceTrainer extends AbstractEventModelSequenceT
sequenceStream.reset();
- Sequence sequence;
+ Sequence<Event> sequence;
while ((sequence = sequenceStream.read()) != null) {
Event[] taggerEvents = sequenceStream.updateContext(sequence,
new PerceptronModel(params,predLabels,outcomeLabels));
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java
index e89e155b..11f1b908 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java
@@ -69,10 +69,6 @@ public class NameFinderEventStream extends opennlp.tools.util.AbstractEventStrea
this.defaultType = type;
}
- public NameFinderEventStream(ObjectStream<NameSample> dataStream) {
- this(dataStream, null, new DefaultNameContextGenerator(), null);
- }
-
/**
* Generates the name tag outcomes (start, continue, other) for each token in a sentence
* with the specified length using the specified name spans.
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java
index 7a3b98a0..9417d6f0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java
@@ -251,7 +251,7 @@ public class NameFinderME implements TokenNameFinder {
trainParams, manifestInfoEntries);
nameFinderModel = trainer.train(ss);
} else if (TrainerType.SEQUENCE_TRAINER.equals(trainerType)) {
- SequenceTrainer trainer = TrainerFactory.getSequenceModelTrainer(
+ SequenceTrainer<NameSample> trainer = TrainerFactory.getSequenceModelTrainer(
trainParams, manifestInfoEntries);
NameSampleSequenceStream ss =
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java
index e90c6631..1954073f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java
@@ -18,7 +18,6 @@
package opennlp.tools.namefind;
import java.io.IOException;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -27,14 +26,16 @@ import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import opennlp.tools.commons.Sample;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import opennlp.tools.util.Span;
/**
* Class for holding names for a single unit of text.
*/
-public class NameSample implements Serializable {
+public class NameSample implements Sample {
+ private static final long serialVersionUID = 1655333056555270688L;
private final String id;
private final List<String> sentence;
private final List<Span> names;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java
index 8064d6b2..d1a17873 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java
@@ -28,12 +28,12 @@ import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.SequenceCodec;
import opennlp.tools.util.featuregen.AdaptiveFeatureGenerator;
-public class NameSampleSequenceStream implements SequenceStream {
+public class NameSampleSequenceStream implements SequenceStream<NameSample> {
- private NameContextGenerator pcg;
+ private final NameContextGenerator pcg;
private final boolean useOutcomes;
- private ObjectStream<NameSample> psi;
- private SequenceCodec<String> seqCodec;
+ private final ObjectStream<NameSample> psi;
+ private final SequenceCodec<String> seqCodec;
public NameSampleSequenceStream(ObjectStream<NameSample> psi) throws IOException {
this(psi, new DefaultNameContextGenerator((AdaptiveFeatureGenerator) null), true);
@@ -69,11 +69,10 @@ public class NameSampleSequenceStream implements SequenceStream {
this.seqCodec = seqCodec;
}
- @SuppressWarnings("unchecked")
- public Event[] updateContext(Sequence sequence, AbstractModel model) {
+ public Event[] updateContext(Sequence<NameSample> sequence, AbstractModel model) {
TokenNameFinder tagger = new NameFinderME(new TokenNameFinderModel(
"x-unspecified", model, Collections.emptyMap(), null));
- String[] sentence = ((Sequence<NameSample>) sequence).getSource().getSentence();
+ String[] sentence = sequence.getSource().getSentence();
String[] tags = seqCodec.encode(tagger.find(sentence), sentence.length);
Event[] events = new Event[sentence.length];
@@ -83,7 +82,7 @@ public class NameSampleSequenceStream implements SequenceStream {
}
@Override
- public Sequence read() throws IOException {
+ public Sequence<NameSample> read() throws IOException {
NameSample sample = psi.read();
if (sample != null) {
String[] sentence = sample.getSentence();
diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
index 98dad067..9ad79420 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java
@@ -194,7 +194,7 @@ public class TokenNameFinderModel extends BaseModel {
* is 'wordcluster', which is the key used to add the serializer to the map.
* @return the map containing the added serializers
*/
- public static Map<String, ArtifactSerializer> createArtifactSerializers() {
+ public static Map<String, ArtifactSerializer<?>> createArtifactSerializers() {
// TODO: Not so nice, because code cannot really be reused by the other create serializer method
// Has to be redesigned, we need static access to default serializers
@@ -203,7 +203,7 @@ public class TokenNameFinderModel extends BaseModel {
// The XML feature generator factory should provide these mappings.
// Usually the feature generators should know what type of resource they expect.
- Map<String, ArtifactSerializer> serializers = BaseModel.createArtifactSerializers();
+ Map<String, ArtifactSerializer<?>> serializers = BaseModel.createArtifactSerializers();
serializers.put("featuregen", new ByteArraySerializer());
serializers.put("wordcluster", new WordClusterDictionary.WordClusterDictionarySerializer());
diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
index 90d51c1d..cc358dd1 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
@@ -77,22 +77,6 @@ public class POSDictionary implements Iterable<String>, MutableTagDictionary, Se
}
}
- /**
- * Associates the specified tags with the specified word. If the dictionary
- * previously contained the word, the old tags are replaced by the specified
- * ones.
- *
- * @param word
- * The word to be added to the dictionary.
- * @param tags
- * The set of tags associated with the specified word.
- *
- * @deprecated Use {@link #put(String, String[])} instead
- */
- void addTags(String word, String... tags) {
- put(word, tags);
- }
-
/**
* Retrieves an iterator over all words in the dictionary.
*/
diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
index d55921c6..030e1d9f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
@@ -46,6 +46,7 @@ import opennlp.tools.util.model.SerializableArtifact;
*/
public final class POSModel extends BaseModel implements SerializableArtifact {
+ private static final long serialVersionUID = -6014331858195322339L;
private static final String COMPONENT_NAME = "POSTaggerME";
static final String POS_MODEL_ENTRY_NAME = "pos.model";
static final String GENERATOR_DESCRIPTOR_ENTRY_NAME = "generator.featuregen";
diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSSample.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSSample.java
index 0bc9f410..d6c40fdf 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSSample.java
@@ -15,26 +15,25 @@
* limitations under the License.
*/
-
package opennlp.tools.postag;
-import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
+import opennlp.tools.commons.Sample;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import opennlp.tools.util.InvalidFormatException;
/**
* Represents an pos-tagged sentence.
*/
-public class POSSample implements Serializable {
-
- private List<String> sentence;
+public class POSSample implements Sample {
- private List<String> tags;
+ private static final long serialVersionUID = -5782784526335651421L;
+ private final List<String> sentence;
+ private final List<String> tags;
private final String[][] additionalContext;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSSampleSequenceStream.java
index 9942d67b..c69cf6e9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSSampleSequenceStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSSampleSequenceStream.java
@@ -25,7 +25,7 @@ import opennlp.tools.ml.model.Sequence;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.ObjectStream;
-public class POSSampleSequenceStream implements SequenceStream {
+public class POSSampleSequenceStream implements SequenceStream<POSSample> {
private POSContextGenerator pcg;
private ObjectStream<POSSample> psi;
@@ -40,21 +40,18 @@ public class POSSampleSequenceStream implements SequenceStream {
this.pcg = pcg;
}
- @SuppressWarnings("unchecked")
- public Event[] updateContext(Sequence sequence, AbstractModel model) {
- Sequence<POSSample> pss = sequence;
+ public Event[] updateContext(Sequence<POSSample> pss, AbstractModel model) {
POSTagger tagger = new POSTaggerME(new POSModel("x-unspecified", model, null, new POSTaggerFactory()));
String[] sentence = pss.getSource().getSentence();
Object[] ac = pss.getSource().getAddictionalContext();
String[] tags = tagger.tag(pss.getSource().getSentence());
Event[] events = new Event[sentence.length];
- POSSampleEventStream.generateEvents(sentence, tags, ac, pcg)
- .toArray(events);
+ POSSampleEventStream.generateEvents(sentence, tags, ac, pcg).toArray(events);
return events;
}
@Override
- public Sequence read() throws IOException {
+ public Sequence<POSSample> read() throws IOException {
POSSample sample = psi.read();
@@ -71,8 +68,7 @@ public class POSSampleSequenceStream implements SequenceStream {
events[i] = new Event(tags[i], context);
}
- Sequence<POSSample> sequence = new Sequence<POSSample>(events,sample);
- return sequence;
+ return new Sequence<>(events,sample);
}
return null;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
index e8df1d6e..8caff463 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
@@ -40,8 +40,8 @@ import opennlp.tools.util.model.ModelUtil;
*/
public class SentenceModel extends BaseModel {
+ private static final long serialVersionUID = -3921848998444722554L;
private static final String COMPONENT_NAME = "SentenceDetectorME";
-
private static final String MAXENT_MODEL_ENTRY_NAME = "sent.model";
public SentenceModel(String languageCode, MaxentModel sentModel,
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
index 3ffe0842..100f807e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
@@ -33,6 +33,7 @@ import opennlp.tools.util.Span;
*/
public class SentenceSample implements Serializable {
+ private static final long serialVersionUID = -5386940708608341113L;
private final String document;
private final List<Span> sentences;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
index 97f6311e..b4e374ce 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
@@ -32,6 +32,7 @@ import opennlp.tools.util.Span;
*/
public class TokenSample implements Serializable {
+ private static final long serialVersionUID = 1057011880085907705L;
public static final String DEFAULT_SEPARATOR_CHARS = "<SPLIT>";
private static final String separatorChars = DEFAULT_SEPARATOR_CHARS;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
index 1db7c499..8e732991 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerModel.java
@@ -41,8 +41,8 @@ import opennlp.tools.util.model.ModelUtil;
*/
public final class TokenizerModel extends BaseModel {
+ private static final long serialVersionUID = 42334333400920419L;
private static final String COMPONENT_NAME = "TokenizerME";
-
private static final String TOKENIZER_MODEL_ENTRY = "token.model";
/**
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
index 6c994da0..130bf079 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/BaseToolFactory.java
@@ -31,7 +31,7 @@ import opennlp.tools.util.model.ArtifactSerializer;
* <ul>
* <li>implement an empty constructor (TODO is it necessary?)
* <li>implement a constructor that takes the {@link ArtifactProvider} and
- * calls {@code BaseToolFactory(Map)}
+ * calls {@link BaseToolFactory(Map)}
* <li>override {@link #createArtifactMap()} and
* {@link #createArtifactSerializersMap()} methods if necessary.
* </ul>
@@ -88,14 +88,13 @@ public abstract class BaseToolFactory {
}
/**
- * Validates the parsed artifacts. If something is not
- * valid subclasses should throw an {@link InvalidFormatException}.
- *
+ * Validates the parsed artifacts.
+ * <p>
* Note:
- * Subclasses should generally invoke super.validateArtifactMap at the beginning
+ * Subclasses should generally invoke {@code super.validateArtifactMap} at the beginning
* of this method.
*
- * @throws InvalidFormatException
+ * @throws InvalidFormatException Thrown If something is not valid.
*/
public abstract void validateArtifactMap() throws InvalidFormatException;
@@ -123,7 +122,7 @@ public abstract class BaseToolFactory {
BaseToolFactory theFactory = null;
if (factoryClass != null) {
try {
- theFactory = factoryClass.newInstance();
+ theFactory = factoryClass.getDeclaredConstructor().newInstance();
theFactory.init(artifactProvider);
} catch (Exception e) {
String msg = "Could not instantiate the "
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Cache.java b/opennlp-tools/src/main/java/opennlp/tools/util/Cache.java
index fb4d6cbe..0de30c29 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Cache.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Cache.java
@@ -25,7 +25,9 @@ import java.util.Map;
*/
public class Cache<K,V> extends LinkedHashMap<K,V> {
- private int capacity;
+ private static final long serialVersionUID = 3037039043085908062L;
+
+ private final int capacity;
public Cache(final int capacity) {
this.capacity = capacity;
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/DownloadUtil.java b/opennlp-tools/src/main/java/opennlp/tools/util/DownloadUtil.java
index 19697892..9880ea73 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/DownloadUtil.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/DownloadUtil.java
@@ -110,7 +110,7 @@ public class DownloadUtil {
}
- public static BaseModel downloadModel(String language, ModelType modelType, Class type)
+ public static BaseModel downloadModel(String language, ModelType modelType, Class<?> type)
throws IOException {
if (available_models.containsKey(language)) {
@@ -133,7 +133,7 @@ public class DownloadUtil {
* @return A {@link TokenNameFinderModel}.
* @throws IOException Thrown if the model cannot be downloaded.
*/
- public static BaseModel downloadModel(URL url, Class type) throws IOException {
+ public static BaseModel downloadModel(URL url, Class<?> type) throws IOException {
final Path homeDirectory = Paths.get(System.getProperty("user.home") + "/.opennlp/");
if (!Files.isDirectory(homeDirectory)) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
index 4576f03b..e1f32b62 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Span.java
@@ -26,6 +26,7 @@ import java.util.Objects;
*/
public class Span implements Comparable<Span>, Serializable {
+ private static final long serialVersionUID = -7648780019844573507L;
private final int start;
private final int end;
private final double prob;//default is 0
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
index f9048424..82640cfc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java
@@ -42,7 +42,7 @@ public class TrainingParameters {
public static final int ITERATIONS_DEFAULT_VALUE = 100;
public static final int CUTOFF_DEFAULT_VALUE = 5;
- private Map<String, Object> parameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
+ private final Map<String, Object> parameters = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
public TrainingParameters() {
}
@@ -51,43 +51,9 @@ public class TrainingParameters {
this.parameters.putAll(trainingParameters.parameters);
}
- /**
- *
- * @deprecated
- */
- public TrainingParameters(Map<String,String> map) {
- //parameters.putAll(map);
- // try to respect their original type...
- for (String key: map.keySet()) {
- String value = map.get(key);
- try {
- int intValue = Integer.parseInt(value);
- parameters.put(key, intValue);
- }
- catch (NumberFormatException ei) {
- try {
- double doubleValue = Double.parseDouble(value);
- parameters.put(key, doubleValue);
- }
- catch (NumberFormatException ed) {
- // Because Boolean.parseBoolean() doesn't throw NFE, it just checks the value is either
- // true or yes. So let's see their letters here.
- if (value.toLowerCase().equals("true") || value.toLowerCase().equals("false")) {
- parameters.put(key, Boolean.parseBoolean(value));
- }
- else {
- parameters.put(key, value);
- }
- }
- }
- }
- }
-
- /* TODO: Once we throw Map<String,String> away, have this constructor to be uncommented
public TrainingParameters(Map<String,Object> map) {
parameters.putAll(map);
}
- */
public TrainingParameters(InputStream in) throws IOException {
@@ -117,38 +83,6 @@ public class TrainingParameters {
return (String)parameters.get(ALGORITHM_PARAM);
}
- /**
- * Retrieves a map with the training parameters which have the passed name space.
- *
- * @param namespace
- *
- * @return a parameter map which can be passed to the train and validate methods.
- *
- * @deprecated use {@link #getObjectSettings(String)} instead
- */
- public Map<String, String> getSettings(String namespace) {
-
- Map<String, String> trainingParams = new HashMap<>();
- String prefix = namespace + ".";
-
- for (Map.Entry<String, Object> entry : parameters.entrySet()) {
- String key = entry.getKey();
-
- if (namespace != null) {
- if (key.startsWith(prefix)) {
- trainingParams.put(key.substring(prefix.length()), getStringValue(entry.getValue()));
- }
- }
- else {
- if (!key.contains(".")) {
- trainingParams.put(key, getStringValue(entry.getValue()));
- }
- }
- }
-
- return Collections.unmodifiableMap(trainingParams);
- }
-
private static String getStringValue(Object value) {
if (value instanceof Integer) {
return Integer.toString((Integer)value);
@@ -164,17 +98,6 @@ public class TrainingParameters {
}
}
- /**
- * Retrieves all parameters without a name space.
- *
- * @return the settings map
- *
- * @deprecated use {@link #getObjectSettings()} instead
- */
- public Map<String, String> getSettings() {
- return getSettings(null);
- }
-
/**
* Retrieves a map with the training parameters which have the passed name space.
*
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
index 71b5822d..fa030a31 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
@@ -406,7 +406,7 @@ public class GeneratorFactory {
}
// TODO: (OPENNLP-1174) just remove when back-compat is no longer needed
- private static Map<String, XmlFeatureGeneratorFactory> factories = new HashMap<>();
+ private final static Map<String, XmlFeatureGeneratorFactory> factories = new HashMap<>();
// TODO: (OPENNLP-1174) just remove when back-compat is no longer needed
static {
@@ -621,9 +621,9 @@ public class GeneratorFactory {
String className = element.getAttribute("class");
if (className != null) {
try {
- Class factoryClass = Class.forName(className);
+ Class<?> factoryClass = Class.forName(className);
try {
- Constructor constructor = factoryClass.getConstructor();
+ Constructor<?> constructor = factoryClass.getConstructor();
AbstractXmlFeatureGeneratorFactory factory =
(AbstractXmlFeatureGeneratorFactory)constructor.newInstance();
factory.init(element, null);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
index ac88bb72..e8f7b415 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
@@ -66,7 +66,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
public static final String TRAINING_ITERATIONS_PROPERTY = "Training-Iterations";
public static final String TRAINING_EVENTHASH_PROPERTY = "Training-Eventhash";
- private static String SERIALIZER_CLASS_NAME_PREFIX = "serializer-class-";
+ private static final String SERIALIZER_CLASS_NAME_PREFIX = "serializer-class-";
private Map<String, ArtifactSerializer> artifactSerializers = new HashMap<>();
@@ -348,8 +348,8 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
}
}
- protected static Map<String, ArtifactSerializer> createArtifactSerializers() {
- Map<String, ArtifactSerializer> serializers = new HashMap<>();
+ protected static Map<String, ArtifactSerializer<?>> createArtifactSerializers() {
+ Map<String, ArtifactSerializer<?>> serializers = new HashMap<>();
GenericModelSerializer.register(serializers);
PropertiesSerializer.register(serializers);
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/DictionarySerializer.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/DictionarySerializer.java
index a3231223..a4bdecd6 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/DictionarySerializer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/DictionarySerializer.java
@@ -34,7 +34,7 @@ public class DictionarySerializer implements ArtifactSerializer<Dictionary> {
dictionary.serialize(out);
}
- static void register(Map<String, ArtifactSerializer> factories) {
+ static void register(Map<String, ArtifactSerializer<?>> factories) {
factories.put("dictionary", new DictionarySerializer());
}
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/GenericModelSerializer.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/GenericModelSerializer.java
index 516bef3c..08f18030 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/GenericModelSerializer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/GenericModelSerializer.java
@@ -36,7 +36,7 @@ public class GenericModelSerializer implements ArtifactSerializer<AbstractModel>
ModelUtil.writeModel(artifact, out);
}
- public static void register(Map<String, ArtifactSerializer> factories) {
+ public static void register(Map<String, ArtifactSerializer<?>> factories) {
factories.put("model", new GenericModelSerializer());
}
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/PropertiesSerializer.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/PropertiesSerializer.java
index adef53c8..def012ad 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/PropertiesSerializer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/PropertiesSerializer.java
@@ -36,7 +36,7 @@ class PropertiesSerializer implements ArtifactSerializer<Properties> {
properties.store(out, "");
}
- static void register(Map<String, ArtifactSerializer> factories) {
+ static void register(Map<String, ArtifactSerializer<?>> factories) {
factories.put("properties", new PropertiesSerializer());
}
}
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/AggregateCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/AggregateCharSequenceNormalizer.java
index 771be199..34ae13b8 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/AggregateCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/AggregateCharSequenceNormalizer.java
@@ -20,6 +20,7 @@ package opennlp.tools.util.normalizer;
public class AggregateCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = 5514902020184083235L;
private final CharSequenceNormalizer[] normalizers;
public AggregateCharSequenceNormalizer(CharSequenceNormalizer ... normalizers) {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/EmojiCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/EmojiCharSequenceNormalizer.java
index c7e66e37..a3d7b094 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/EmojiCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/EmojiCharSequenceNormalizer.java
@@ -23,6 +23,8 @@ import java.util.regex.Pattern;
*/
public class EmojiCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = 4553401197981667914L;
+
private static final EmojiCharSequenceNormalizer INSTANCE = new EmojiCharSequenceNormalizer();
public static EmojiCharSequenceNormalizer getInstance() {
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/NumberCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/NumberCharSequenceNormalizer.java
index 5fe0f629..531f0cb7 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/NumberCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/NumberCharSequenceNormalizer.java
@@ -23,6 +23,8 @@ import java.util.regex.Pattern;
*/
public class NumberCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = -782056416383201122L;
+
private static final Pattern NUMBER_REGEX = Pattern.compile("\\d+");
private static final NumberCharSequenceNormalizer INSTANCE = new NumberCharSequenceNormalizer();
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/ShrinkCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/ShrinkCharSequenceNormalizer.java
index cc1c15e1..792aed6b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/ShrinkCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/ShrinkCharSequenceNormalizer.java
@@ -23,6 +23,8 @@ import java.util.regex.Pattern;
*/
public class ShrinkCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = -4511969661556543048L;
+
private static final Pattern REPEATED_CHAR_REGEX = Pattern.compile("(.)\\1{2,}",
Pattern.CASE_INSENSITIVE);
private static final Pattern SPACE_REGEX = Pattern.compile("\\s{2,}",
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/TwitterCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/TwitterCharSequenceNormalizer.java
index 69c70687..e3a0a933 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/TwitterCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/TwitterCharSequenceNormalizer.java
@@ -23,6 +23,8 @@ import java.util.regex.Pattern;
*/
public class TwitterCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = -8155452559337913929L;
+
private static final Pattern HASH_USER_REGEX =
Pattern.compile("[#@]\\S+");
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/UrlCharSequenceNormalizer.java b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/UrlCharSequenceNormalizer.java
index 188e3892..8efbde00 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/UrlCharSequenceNormalizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/normalizer/UrlCharSequenceNormalizer.java
@@ -23,6 +23,7 @@ import java.util.regex.Pattern;
*/
public class UrlCharSequenceNormalizer implements CharSequenceNormalizer {
+ private static final long serialVersionUID = 2023145028634552389L;
private static final Pattern URL_REGEX =
Pattern.compile("https?://[-_.?&~;+=/#0-9A-Za-z]+");
private static final Pattern MAIL_REGEX =
diff --git a/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java b/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
index f09cd95d..8b0f73e8 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/cmdline/CLITest.java
@@ -27,6 +27,9 @@ import org.junit.jupiter.api.Test;
public class CLITest {
private static class ExitException extends SecurityException {
+
+ private static final long serialVersionUID = 6144359372794123631L;
+
private final int status;
public ExitException(int status) {
diff --git a/opennlp-tools/src/test/java/opennlp/tools/convert/FileToStringSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/convert/FileToStringSampleStreamTest.java
index b274be94..a8d1c2d6 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/convert/FileToStringSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/convert/FileToStringSampleStreamTest.java
@@ -20,6 +20,7 @@ package opennlp.tools.convert;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
@@ -49,10 +50,10 @@ public class FileToStringSampleStreamTest {
new DirectorySampleStream(directory.toFile(), null, false);
File tempFile1 = directory.resolve("tempFile1").toFile();
- FileUtils.writeStringToFile(tempFile1, sentence1);
+ FileUtils.writeStringToFile(tempFile1, sentence1, StandardCharsets.UTF_8);
File tempFile2 = directory.resolve("tempFile2").toFile();
- FileUtils.writeStringToFile(tempFile2, sentence2);
+ FileUtils.writeStringToFile(tempFile2, sentence2, StandardCharsets.UTF_8);
try (FileToStringSampleStream stream =
new FileToStringSampleStream(directorySampleStream, Charset.defaultCharset())) {
diff --git a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADTokenSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADTokenSampleStreamTest.java
index e37dc26d..309bd1eb 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADTokenSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/formats/ad/ADTokenSampleStreamTest.java
@@ -33,7 +33,7 @@ import opennlp.tools.util.ObjectStream;
public class ADTokenSampleStreamTest {
- private List<TokenSample> samples = new ArrayList<>();
+ private final List<TokenSample> samples = new ArrayList<>();
@Test
void testSimpleCount() {
@@ -47,8 +47,8 @@ public class ADTokenSampleStreamTest {
@BeforeEach
void setup() throws IOException, URISyntaxException {
- ADTokenSampleStreamFactory factory = new ADTokenSampleStreamFactory(
- ADTokenSampleStreamFactory.Parameters.class);
+ ADTokenSampleStreamFactory<ADTokenSampleStreamFactory.Parameters> factory =
+ new ADTokenSampleStreamFactory<>(ADTokenSampleStreamFactory.Parameters.class);
File dict = new File(Objects.requireNonNull(getClass().getClassLoader()
.getResource("opennlp/tools/tokenize/latin-detokenizer.xml")).toURI());
diff --git a/opennlp-tools/src/test/java/opennlp/tools/langdetect/DummyFactory.java b/opennlp-tools/src/test/java/opennlp/tools/langdetect/DummyFactory.java
index 7e3a9da1..624c3762 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/langdetect/DummyFactory.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/langdetect/DummyFactory.java
@@ -42,20 +42,25 @@ public class DummyFactory extends LanguageDetectorFactory {
@Override
public LanguageDetectorContextGenerator getContextGenerator() {
- return new DummyFactory.MyContectGenerator(2, 5,
- new DummyFactory.UpperCaseNormalizer());
+ return new MyContextGenerator(2, 5,
+ new UpperCaseNormalizer());
}
- public class UpperCaseNormalizer implements CharSequenceNormalizer {
+ public static class UpperCaseNormalizer implements CharSequenceNormalizer {
+
+ private static final long serialVersionUID = 589425364183582853L;
+
@Override
public CharSequence normalize(CharSequence text) {
return text.toString().toUpperCase();
}
}
- public class MyContectGenerator extends DefaultLanguageDetectorContextGenerator {
+ public static class MyContextGenerator extends DefaultLanguageDetectorContextGenerator {
+
+ private static final long serialVersionUID = 5737572653101696876L;
- public MyContectGenerator(int min, int max, CharSequenceNormalizer... normalizers) {
+ public MyContextGenerator(int min, int max, CharSequenceNormalizer... normalizers) {
super(min, max, normalizers);
}
@@ -63,7 +68,7 @@ public class DummyFactory extends LanguageDetectorFactory {
public String[] getContext(CharSequence document) {
String[] superContext = super.getContext(document);
- List<String> context = new ArrayList(Arrays.asList(superContext));
+ List<String> context = new ArrayList<>(Arrays.asList(superContext));
document = this.normalizer.normalize(document);
@@ -72,10 +77,10 @@ public class DummyFactory extends LanguageDetectorFactory {
NGramModel tokenNgramModel = new NGramModel();
if (words.length > 0) {
tokenNgramModel.add(new StringList(words), 1, 3);
- Iterator tokenNgramIterator = tokenNgramModel.iterator();
+ Iterator<StringList> tokenNgramIterator = tokenNgramModel.iterator();
while (tokenNgramIterator.hasNext()) {
- StringList tokenList = (StringList) tokenNgramIterator.next();
+ StringList tokenList = tokenNgramIterator.next();
if (tokenList.size() > 0) {
context.add("tg=" + tokenList.toString());
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/langdetect/LanguageDetectorFactoryTest.java b/opennlp-tools/src/test/java/opennlp/tools/langdetect/LanguageDetectorFactoryTest.java
index a176bb7f..ee594475 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/langdetect/LanguageDetectorFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/langdetect/LanguageDetectorFactoryTest.java
@@ -81,7 +81,7 @@ public class LanguageDetectorFactoryTest {
String[] context = cg.getContext(
"a dummy text phrase to test if the context generator works!!!!!!!!!!!!");
- Set<String> set = new HashSet(Arrays.asList(context));
+ Set<String> set = new HashSet<>(Arrays.asList(context));
Assertions.assertTrue(set.contains("!!!!!")); // default normalizer would remove the repeated !
Assertions.assertTrue(set.contains("a dum"));
diff --git a/opennlp-tools/src/test/java/opennlp/tools/languagemodel/NgramLanguageModelTest.java b/opennlp-tools/src/test/java/opennlp/tools/languagemodel/NgramLanguageModelTest.java
index 896a3b99..e40b5b31 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/languagemodel/NgramLanguageModelTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/languagemodel/NgramLanguageModelTest.java
@@ -18,6 +18,7 @@
package opennlp.tools.languagemodel;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
@@ -135,26 +136,27 @@ public class NgramLanguageModelTest {
public void testTrigramLanguageModelCreationFromText() throws Exception {
int ngramSize = 3;
NGramLanguageModel languageModel = new NGramLanguageModel(ngramSize);
- InputStream stream = getClass().getResourceAsStream("/opennlp/tools/languagemodel/sentences.txt");
- for (String line : IOUtils.readLines(stream)) {
- String[] array = line.split(" ");
- List<String> split = Arrays.asList(array);
- List<String> generatedStrings = NGramGenerator.generate(split, ngramSize, " ");
- for (String generatedString : generatedStrings) {
- String[] tokens = generatedString.split(" ");
- if (tokens.length > 0) {
- languageModel.add(tokens);
+ try (InputStream stream = getClass().getResourceAsStream("/opennlp/tools/languagemodel/sentences.txt")) {
+ for (String line : IOUtils.readLines(stream, StandardCharsets.UTF_8)) {
+ String[] array = line.split(" ");
+ List<String> split = Arrays.asList(array);
+ List<String> generatedStrings = NGramGenerator.generate(split, ngramSize, " ");
+ for (String generatedString : generatedStrings) {
+ String[] tokens = generatedString.split(" ");
+ if (tokens.length > 0) {
+ languageModel.add(tokens);
+ }
}
}
+ String[] tokens = languageModel.predictNextTokens("neural",
+ "network", "language");
+ Assertions.assertNotNull(tokens);
+ Assertions.assertArrayEquals(new String[] {"models"}, tokens);
+ double p1 = languageModel.calculateProbability("neural", "network",
+ "language", "models");
+ double p2 = languageModel.calculateProbability("neural", "network",
+ "language", "model");
+ Assertions.assertTrue(p1 > p2);
}
- String[] tokens = languageModel.predictNextTokens("neural",
- "network", "language");
- Assertions.assertNotNull(tokens);
- Assertions.assertArrayEquals(new String[] {"models"}, tokens);
- double p1 = languageModel.calculateProbability("neural", "network",
- "language", "models");
- double p2 = languageModel.calculateProbability("neural", "network",
- "language", "model");
- Assertions.assertTrue(p1 > p2);
}
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/ArrayMathTest.java b/opennlp-tools/src/test/java/opennlp/tools/ml/ArrayMathTest.java
index 82974d27..492af233 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/ArrayMathTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/ArrayMathTest.java
@@ -19,6 +19,7 @@ package opennlp.tools.ml;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@@ -104,16 +105,16 @@ public class ArrayMathTest {
@Test
public void testToDoubleArray() {
- Assertions.assertEquals(0, ArrayMath.toDoubleArray(Collections.EMPTY_LIST).length);
- Assertions.assertArrayEquals(new double[] {0}, ArrayMath.toDoubleArray(Arrays.asList(0D)), 0);
+ Assertions.assertEquals(0, ArrayMath.toDoubleArray(Collections.emptyList()).length);
+ Assertions.assertArrayEquals(new double[] {0}, ArrayMath.toDoubleArray(List.of((0D))), 0);
Assertions.assertArrayEquals(new double[] {0, 1, -2.5, -0.3, 4},
ArrayMath.toDoubleArray(Arrays.asList(0D, 1D, -2.5D, -0.3D, 4D)), 0);
}
@Test
public void testToIntArray() {
- Assertions.assertEquals(0, ArrayMath.toIntArray(Collections.EMPTY_LIST).length);
- Assertions.assertArrayEquals(new int[] {0}, ArrayMath.toIntArray(Arrays.asList(0)));
+ Assertions.assertEquals(0, ArrayMath.toIntArray(Collections.emptyList()).length);
+ Assertions.assertArrayEquals(new int[] {0}, ArrayMath.toIntArray(List.of(0)));
Assertions.assertArrayEquals(new int[] {0, 1, -2, -3, 4},
ArrayMath.toIntArray(Arrays.asList(0, 1, -2, -3, 4)));
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/MockEventTrainer.java b/opennlp-tools/src/test/java/opennlp/tools/ml/MockEventTrainer.java
index 242865a2..a709cae5 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/MockEventTrainer.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/MockEventTrainer.java
@@ -37,12 +37,10 @@ public class MockEventTrainer implements EventTrainer {
}
@Override
- public void init(Map<String, String> trainParams,
- Map<String, String> reportMap) {
+ public void init(Map<String, Object> trainParams, Map<String, String> reportMap) {
}
@Override
- public void init(TrainingParameters trainingParams,
- Map<String, String> reportMap) {
+ public void init(TrainingParameters trainingParams, Map<String, String> reportMap) {
}
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/ml/MockSequenceTrainer.java b/opennlp-tools/src/test/java/opennlp/tools/ml/MockSequenceTrainer.java
index 7f4ad621..f3c848c6 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/ml/MockSequenceTrainer.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/ml/MockSequenceTrainer.java
@@ -19,24 +19,23 @@ package opennlp.tools.ml;
import java.util.Map;
+import opennlp.tools.commons.Sample;
import opennlp.tools.ml.model.AbstractModel;
import opennlp.tools.ml.model.SequenceStream;
import opennlp.tools.util.TrainingParameters;
public class MockSequenceTrainer implements EventModelSequenceTrainer {
- public AbstractModel train(SequenceStream events) {
+ public AbstractModel train(SequenceStream<? extends Sample> events) {
return null;
}
@Override
- public void init(Map<String, String> trainParams,
- Map<String, String> reportMap) {
+ public void init(Map<String, Object> trainParams, Map<String, String> reportMap) {
}
@Override
- public void init(TrainingParameters trainParams,
- Map<String, String> reportMap) {
+ public void init(TrainingParameters trainParams, Map<String, String> reportMap) {
}
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
index d9ae7ec6..175531a3 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/namefind/NameFinderEventStreamTest.java
@@ -46,11 +46,14 @@ public class NameFinderEventStreamTest {
@Test
void testOutcomesForSingleTypeSentence() throws IOException {
+ NameContextGenerator CG = new DefaultNameContextGenerator(
+ (AdaptiveFeatureGenerator[]) null);
+
NameSample nameSample = new NameSample(SENTENCE,
new Span[] {new Span(0, 2, "person")}, false);
try (ObjectStream<Event> eventStream = new NameFinderEventStream(
- ObjectStreamUtils.createObjectStream(nameSample))) {
+ ObjectStreamUtils.createObjectStream(nameSample), "person", CG, null)) {
Assertions.assertEquals("person-" + NameFinderME.START, eventStream.read().getOutcome());
Assertions.assertEquals("person-" + NameFinderME.CONTINUE, eventStream.read().getOutcome());
diff --git a/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java b/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java
index ec8cfa5a..07739574 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/postag/POSTaggerFactoryTest.java
@@ -89,7 +89,7 @@ public class POSTaggerFactoryTest {
POSTaggerFactory factory = posModel.getFactory();
Assertions.assertTrue(factory.getTagDictionary() instanceof POSDictionary);
- Assertions.assertTrue(factory.getPOSContextGenerator() != null);
+ Assertions.assertNotNull(factory.getPOSContextGenerator());
Assertions.assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator);
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -100,7 +100,7 @@ public class POSTaggerFactoryTest {
factory = fromSerialized.getFactory();
Assertions.assertTrue(factory.getTagDictionary() instanceof POSDictionary);
- Assertions.assertTrue(factory.getPOSContextGenerator() != null);
+ Assertions.assertNotNull(factory.getPOSContextGenerator());
Assertions.assertTrue(factory.getSequenceValidator() instanceof DefaultPOSSequenceValidator);
}
diff --git a/opennlp-tools/src/test/java/opennlp/tools/util/TrainingParametersTest.java b/opennlp-tools/src/test/java/opennlp/tools/util/TrainingParametersTest.java
index 64a8880c..dd05af6e 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/util/TrainingParametersTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/util/TrainingParametersTest.java
@@ -47,7 +47,7 @@ public class TrainingParametersTest {
void testDefault() {
TrainingParameters tr = TrainingParameters.defaultParams();
- Assertions.assertEquals(4, tr.getSettings().size());
+ Assertions.assertEquals(4, tr.getObjectSettings().size());
Assertions.assertEquals("MAXENT", tr.algorithm());
Assertions.assertEquals(EventTrainer.EVENT_VALUE,
tr.getStringParameter(TrainingParameters.TRAINER_TYPE_PARAM,
@@ -144,10 +144,10 @@ public class TrainingParametersTest {
void testGetSettings() {
TrainingParameters tp = build("k1=v1,n1.k2=v2,n2.k3=v3,n1.k4=v4");
- assertEquals(buildMap("k1=v1"), tp.getSettings());
- assertEquals(buildMap("k2=v2,k4=v4"), tp.getSettings("n1"));
- assertEquals(buildMap("k3=v3"), tp.getSettings("n2"));
- Assertions.assertTrue(tp.getSettings("n3").isEmpty());
+ assertEquals(buildMap("k1=v1"), tp.getObjectSettings());
+ assertEquals(buildMap("k2=v2,k4=v4"), tp.getObjectSettings("n1"));
+ assertEquals(buildMap("k3=v3"), tp.getObjectSettings("n2"));
+ Assertions.assertTrue(tp.getObjectSettings("n3").isEmpty());
}
@Test
@@ -157,7 +157,7 @@ public class TrainingParametersTest {
assertEquals(build("k1=v1"), tp.getParameters(null));
assertEquals(build("k2=v2,k4=v4"), tp.getParameters("n1"));
assertEquals(build("k3=v3"), tp.getParameters("n2"));
- Assertions.assertTrue(tp.getParameters("n3").getSettings().isEmpty());
+ Assertions.assertTrue(tp.getParameters("n3").getObjectSettings().isEmpty());
}
@Test
@@ -183,16 +183,16 @@ public class TrainingParametersTest {
Assertions.assertEquals(tp.getDoubleParameter("k21", -100), 0.001, 345.6); // should be unchanged
Assertions.assertEquals(tp.getDoubleParameter("double", "k5", -100), 0.001, 123.45);
- Assertions.assertEquals(true, tp.getBooleanParameter("k31", true));
+ Assertions.assertTrue(tp.getBooleanParameter("k31", true));
tp.put("k31", false);
- Assertions.assertEquals(false, tp.getBooleanParameter("k31", true));
- Assertions.assertEquals(false, tp.getBooleanParameter("boolean", "k4", true));
+ Assertions.assertFalse(tp.getBooleanParameter("k31", true));
+ Assertions.assertFalse(tp.getBooleanParameter("boolean", "k4", true));
}
// format: k1=v1,k2=v2,...
- private static Map<String, String> buildMap(String str) {
+ private static Map<String, Object> buildMap(String str) {
String[] pairs = str.split(",");
- Map<String, String> map = new HashMap<>(pairs.length);
+ Map<String, Object> map = new HashMap<>(pairs.length);
for (String pair : pairs) {
String[] keyValue = pair.split("=");
map.put(keyValue[0], keyValue[1]);
@@ -206,7 +206,7 @@ public class TrainingParametersTest {
return new TrainingParameters(buildMap(str));
}
- private static void assertEquals(Map<String, String> map1, Map<String, String> map2) {
+ private static void assertEquals(Map<String, Object> map1, Map<String, Object> map2) {
Assertions.assertNotNull(map1);
Assertions.assertNotNull(map2);
Assertions.assertEquals(map1.size(), map2.size());
@@ -215,16 +215,16 @@ public class TrainingParametersTest {
}
}
- private static void assertEquals(Map<String, String> map, TrainingParameters actual) {
+ private static void assertEquals(Map<String, Object> map, TrainingParameters actual) {
Assertions.assertNotNull(actual);
- assertEquals(map, actual.getSettings());
+ assertEquals(map, actual.getObjectSettings());
}
private static void assertEquals(TrainingParameters expected, TrainingParameters actual) {
if (expected == null) {
Assertions.assertNull(actual);
} else {
- assertEquals(expected.getSettings(), actual);
+ assertEquals(expected.getObjectSettings(), actual);
}
}
}
diff --git a/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java b/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
index d1472598..2217d55c 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
@@ -216,7 +216,7 @@ public class Parser extends CasAnnotator_ImplBase {
parseAnnotation.setDoubleValue(probabilityFeature, parse.getProb());
}
- ArrayFS childrenArray = cas.createArrayFS(parseChildAnnotations.length);
+ ArrayFS<?> childrenArray = cas.createArrayFS(parseChildAnnotations.length);
childrenArray.copyFromArray(parseChildAnnotations, 0, 0, parseChildAnnotations.length);
parseAnnotation.setFeatureValue(childrenFeature, childrenArray);
@@ -235,8 +235,8 @@ public class Parser extends CasAnnotator_ImplBase {
private static class ParseConverter {
private final String mSentence;
- private Map<Integer, Integer> mIndexMap = new HashMap<>();
- private Parse mParseForTagger;
+ private final Map<Integer, Integer> mIndexMap = new HashMap<>();
+ private final Parse mParseForTagger;
/**
* Initializes a new instance.