You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2016/12/21 18:18:26 UTC
opennlp git commit: OPENNLP-871: Cleanup for Java 8
Repository: opennlp
Updated Branches:
refs/heads/trunk dd2aaccc0 -> bbda5de40
OPENNLP-871: Cleanup for Java 8
This closes #12
Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/bbda5de4
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/bbda5de4
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/bbda5de4
Branch: refs/heads/trunk
Commit: bbda5de4098e0ffb884384a2fbbccae8b181742b
Parents: dd2aacc
Author: smarthi <sm...@apache.org>
Authored: Wed Dec 21 12:58:26 2016 -0500
Committer: J�rn Kottmann <jo...@apache.org>
Committed: Wed Dec 21 19:17:41 2016 +0100
----------------------------------------------------------------------
.../tools/tokenize/TokenizerCrossValidator.java | 3 +-
.../opennlp/tools/tokenize/TokenizerME.java | 22 +++++-------
.../opennlp/tools/util/ObjectStreamUtils.java | 2 ++
.../tools/tokenize/TokenizerFactoryTest.java | 25 ++++++--------
.../opennlp/uima/chunker/ChunkerTrainer.java | 12 +++----
.../doccat/AbstractDocumentCategorizer.java | 4 +--
.../uima/doccat/DocumentCategorizer.java | 3 +-
.../uima/doccat/DocumentCategorizerTrainer.java | 10 ++----
.../uima/namefind/AbstractNameFinder.java | 6 ++--
.../uima/namefind/NameFinderTrainer.java | 24 ++++----------
.../opennlp/uima/normalizer/Normalizer.java | 5 +--
.../uima/normalizer/StringDictionary.java | 6 ++--
.../main/java/opennlp/uima/parser/Parser.java | 4 +--
.../java/opennlp/uima/postag/POSTagger.java | 4 +--
.../opennlp/uima/postag/POSTaggerTrainer.java | 17 +++++-----
.../sentdetect/SentenceDetectorTrainer.java | 10 +++---
.../opennlp/uima/tokenize/TokenizerTrainer.java | 35 ++++++++++----------
.../opennlp/uima/util/ContainingConstraint.java | 11 ++----
.../java/opennlp/uima/util/OpennlpUtil.java | 4 +--
.../main/java/opennlp/uima/util/UimaUtil.java | 2 +-
20 files changed, 84 insertions(+), 125 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
index 7a85d6a..811165c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
@@ -86,8 +86,7 @@ public class TokenizerCrossValidator {
*/
public void evaluate(ObjectStream<TokenSample> samples, int nFolds) throws IOException {
- CrossValidationPartitioner<TokenSample> partitioner =
- new CrossValidationPartitioner<TokenSample>(samples, nFolds);
+ CrossValidationPartitioner<TokenSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds);
while (partitioner.hasNext()) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
index 3d03943..5412c28 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
@@ -18,7 +18,6 @@
package opennlp.tools.tokenize;
import java.io.IOException;
-import java.io.ObjectStreamException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -26,7 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
-
import opennlp.tools.dictionary.Dictionary;
import opennlp.tools.ml.EventTrainer;
import opennlp.tools.ml.TrainerFactory;
@@ -127,8 +125,8 @@ public class TokenizerME extends AbstractTokenizer {
this.model = model.getMaxentModel();
this.useAlphaNumericOptimization = factory.isUseAlphaNumericOptmization();
- newTokens = new ArrayList<Span>();
- tokProbs = new ArrayList<Double>(50);
+ newTokens = new ArrayList<>();
+ tokProbs = new ArrayList<>(50);
}
/**
@@ -145,13 +143,13 @@ public class TokenizerME extends AbstractTokenizer {
this.model = model.getMaxentModel();
useAlphaNumericOptimization = model.useAlphaNumericOptimization();
- newTokens = new ArrayList<Span>();
- tokProbs = new ArrayList<Double>(50);
+ newTokens = new ArrayList<>();
+ tokProbs = new ArrayList<>(50);
}
private static Set<String> getAbbreviations(Dictionary abbreviations) {
if(abbreviations == null) {
- return Collections.<String>emptySet();
+ return Collections.emptySet();
}
return abbreviations.asStringSet();
}
@@ -241,7 +239,7 @@ public class TokenizerME extends AbstractTokenizer {
public static TokenizerModel train(ObjectStream<TokenSample> samples, TokenizerFactory factory,
TrainingParameters mlParams) throws IOException {
- Map<String, String> manifestInfoEntries = new HashMap<String, String>();
+ Map<String, String> manifestInfoEntries = new HashMap<>();
ObjectStream<Event> eventStream = new TokSpanEventStream(samples,
factory.isUseAlphaNumericOptmization(),
@@ -305,7 +303,7 @@ public class TokenizerME extends AbstractTokenizer {
throws IOException {
Factory factory = new Factory();
- Map<String, String> manifestInfoEntries = new HashMap<String, String>();
+ Map<String, String> manifestInfoEntries = new HashMap<>();
ObjectStream<Event> eventStream = new TokSpanEventStream(samples,
useAlphaNumericOptimization, factory.getAlphanumeric(languageCode),
@@ -334,16 +332,12 @@ public class TokenizerME extends AbstractTokenizer {
* @throws IOException it throws an {@link IOException} if an {@link IOException}
* is thrown during IO operations on a temp file which is
*
- * @throws ObjectStreamException if reading from the {@link ObjectStream} fails
- * created during training.
- *
- *
* @deprecated Use
* {@link #train(ObjectStream, TokenizerFactory, TrainingParameters)}
* and pass in a {@link TokenizerFactory}
*/
public static TokenizerModel train(String languageCode, ObjectStream<TokenSample> samples,
- boolean useAlphaNumericOptimization) throws IOException, ObjectStreamException {
+ boolean useAlphaNumericOptimization) throws IOException {
return train(languageCode, samples, useAlphaNumericOptimization, ModelUtil.createDefaultTrainingParameters());
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java b/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
index b9b1fe8..9ad98dd 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
@@ -31,6 +31,7 @@ public class ObjectStreamUtils {
*
* @return the object stream over the array elements
*/
+ @SafeVarargs
public static <T> ObjectStream<T> createObjectStream(final T... array) {
return new ObjectStream<T>() {
@@ -90,6 +91,7 @@ public class ObjectStreamUtils {
* @param streams
* @return
*/
+ @SafeVarargs
public static <T> ObjectStream<T> createObjectStream(final ObjectStream<T>... streams) {
for (ObjectStream<T> stream : streams) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenizerFactoryTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenizerFactoryTest.java b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenizerFactoryTest.java
index 96d19a6..2fb3d40 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenizerFactoryTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/tokenize/TokenizerFactoryTest.java
@@ -18,19 +18,12 @@
package opennlp.tools.tokenize;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Pattern;
-
-import org.junit.Test;
-
import opennlp.tools.dictionary.Dictionary;
import opennlp.tools.formats.ResourceAsStreamFactory;
import opennlp.tools.tokenize.DummyTokenizerFactory.DummyContextGenerator;
@@ -40,6 +33,12 @@ import opennlp.tools.util.InputStreamFactory;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.PlainTextByLineStream;
import opennlp.tools.util.TrainingParameters;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
/**
* Tests for the {@link TokenizerFactory} class.
@@ -56,11 +55,10 @@ public class TokenizerFactoryTest {
private static TokenizerModel train(TokenizerFactory factory)
throws IOException {
- return TokenizerME.train(createSampleStream(),
- factory, TrainingParameters.defaultParams());
+ return TokenizerME.train(createSampleStream(), factory, TrainingParameters.defaultParams());
}
- static Dictionary loadAbbDictionary() throws IOException {
+ private static Dictionary loadAbbDictionary() throws IOException {
InputStream in = TokenizerFactoryTest.class.getClassLoader()
.getResourceAsStream("opennlp/tools/sentdetect/abb.xml");
@@ -76,7 +74,7 @@ public class TokenizerFactoryTest {
TokenizerModel model = train(new TokenizerFactory(lang, dic, false, null));
TokenizerFactory factory = model.getFactory();
- assertTrue(factory.getAbbreviationDictionary() instanceof Dictionary);
+ assertTrue(factory.getAbbreviationDictionary() != null);
assertTrue(factory.getContextGenerator() instanceof DefaultTokenContextGenerator);
assertEquals(Factory.DEFAULT_ALPHANUMERIC, factory.getAlphaNumericPattern()
@@ -92,7 +90,7 @@ public class TokenizerFactoryTest {
TokenizerModel fromSerialized = new TokenizerModel(in);
factory = fromSerialized.getFactory();
- assertTrue(factory.getAbbreviationDictionary() instanceof Dictionary);
+ assertTrue(factory.getAbbreviationDictionary() != null);
assertTrue(factory.getContextGenerator() instanceof DefaultTokenContextGenerator);
assertEquals(Factory.DEFAULT_ALPHANUMERIC, factory.getAlphaNumericPattern()
@@ -130,8 +128,7 @@ public class TokenizerFactoryTest {
assertNull(factory.getAbbreviationDictionary());
assertTrue(factory.getContextGenerator() instanceof DefaultTokenContextGenerator);
- assertEquals(Factory.DEFAULT_ALPHANUMERIC, factory.getAlphaNumericPattern()
- .pattern());
+ assertEquals(Factory.DEFAULT_ALPHANUMERIC, factory.getAlphaNumericPattern().pattern());
assertEquals(lang, factory.getLanguageCode());
assertEquals(lang, model.getLanguage());
assertFalse(factory.isUseAlphaNumericOptmization());
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/chunker/ChunkerTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/chunker/ChunkerTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/chunker/ChunkerTrainer.java
index d22879d..8c6232b 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/chunker/ChunkerTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/chunker/ChunkerTrainer.java
@@ -66,7 +66,7 @@ import org.apache.uima.util.ProcessTrace;
*/
public class ChunkerTrainer extends CasConsumer_ImplBase {
- private List<ChunkSample> mChunkSamples = new ArrayList<ChunkSample>();
+ private List<ChunkSample> mChunkSamples = new ArrayList<>();
private UimaContext mContext;
@@ -82,8 +82,6 @@ public class ChunkerTrainer extends CasConsumer_ImplBase {
private Feature mChunkTagFeature;
- private Logger mLogger;
-
private String language;
/**
@@ -95,7 +93,7 @@ public class ChunkerTrainer extends CasConsumer_ImplBase {
mContext = getUimaContext();
- mLogger = mContext.getLogger();
+ Logger mLogger = mContext.getLogger();
if (mLogger.isLoggable(Level.INFO)) {
mLogger.log(Level.INFO, "Initializing the OpenNLP Chunker Trainer.");
@@ -183,9 +181,9 @@ public class ChunkerTrainer extends CasConsumer_ImplBase {
Iterator<AnnotationFS> tokenIterator = tcas.createFilteredIterator(tokenIndex.iterator(),
containingConstraint);
- List<String> tokens = new ArrayList<String>();
- List<String> tags = new ArrayList<String>();;
- List<String> chunkTags = new ArrayList<String>();;
+ List<String> tokens = new ArrayList<>();
+ List<String> tags = new ArrayList<>();
+ List<String> chunkTags = new ArrayList<>();
while (tokenIterator.hasNext()) {
AnnotationFS tokenAnnotation = tokenIterator.next();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/doccat/AbstractDocumentCategorizer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/doccat/AbstractDocumentCategorizer.java b/opennlp-uima/src/main/java/opennlp/uima/doccat/AbstractDocumentCategorizer.java
index 5abfd76..d2591d5 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/doccat/AbstractDocumentCategorizer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/doccat/AbstractDocumentCategorizer.java
@@ -41,8 +41,6 @@ abstract class AbstractDocumentCategorizer extends CasAnnotator_ImplBase {
private UimaContext context;
- private Logger mLogger;
-
private opennlp.tools.doccat.DocumentCategorizer mCategorizer;
private Type mTokenType;
@@ -54,7 +52,7 @@ abstract class AbstractDocumentCategorizer extends CasAnnotator_ImplBase {
this.context = context;
- mLogger = context.getLogger();
+ Logger mLogger = context.getLogger();
if (mLogger.isLoggable(Level.INFO)) {
mLogger.log(Level.INFO, "Initializing the OpenNLP Categorizer.");
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizer.java b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizer.java
index 5cf337f..cb71a50 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizer.java
@@ -56,8 +56,7 @@ public class DocumentCategorizer extends AbstractDocumentCategorizer {
protected void setBestCategory(CAS tcas, String bestCategory) {
FSIndex<AnnotationFS> categoryIndex = tcas.getAnnotationIndex(mCategoryType);
- AnnotationFS categoryAnnotation = categoryIndex.size() > 0 ?
- categoryIndex.iterator().next() : null;
+ AnnotationFS categoryAnnotation;
if (categoryIndex.size() > 0) {
categoryAnnotation = categoryIndex.iterator().next();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
index 31c6392..5b35a82 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/doccat/DocumentCategorizerTrainer.java
@@ -56,13 +56,9 @@ public class DocumentCategorizerTrainer extends CasConsumer_ImplBase {
private UimaContext mContext;
- private Logger mLogger;
-
private String mModelName;
- private List<DocumentSample> documentSamples = new ArrayList<DocumentSample>();
-
- private Type mTokenType;
+ private List<DocumentSample> documentSamples = new ArrayList<>();
private Type mCategoryType;
@@ -76,7 +72,7 @@ public class DocumentCategorizerTrainer extends CasConsumer_ImplBase {
mContext = getUimaContext();
- mLogger = mContext.getLogger();
+ Logger mLogger = mContext.getLogger();
if (mLogger.isLoggable(Level.INFO)) {
mLogger.log(Level.INFO, "Initializing the OpenNLP Doccat Trainer.");
@@ -95,7 +91,7 @@ public class DocumentCategorizerTrainer extends CasConsumer_ImplBase {
String tokenTypeName = CasConsumerUtil.getRequiredStringParameter(mContext,
UimaUtil.SENTENCE_TYPE_PARAMETER);
- mTokenType = CasConsumerUtil.getType(typeSystem, tokenTypeName);
+ Type mTokenType = CasConsumerUtil.getType(typeSystem, tokenTypeName);
String categoryTypeName = CasConsumerUtil.getRequiredStringParameter(mContext,
"opennlp.uima.doccat.CategoryType");
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/namefind/AbstractNameFinder.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/namefind/AbstractNameFinder.java b/opennlp-uima/src/main/java/opennlp/uima/namefind/AbstractNameFinder.java
index c0bad5d..dbc604c 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/namefind/AbstractNameFinder.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/namefind/AbstractNameFinder.java
@@ -123,7 +123,7 @@ abstract class AbstractNameFinder extends CasAnnotator_ImplBase {
final AnnotationComboIterator sentenceNameCombo = new AnnotationComboIterator(cas,
mSentenceType, mNameType);
- List<AnnotationFS> removeAnnotations = new LinkedList<AnnotationFS>();
+ List<AnnotationFS> removeAnnotations = new LinkedList<>();
for (AnnotationIteratorPair annotationIteratorPair : sentenceNameCombo) {
for (AnnotationFS nameAnnotation : annotationIteratorPair.getSubIterator()) {
removeAnnotations.add(nameAnnotation);
@@ -140,9 +140,9 @@ abstract class AbstractNameFinder extends CasAnnotator_ImplBase {
for (AnnotationIteratorPair annotationIteratorPair : sentenceTokenCombo) {
- final List<AnnotationFS> sentenceTokenAnnotationList = new LinkedList<AnnotationFS>();
+ final List<AnnotationFS> sentenceTokenAnnotationList = new LinkedList<>();
- final List<String> sentenceTokenList = new LinkedList<String>();
+ final List<String> sentenceTokenList = new LinkedList<>();
for (AnnotationFS tokenAnnotation : annotationIteratorPair.getSubIterator()) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/namefind/NameFinderTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/namefind/NameFinderTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/namefind/NameFinderTrainer.java
index dcc0ddc..6207580 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/namefind/NameFinderTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/namefind/NameFinderTrainer.java
@@ -126,7 +126,7 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
// - Directly start indexing with a blocking sample stream, the indexer will then write everything
// to disk or could store the events much more space efficient in memory
- private List<NameSample> nameFinderSamples = new ArrayList<NameSample>();
+ private List<NameSample> nameFinderSamples = new ArrayList<>();
private TrainingParameters trainingParams;
/**
@@ -220,7 +220,7 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
* @return
*/
private static <T> List<T> iteratorToList(Iterator<T> it) {
- List<T> list = new LinkedList<T>();
+ List<T> list = new LinkedList<>();
while (it.hasNext()) {
list.add(it.next());
@@ -231,19 +231,9 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
private static boolean isContaining(AnnotationFS annotation,
AnnotationFS containtedAnnotation) {
- boolean isStartContaining = annotation.getBegin() <= containtedAnnotation
- .getBegin();
- if (!isStartContaining) {
- return false;
- }
-
- boolean isEndContaining = annotation.getEnd() >= containtedAnnotation
- .getEnd();
- if (!isEndContaining) {
- return false;
- }
+ boolean isStartContaining = annotation.getBegin() <= containtedAnnotation.getBegin();
+ return isStartContaining && annotation.getEnd() >= containtedAnnotation.getEnd();
- return true;
}
/**
@@ -258,7 +248,7 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
*/
private static Span[] createNames(List<AnnotationFS> tokenList, List<AnnotationFS> entityAnnotations) {
- List<Span> nameList = new LinkedList<Span>();
+ List<Span> nameList = new LinkedList<>();
AnnotationFS currentEntity = null;
@@ -299,7 +289,7 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
return nameList.toArray(new Span[nameList.size()]);
}
- /**
+ /*
* Process the given CAS object.
*/
/**
@@ -392,7 +382,7 @@ public final class NameFinderTrainer extends CasConsumer_ImplBase {
if (sampleTraceFile != null) {
samplesOut = new OutputStreamWriter(new FileOutputStream(sampleTraceFile), sampleTraceFileEncoding);
- samples = new SampleTraceStream<NameSample>(samples, samplesOut);
+ samples = new SampleTraceStream<>(samples, samplesOut);
}
Map<String, Object> resourceMap;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/normalizer/Normalizer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/normalizer/Normalizer.java b/opennlp-uima/src/main/java/opennlp/uima/normalizer/Normalizer.java
index 39150ac..2118a0a 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/normalizer/Normalizer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/normalizer/Normalizer.java
@@ -65,7 +65,7 @@ public class Normalizer extends CasAnnotator_ImplBase {
private static final Set<String> SUPPORTED_TYPES;
static {
- Set<String> supportedTypes = new HashSet<String>();
+ Set<String> supportedTypes = new HashSet<>();
supportedTypes.add(CAS.TYPE_NAME_STRING);
supportedTypes.add(CAS.TYPE_NAME_BYTE);
@@ -232,9 +232,6 @@ public class Normalizer extends CasAnnotator_ImplBase {
.getName())) {
nameAnnotation
.setDoubleValue(mStructureFeature, number.doubleValue());
- } else {
- // assert false : mStructureFeature.getRange().getName()
- // + " is not supported!";
}
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/normalizer/StringDictionary.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/normalizer/StringDictionary.java b/opennlp-uima/src/main/java/opennlp/uima/normalizer/StringDictionary.java
index e55f4ae..5631544 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/normalizer/StringDictionary.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/normalizer/StringDictionary.java
@@ -34,7 +34,7 @@ import opennlp.tools.util.StringList;
// lookup a string for given token list
public class StringDictionary {
- private Map<StringList, String> entries = new HashMap<StringList, String>();
+ private Map<StringList, String> entries = new HashMap<>();
public StringDictionary() {
}
@@ -44,10 +44,8 @@ public class StringDictionary {
*
* @param in
* @throws IOException
- * @throws InvalidFormatException
*/
- public StringDictionary(InputStream in) throws IOException,
- InvalidFormatException {
+ public StringDictionary(InputStream in) throws IOException {
DictionarySerializer.create(in, new EntryInserter() {
public void insert(Entry entry) throws InvalidFormatException {
String valueString = entry.getAttributes().getValue("value");
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
----------------------------------------------------------------------
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 a3b3f00..6e7ecda 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/parser/Parser.java
@@ -70,7 +70,7 @@ import org.apache.uima.util.Logger;
public class Parser extends CasAnnotator_ImplBase {
private static class ParseConverter {
- private Map<Integer, Integer> mIndexMap = new HashMap<Integer, Integer>();
+ private Map<Integer, Integer> mIndexMap = new HashMap<>();
private Parse mParseForTagger;
@@ -271,7 +271,7 @@ public class Parser extends CasAnnotator_ImplBase {
Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator(
allTokens.iterator(), containingConstraint);
- List<Span> tokenSpans = new LinkedList<Span>();
+ List<Span> tokenSpans = new LinkedList<>();
while(containingTokens.hasNext()) {
AnnotationFS token = containingTokens.next();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/postag/POSTagger.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/postag/POSTagger.java b/opennlp-uima/src/main/java/opennlp/uima/postag/POSTagger.java
index 2fdc47c..358e82c 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/postag/POSTagger.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/postag/POSTagger.java
@@ -164,9 +164,9 @@ public final class POSTagger extends CasAnnotator_ImplBase {
for (AnnotationIteratorPair annotationIteratorPair : comboIterator) {
- final List<AnnotationFS> sentenceTokenAnnotationList = new LinkedList<AnnotationFS>();
+ final List<AnnotationFS> sentenceTokenAnnotationList = new LinkedList<>();
- final List<String> sentenceTokenList = new LinkedList<String>();
+ final List<String> sentenceTokenList = new LinkedList<>();
for (AnnotationFS tokenAnnotation : annotationIteratorPair.getSubIterator()) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/postag/POSTaggerTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/postag/POSTaggerTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/postag/POSTaggerTrainer.java
index 23158b9..16e1605 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/postag/POSTaggerTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/postag/POSTaggerTrainer.java
@@ -17,26 +17,25 @@
package opennlp.uima.postag;
-import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-
import opennlp.tools.ml.maxent.GIS;
-import opennlp.tools.postag.*;
+import opennlp.tools.postag.POSDictionary;
+import opennlp.tools.postag.POSModel;
+import opennlp.tools.postag.POSSample;
+import opennlp.tools.postag.POSTaggerFactory;
+import opennlp.tools.postag.POSTaggerME;
import opennlp.tools.util.ObjectStreamUtils;
import opennlp.tools.util.TrainingParameters;
-import opennlp.tools.util.model.ModelType;
import opennlp.uima.util.AnnotatorUtil;
import opennlp.uima.util.CasConsumerUtil;
import opennlp.uima.util.ContainingConstraint;
import opennlp.uima.util.OpennlpUtil;
import opennlp.uima.util.UimaUtil;
-
import org.apache.uima.UimaContext;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.FSIndex;
@@ -82,7 +81,7 @@ public class POSTaggerTrainer extends CasConsumer_ImplBase {
private Logger mLogger;
- private List<POSSample> mPOSSamples = new ArrayList<POSSample>();
+ private List<POSSample> mPOSSamples = new ArrayList<>();
private String language;
@@ -173,8 +172,8 @@ public class POSTaggerTrainer extends CasConsumer_ImplBase {
ContainingConstraint containingConstraint =
new ContainingConstraint(sentence);
- List<String> tokens = new ArrayList<String>();
- List<String> tags = new ArrayList<String>();
+ List<String> tokens = new ArrayList<>();
+ List<String> tags = new ArrayList<>();
Iterator<AnnotationFS> containingTokens = tcas.createFilteredIterator(
allTokens.iterator(), containingConstraint);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/sentdetect/SentenceDetectorTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/sentdetect/SentenceDetectorTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/sentdetect/SentenceDetectorTrainer.java
index 8fa22d7..2c110bd 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/sentdetect/SentenceDetectorTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/sentdetect/SentenceDetectorTrainer.java
@@ -67,7 +67,7 @@ import org.apache.uima.util.ProcessTrace;
*/
public final class SentenceDetectorTrainer extends CasConsumer_ImplBase {
- private List<SentenceSample> sentenceSamples = new ArrayList<SentenceSample>();
+ private List<SentenceSample> sentenceSamples = new ArrayList<>();
private Type mSentenceType;
@@ -75,8 +75,6 @@ public final class SentenceDetectorTrainer extends CasConsumer_ImplBase {
private String language = "en";
- private Logger mLogger;
-
private UimaContext mContext;
private String eosChars;
@@ -94,7 +92,7 @@ public final class SentenceDetectorTrainer extends CasConsumer_ImplBase {
mContext = getUimaContext();
- mLogger = mContext.getLogger();
+ Logger mLogger = mContext.getLogger();
if (mLogger.isLoggable(Level.INFO)) {
mLogger.log(Level.INFO, "Initializing the OpenNLP SentenceDetector " +
@@ -172,11 +170,11 @@ public final class SentenceDetectorTrainer extends CasConsumer_ImplBase {
TrainingParameters mlParams = ModelUtil.createDefaultTrainingParameters();
ObjectStream<SentenceSample> samples = ObjectStreamUtils.createObjectStream(sentenceSamples);
- Writer samplesOut = null;
+ Writer samplesOut;
if (sampleTraceFile != null) {
samplesOut = new OutputStreamWriter(new FileOutputStream(sampleTraceFile), sampleTraceFileEncoding);
- samples = new SampleTraceStream<SentenceSample>(samples, samplesOut);
+ samples = new SampleTraceStream<>(samples, samplesOut);
}
SentenceModel sentenceModel = SentenceDetectorME.train(language, samples,
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/tokenize/TokenizerTrainer.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/tokenize/TokenizerTrainer.java b/opennlp-uima/src/main/java/opennlp/uima/tokenize/TokenizerTrainer.java
index ece9eca..66d1dfa 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/tokenize/TokenizerTrainer.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/tokenize/TokenizerTrainer.java
@@ -29,19 +29,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import org.apache.uima.UimaContext;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.FSIndex;
-import org.apache.uima.cas.Type;
-import org.apache.uima.cas.TypeSystem;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.collection.CasConsumer_ImplBase;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceProcessException;
-import org.apache.uima.util.Level;
-import org.apache.uima.util.Logger;
-import org.apache.uima.util.ProcessTrace;
-
import opennlp.tools.ml.maxent.GIS;
import opennlp.tools.tokenize.TokenSample;
import opennlp.tools.tokenize.TokenSampleStream;
@@ -58,6 +45,18 @@ import opennlp.uima.util.ContainingConstraint;
import opennlp.uima.util.OpennlpUtil;
import opennlp.uima.util.SampleTraceStream;
import opennlp.uima.util.UimaUtil;
+import org.apache.uima.UimaContext;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.collection.CasConsumer_ImplBase;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceProcessException;
+import org.apache.uima.util.Level;
+import org.apache.uima.util.Logger;
+import org.apache.uima.util.ProcessTrace;
/**
* OpenNLP Tokenizer trainer.
@@ -80,10 +79,10 @@ import opennlp.uima.util.UimaUtil;
*/
public final class TokenizerTrainer extends CasConsumer_ImplBase {
- public static final String IS_ALPHA_NUMERIC_OPTIMIZATION =
+ private static final String IS_ALPHA_NUMERIC_OPTIMIZATION =
"opennlp.uima.tokenizer.IsAlphaNumericOptimization";
- private List<TokenSample> tokenSamples = new ArrayList<TokenSample>();
+ private List<TokenSample> tokenSamples = new ArrayList<>();
private UimaContext mContext;
@@ -194,7 +193,7 @@ public final class TokenizerTrainer extends CasConsumer_ImplBase {
Iterator<AnnotationFS> containingTokens = tcas.createFilteredIterator(
allTokens.iterator(), containingConstraint);
- List<Span> openNLPSpans = new LinkedList<Span>();
+ List<Span> openNLPSpans = new LinkedList<>();
while (containingTokens.hasNext()) {
AnnotationFS tokenAnnotation = containingTokens.next();
@@ -231,7 +230,7 @@ public final class TokenizerTrainer extends CasConsumer_ImplBase {
// if trace file
// serialize events ...
- Writer samplesOut = null;
+ Writer samplesOut;
TokenizerModel tokenModel;
if (additionalTrainingDataFile != null) {
@@ -255,7 +254,7 @@ public final class TokenizerTrainer extends CasConsumer_ImplBase {
if (sampleTraceFile != null) {
samplesOut = new OutputStreamWriter(new FileOutputStream(sampleTraceFile), sampleTraceFileEncoding);
- samples = new SampleTraceStream<TokenSample>(samples, samplesOut);
+ samples = new SampleTraceStream<>(samples, samplesOut);
}
tokenModel = TokenizerME.train(language, samples, isSkipAlphaNumerics);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/util/ContainingConstraint.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/util/ContainingConstraint.java b/opennlp-uima/src/main/java/opennlp/uima/util/ContainingConstraint.java
index 20c00ed..57ae612 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/util/ContainingConstraint.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/util/ContainingConstraint.java
@@ -30,8 +30,7 @@ import org.apache.uima.cas.text.AnnotationFS;
public final class ContainingConstraint implements FSMatchConstraint {
private static final long serialVersionUID = 1;
- private Collection<AnnotationFS> mContainingAnnotations =
- new LinkedList<AnnotationFS>();
+ private Collection<AnnotationFS> mContainingAnnotations = new LinkedList<>();
/**
* Initializes a new instance.
@@ -69,12 +68,8 @@ public final class ContainingConstraint implements FSMatchConstraint {
}
private boolean isContaining(AnnotationFS annotation, AnnotationFS containing) {
- if ((containing.getBegin() <= annotation.getBegin())
- && (containing.getEnd() >= annotation.getEnd())) {
- return true;
- } else {
- return false;
- }
+ return (containing.getBegin() <= annotation.getBegin())
+ && (containing.getEnd() >= annotation.getEnd());
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/util/OpennlpUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/util/OpennlpUtil.java b/opennlp-uima/src/main/java/opennlp/uima/util/OpennlpUtil.java
index 59e8566..23d0b3a 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/util/OpennlpUtil.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/util/OpennlpUtil.java
@@ -56,7 +56,7 @@ final public class OpennlpUtil {
}
}
- public static final byte[] loadBytes(File inFile) throws IOException {
+ public static byte[] loadBytes(File inFile) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (InputStream in = new FileInputStream(inFile)) {
@@ -71,7 +71,7 @@ final public class OpennlpUtil {
return bytes.toByteArray();
}
- public static final TrainingParameters loadTrainingParams(String inFileValue,
+ public static TrainingParameters loadTrainingParams(String inFileValue,
boolean isSequenceTrainingAllowed) throws ResourceInitializationException {
TrainingParameters params;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/bbda5de4/opennlp-uima/src/main/java/opennlp/uima/util/UimaUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-uima/src/main/java/opennlp/uima/util/UimaUtil.java b/opennlp-uima/src/main/java/opennlp/uima/util/UimaUtil.java
index 610cdfd..5d4efc6 100644
--- a/opennlp-uima/src/main/java/opennlp/uima/util/UimaUtil.java
+++ b/opennlp-uima/src/main/java/opennlp/uima/util/UimaUtil.java
@@ -102,7 +102,7 @@ public final class UimaUtil {
Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator(
allRemoveAnnotations.iterator(), containingConstraint);
- Collection<AnnotationFS> removeAnnotations = new LinkedList<AnnotationFS>();
+ Collection<AnnotationFS> removeAnnotations = new LinkedList<>();
while (containingTokens.hasNext()) {
removeAnnotations.add(containingTokens.next());