You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by sm...@apache.org on 2017/01/19 04:32:10 UTC
[8/9] opennlp git commit: OPENNLP-947: Organize imports according to
new order, this closes apache/opennlp#74
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
index 3aea957..a29119b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java
@@ -51,7 +51,7 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
* @param eosCharacters
*/
public DefaultSDContextGenerator(char[] eosCharacters) {
- this(Collections.<String>emptySet(), eosCharacters);
+ this(Collections.emptySet(), eosCharacters);
}
/**
@@ -68,7 +68,7 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
this.inducedAbbreviations = inducedAbbreviations;
this.eosCharacters = eosCharacters;
buf = new StringBuffer();
- collectFeats = new ArrayList<String>();
+ collectFeats = new ArrayList<>();
}
private static String escapeChar(Character c) {
@@ -88,22 +88,22 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
*/
public String[] getContext(CharSequence sb, int position) {
- /**
+ /*
* String preceding the eos character in the eos token.
*/
String prefix;
- /**
+ /*
* Space delimited token preceding token containing eos character.
*/
String previous;
- /**
+ /*
* String following the eos character in the eos token.
*/
String suffix;
- /**
+ /*
* Space delimited token following token containing eos character.
*/
String next;
@@ -244,7 +244,7 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
}
}
- private static final boolean isFirstUpper(String s) {
+ private static boolean isFirstUpper(String s) {
return Character.isUpperCase(s.charAt(0));
}
@@ -255,7 +255,7 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
* @param seek The index to begin searching from.
* @return The index which contains the nearest space.
*/
- private static final int previousSpaceIndex(CharSequence sb, int seek) {
+ private static int previousSpaceIndex(CharSequence sb, int seek) {
seek--;
while (seek > 0 && !StringUtil.isWhitespace(sb.charAt(seek))) {
seek--;
@@ -276,7 +276,7 @@ public class DefaultSDContextGenerator implements SDContextGenerator {
* @param lastIndex The highest index of the StringBuffer sb.
* @return The index which contains the nearest space.
*/
- private static final int nextSpaceIndex(CharSequence sb, int seek, int lastIndex) {
+ private static int nextSpaceIndex(CharSequence sb, int seek, int lastIndex) {
seek++;
char c;
while (seek < lastIndex) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java
index 2b79ce4..b48ad3f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java
@@ -15,8 +15,6 @@
* limitations under the License.
*/
-
-
package opennlp.tools.sentdetect;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
index 2f7100b..4f3c96c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/NewlineSentenceDetector.java
@@ -34,7 +34,7 @@ public class NewlineSentenceDetector implements SentenceDetector {
public Span[] sentPosDetect(String s) {
- List<Span> sentences = new ArrayList<Span>();
+ List<Span> sentences = new ArrayList<>();
int start = 0;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
index ebf0a3c..2f6daec 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
@@ -41,8 +41,7 @@ public class SDCrossValidator {
private SentenceDetectorFactory sdFactory;
public SDCrossValidator(String languageCode, TrainingParameters params,
- SentenceDetectorFactory sdFactory,
- SentenceDetectorEvaluationMonitor... listeners) {
+ SentenceDetectorFactory sdFactory, SentenceDetectorEvaluationMonitor... listeners) {
this.languageCode = languageCode;
this.params = params;
this.listeners = listeners;
@@ -94,7 +93,7 @@ public class SDCrossValidator {
public void evaluate(ObjectStream<SentenceSample> samples, int nFolds) throws IOException {
CrossValidationPartitioner<SentenceSample> partitioner =
- new CrossValidationPartitioner<SentenceSample>(samples, nFolds);
+ new CrossValidationPartitioner<>(samples, nFolds);
while (partitioner.hasNext()) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
index 58c9846..b246327 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorEvaluator.java
@@ -46,7 +46,7 @@ public class SentenceDetectorEvaluator extends Evaluator<SentenceSample> {
* @param listeners evaluation sample listeners
*/
public SentenceDetectorEvaluator(SentenceDetector sentenceDetector,
- SentenceDetectorEvaluationMonitor... listeners) {
+ SentenceDetectorEvaluationMonitor... listeners) {
super(listeners);
this.sentenceDetector = sentenceDetector;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
index 9ef3e78..54dcc64 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorFactory.java
@@ -77,11 +77,9 @@ public class SentenceDetectorFactory extends BaseToolFactory {
throw new InvalidFormatException(TOKEN_END_PROPERTY
+ " is a mandatory property!");
- Object abbreviationsEntry = this.artifactProvider
- .getArtifact(ABBREVIATIONS_ENTRY_NAME);
+ Object abbreviationsEntry = this.artifactProvider.getArtifact(ABBREVIATIONS_ENTRY_NAME);
- if (abbreviationsEntry != null
- && !(abbreviationsEntry instanceof Dictionary)) {
+ if (abbreviationsEntry != null && !(abbreviationsEntry instanceof Dictionary)) {
throw new InvalidFormatException(
"Abbreviations dictionary '" + abbreviationsEntry +
"' has wrong type, needs to be of type Dictionary!");
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
index 7f28a9b..282147d 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
@@ -74,7 +74,7 @@ public class SentenceDetectorME implements SentenceDetector {
/**
* The list of probabilities associated with each decision.
*/
- private List<Double> sentProbs = new ArrayList<Double>();
+ private List<Double> sentProbs = new ArrayList<>();
protected boolean useTokenEnd;
@@ -114,7 +114,7 @@ public class SentenceDetectorME implements SentenceDetector {
private static Set<String> getAbbreviations(Dictionary abbreviations) {
if (abbreviations == null) {
- return Collections.<String>emptySet();
+ return Collections.emptySet();
}
return abbreviations.asStringSet();
}
@@ -130,9 +130,7 @@ public class SentenceDetectorME implements SentenceDetector {
Span[] spans = sentPosDetect(s);
String sentences[];
if (spans.length != 0) {
-
sentences = new String[spans.length];
-
for (int si = 0; si < spans.length; si++) {
sentences[si] = spans[si].getCoveredText(s).toString();
}
@@ -167,11 +165,10 @@ public class SentenceDetectorME implements SentenceDetector {
sentProbs.clear();
StringBuffer sb = new StringBuffer(s);
List<Integer> enders = scanner.getPositions(s);
- List<Integer> positions = new ArrayList<Integer>(enders.size());
+ List<Integer> positions = new ArrayList<>(enders.size());
for (int i = 0, end = enders.size(), index = 0; i < end; i++) {
- Integer candidate = enders.get(i);
- int cint = candidate;
+ int cint = enders.get(i);
// skip over the leading parts of non-token final delimiters
int fws = getFirstWS(s,cint + 1);
if (i + 1 < end && enders.get(i + 1) < fws) {
@@ -256,7 +253,7 @@ public class SentenceDetectorME implements SentenceDetector {
sentProbs.add(1d);
}
}
- /**
+ /*
* set the prob for each span
*/
for (int i = 0; i < spans.length; i++) {
@@ -317,7 +314,7 @@ public class SentenceDetectorME implements SentenceDetector {
ObjectStream<SentenceSample> samples, SentenceDetectorFactory sdFactory,
TrainingParameters mlParams) throws IOException {
- Map<String, String> manifestInfoEntries = new HashMap<String, String>();
+ Map<String, String> manifestInfoEntries = new HashMap<>();
// TODO: Fix the EventStream to throw exceptions when training goes wrong
ObjectStream<Event> eventStream = new SDEventStream(samples,
@@ -327,8 +324,7 @@ public class SentenceDetectorME implements SentenceDetector {
MaxentModel sentModel = trainer.train(eventStream);
- return new SentenceModel(languageCode, sentModel, manifestInfoEntries,
- sdFactory);
+ return new SentenceModel(languageCode, sentModel, manifestInfoEntries, sdFactory);
}
/**
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
----------------------------------------------------------------------
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 ddec4ba..8b1d118 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSample.java
@@ -44,12 +44,12 @@ public class SentenceSample {
*/
public SentenceSample(String document, Span... sentences) {
this.document = document;
- this.sentences = Collections.unmodifiableList(new ArrayList<Span>(Arrays.asList(sentences)));
+ this.sentences = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(sentences)));
}
public SentenceSample(Detokenizer detokenizer, String[][] sentences) {
- List<Span> spans = new ArrayList<Span>(sentences.length);
+ List<Span> spans = new ArrayList<>(sentences.length);
StringBuilder documentBuilder = new StringBuilder();
@@ -89,15 +89,12 @@ public class SentenceSample {
// TODO: This one must output the tags!
@Override
public String toString() {
-
StringBuilder documentBuilder = new StringBuilder();
-
for (Span sentSpan : sentences) {
documentBuilder.append(sentSpan.getCoveredText(document).toString()
.replace("\r", "<CR>").replace("\n", "<LF>"));
documentBuilder.append("\n");
}
-
return documentBuilder.toString();
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSampleStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSampleStream.java
index a5c418b..10348bd 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSampleStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceSampleStream.java
@@ -44,11 +44,10 @@ public class SentenceSampleStream extends FilterObjectStream<String, SentenceSam
public SentenceSample read() throws IOException {
StringBuilder sentencesString = new StringBuilder();
- List<Span> sentenceSpans = new LinkedList<Span>();
+ List<Span> sentenceSpans = new LinkedList<>();
String sentence;
while ((sentence = samples.read()) != null && !sentence.equals("")) {
-
int begin = sentencesString.length();
sentence = sentence.trim();
sentence = replaceNewLineEscapeTags(sentence);
@@ -62,8 +61,6 @@ public class SentenceSampleStream extends FilterObjectStream<String, SentenceSam
return new SentenceSample(sentencesString.toString(),
sentenceSpans.toArray(new Span[sentenceSpans.size()]));
}
- else {
- return null;
- }
+ return null;
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
index 9d4647d..28b515b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.sentdetect.lang;
import java.util.Collections;
@@ -65,7 +64,7 @@ public class Factory {
}
public SDContextGenerator createSentenceContextGenerator(String languageCode) {
- return createSentenceContextGenerator(languageCode, Collections.<String>emptySet());
+ return createSentenceContextGenerator(languageCode, Collections.emptySet());
}
public char[] getEOSCharacters(String languageCode) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
index baab080..3b24662 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.sentdetect.lang.th;
import opennlp.tools.sentdetect.DefaultSDContextGenerator;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
index 99c717d..552cc69 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DefaultTokenContextGenerator.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.tokenize;
import java.util.ArrayList;
@@ -36,7 +35,7 @@ public class DefaultTokenContextGenerator implements TokenContextGenerator {
* Creates a default context generator for tokenizer.
*/
public DefaultTokenContextGenerator() {
- this(Collections.<String>emptySet());
+ this(Collections.emptySet());
}
/**
@@ -71,7 +70,7 @@ public class DefaultTokenContextGenerator implements TokenContextGenerator {
* at the specified index.
*/
protected List<String> createContext(String sentence, int index) {
- List<String> preds = new ArrayList<String>();
+ List<String> preds = new ArrayList<>();
String prefix = sentence.substring(0, index);
String suffix = sentence.substring(index);
preds.add("p=" + prefix);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
index 00d2dc7..f1b86d0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DetokenizationDictionary.java
@@ -27,7 +27,6 @@ import java.util.Map;
import opennlp.tools.dictionary.serializer.Attributes;
import opennlp.tools.dictionary.serializer.DictionarySerializer;
import opennlp.tools.dictionary.serializer.Entry;
-import opennlp.tools.dictionary.serializer.EntryInserter;
import opennlp.tools.util.InvalidFormatException;
import opennlp.tools.util.StringList;
@@ -76,8 +75,7 @@ public class DetokenizationDictionary {
}
}
- private final Map<String, DetokenizationDictionary.Operation> operationTable =
- new HashMap<String, DetokenizationDictionary.Operation>();
+ private final Map<String, DetokenizationDictionary.Operation> operationTable = new HashMap<>();
/**
* Initializes the current instance.
@@ -106,26 +104,24 @@ public class DetokenizationDictionary {
}
}
- public DetokenizationDictionary(InputStream in) throws IOException, InvalidFormatException {
+ public DetokenizationDictionary(InputStream in) throws IOException {
- DictionarySerializer.create(in, new EntryInserter() {
- public void insert(Entry entry) throws InvalidFormatException {
+ DictionarySerializer.create(in, entry -> {
- String operationString = entry.getAttributes().getValue("operation");
+ String operationString = entry.getAttributes().getValue("operation");
- StringList word = entry.getTokens();
+ StringList word = entry.getTokens();
- if (word.size() != 1)
- throw new InvalidFormatException("Each entry must have exactly one token! " + word);
+ if (word.size() != 1)
+ throw new InvalidFormatException("Each entry must have exactly one token! " + word);
- // parse operation
- Operation operation = Operation.parse(operationString);
+ // parse operation
+ Operation operation = Operation.parse(operationString);
- if (operation == null)
- throw new InvalidFormatException("Unknown operation type: " + operationString);
+ if (operation == null)
+ throw new InvalidFormatException("Unknown operation type: " + operationString);
- operationTable.put(word.getToken(0), operation);
- }
+ operationTable.put(word.getToken(0), operation);
});
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
index cb38004..33eab9e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/DictionaryDetokenizer.java
@@ -37,10 +37,9 @@ public class DictionaryDetokenizer implements Detokenizer {
public DetokenizationOperation[] detokenize(String[] tokens) {
- DetokenizationOperation operations[] =
- new DetokenizationOperation[tokens.length];
+ DetokenizationOperation operations[] = new DetokenizationOperation[tokens.length];
- Set<String> matchingTokens = new HashSet<String>();
+ Set<String> matchingTokens = new HashSet<>();
for (int i = 0; i < tokens.length; i++) {
DetokenizationDictionary.Operation dictOperation = dict.getOperation(tokens[i]);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
index 0b3c294..b855c3b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.tokenize;
import java.util.ArrayList;
@@ -65,7 +64,7 @@ public class SimpleTokenizer extends AbstractTokenizer {
CharacterEnum charType = CharacterEnum.WHITESPACE;
CharacterEnum state = charType;
- List<Span> tokens = new ArrayList<Span>();
+ List<Span> tokens = new ArrayList<>();
int sl = s.length();
int start = -1;
char pc = 0;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
index 16b1616..dd9745e 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokSpanEventStream.java
@@ -97,7 +97,7 @@ public class TokSpanEventStream extends AbstractEventStream<TokenSample> {
@Override
protected Iterator<Event> createEvents(TokenSample tokenSample) {
- List<Event> events = new ArrayList<Event>(50);
+ List<Event> events = new ArrayList<>(50);
Span tokens[] = tokenSample.getTokenSpans();
String text = tokenSample.getText();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
----------------------------------------------------------------------
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 4f3ebd2..a61f8ae 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenSample.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.tokenize;
import java.util.ArrayList;
@@ -34,7 +33,7 @@ public class TokenSample {
public static final String DEFAULT_SEPARATOR_CHARS = "<SPLIT>";
- private final String separatorChars = DEFAULT_SEPARATOR_CHARS;
+ private static final String separatorChars = DEFAULT_SEPARATOR_CHARS;
private final String text;
@@ -55,7 +54,7 @@ public class TokenSample {
throw new IllegalArgumentException("tokenSpans must not be null! ");
this.text = text;
- this.tokenSpans = Collections.unmodifiableList(new ArrayList<Span>(Arrays.asList(tokenSpans)));
+ this.tokenSpans = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tokenSpans)));
for (Span tokenSpan : tokenSpans) {
if (tokenSpan.getStart() < 0 || tokenSpan.getStart() > text.length() ||
@@ -72,7 +71,7 @@ public class TokenSample {
DetokenizationOperation[] operations = detokenizer.detokenize(tokens);
- List<Span> mergedTokenSpans = new ArrayList<Span>();
+ List<Span> mergedTokenSpans = new ArrayList<>();
for (int i = 0; i < operations.length; i++) {
@@ -173,7 +172,7 @@ public class TokenSample {
Span whitespaceTokenSpans[] = WhitespaceTokenizer.INSTANCE.tokenizePos(sampleString);
// Pre-allocate 20% for newly created tokens
- List<Span> realTokenSpans = new ArrayList<Span>((int) (whitespaceTokenSpans.length * 1.2d));
+ List<Span> realTokenSpans = new ArrayList<>((int) (whitespaceTokenSpans.length * 1.2d));
StringBuilder untaggedSampleString = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/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 42f4b34..7344ab2 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerCrossValidator.java
@@ -50,7 +50,8 @@ public class TokenizerCrossValidator {
*/
public void evaluate(ObjectStream<TokenSample> samples, int nFolds) throws IOException {
- CrossValidationPartitioner<TokenSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds);
+ CrossValidationPartitioner<TokenSample> partitioner =
+ new CrossValidationPartitioner<>(samples, nFolds);
while (partitioner.hasNext()) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerFactory.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerFactory.java
index 366e433..ba3d285 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerFactory.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerFactory.java
@@ -82,14 +82,11 @@ public class TokenizerFactory extends BaseToolFactory {
@Override
public void validateArtifactMap() throws InvalidFormatException {
-
- if (this.artifactProvider
- .getManifestProperty(USE_ALPHA_NUMERIC_OPTIMIZATION) == null)
+ if (this.artifactProvider.getManifestProperty(USE_ALPHA_NUMERIC_OPTIMIZATION) == null)
throw new InvalidFormatException(USE_ALPHA_NUMERIC_OPTIMIZATION
+ " is a mandatory property!");
- Object abbreviationsEntry = this.artifactProvider
- .getArtifact(ABBREVIATIONS_ENTRY_NAME);
+ Object abbreviationsEntry = this.artifactProvider.getArtifact(ABBREVIATIONS_ENTRY_NAME);
if (abbreviationsEntry != null && !(abbreviationsEntry instanceof Dictionary)) {
throw new InvalidFormatException("Abbreviations dictionary '" + abbreviationsEntry +
@@ -102,8 +99,9 @@ public class TokenizerFactory extends BaseToolFactory {
Map<String, Object> artifactMap = super.createArtifactMap();
// Abbreviations are optional
- if (abbreviationDictionary != null)
+ if (abbreviationDictionary != null) {
artifactMap.put(ABBREVIATIONS_ENTRY_NAME, abbreviationDictionary);
+ }
return artifactMap;
}
@@ -112,11 +110,13 @@ public class TokenizerFactory extends BaseToolFactory {
public Map<String, String> createManifestEntries() {
Map<String, String> manifestEntries = super.createManifestEntries();
- manifestEntries.put(USE_ALPHA_NUMERIC_OPTIMIZATION, Boolean.toString(isUseAlphaNumericOptmization()));
+ manifestEntries.put(USE_ALPHA_NUMERIC_OPTIMIZATION,
+ Boolean.toString(isUseAlphaNumericOptmization()));
// alphanumeric pattern is optional
- if (getAlphaNumericPattern() != null)
+ if (getAlphaNumericPattern() != null) {
manifestEntries.put(ALPHA_NUMERIC_PATTERN, getAlphaNumericPattern().pattern());
+ }
return manifestEntries;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/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 4444e78..adf9adb 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenizerME.java
@@ -179,26 +179,23 @@ public class TokenizerME extends AbstractTokenizer {
Span[] tokens = WhitespaceTokenizer.INSTANCE.tokenizePos(d);
newTokens.clear();
tokProbs.clear();
- for (int i = 0, il = tokens.length; i < il; i++) {
- Span s = tokens[i];
+ for (Span s : tokens) {
String tok = d.substring(s.getStart(), s.getEnd());
// Can't tokenize single characters
if (tok.length() < 2) {
newTokens.add(s);
tokProbs.add(1d);
- }
- else if (useAlphaNumericOptimization() && alphanumeric.matcher(tok).matches()) {
+ } else if (useAlphaNumericOptimization() && alphanumeric.matcher(tok).matches()) {
newTokens.add(s);
tokProbs.add(1d);
- }
- else {
+ } else {
int start = s.getStart();
int end = s.getEnd();
final int origStart = s.getStart();
double tokenProb = 1.0;
for (int j = origStart + 1; j < end; j++) {
double[] probs =
- model.eval(cg.getContext(tok, j - origStart));
+ model.eval(cg.getContext(tok, j - origStart));
String best = model.getBestOutcome(probs);
tokenProb *= probs[model.getIndex(best)];
if (best.equals(TokenizerME.SPLIT)) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
index deb24a1..fa7f741 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/lang/en/TokenSampleStream.java
@@ -61,17 +61,19 @@ public class TokenSampleStream implements Iterator<TokenSample> {
for (int ti = 0; ti < tokens.length; ti++) {
String token = tokens[ti];
String lastToken = ti - 1 >= 0 ? tokens[ti - 1] : "";
- if (token.equals("-LRB-")) {
- token = "(";
- }
- else if (token.equals("-LCB-")) {
- token = "{";
- }
- else if (token.equals("-RRB-")) {
- token = ")";
- }
- else if (token.equals("-RCB-")) {
- token = "}";
+ switch (token) {
+ case "-LRB-":
+ token = "(";
+ break;
+ case "-LCB-":
+ token = "{";
+ break;
+ case "-RRB-":
+ token = ")";
+ break;
+ case "-RCB-":
+ token = "}";
+ break;
}
if (sb.length() != 0) {
if (!alphaNumeric.matcher(token).find() || token.startsWith("'") || token.equalsIgnoreCase("n't")) {
@@ -100,7 +102,7 @@ public class TokenSampleStream implements Iterator<TokenSample> {
spans.add(new Span(length, length + token.length()));
length += token.length();
}
- //System.out.println();
+
try {
line = in.readLine();
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
index 20184ea..ace980a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/AbstractEventStream.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.util;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/CollectionObjectStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/CollectionObjectStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/CollectionObjectStream.java
index aa52978..700d1f3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/CollectionObjectStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/CollectionObjectStream.java
@@ -27,15 +27,11 @@ public class CollectionObjectStream<E> implements ObjectStream<E> {
public CollectionObjectStream(Collection<E> collection) {
this.collection = collection;
-
reset();
}
public E read() {
- if (iterator.hasNext())
- return iterator.next();
- else
- return null;
+ return iterator.hasNext() ? iterator.next() : null;
}
public void reset() {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/FilterObjectStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/FilterObjectStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/FilterObjectStream.java
index 003a09d..24ab86c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/FilterObjectStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/FilterObjectStream.java
@@ -33,8 +33,9 @@ public abstract class FilterObjectStream<S, T> implements ObjectStream<T> {
protected final ObjectStream<S> samples;
protected FilterObjectStream(ObjectStream<S> samples) {
- if (samples == null)
+ if (samples == null) {
throw new IllegalArgumentException("samples must not be null!");
+ }
this.samples = samples;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/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 0ee8fa5..f2fb5df 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ObjectStreamUtils.java
@@ -95,8 +95,9 @@ public class ObjectStreamUtils {
public static <T> ObjectStream<T> createObjectStream(final ObjectStream<T>... streams) {
for (ObjectStream<T> stream : streams) {
- if (stream == null)
+ if (stream == null) {
throw new NullPointerException("stream cannot be null");
+ }
}
return new ObjectStream<T>() {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
index eb3a410..8942437 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.util;
import java.io.BufferedReader;
@@ -37,11 +36,13 @@ public class PlainTextByLineStream implements ObjectStream<String> {
private BufferedReader in;
- public PlainTextByLineStream(InputStreamFactory inputStreamFactory, String charsetName) throws IOException {
+ public PlainTextByLineStream(InputStreamFactory inputStreamFactory,
+ String charsetName) throws IOException {
this(inputStreamFactory, Charset.forName(charsetName));
}
- public PlainTextByLineStream(InputStreamFactory inputStreamFactory, Charset charset) throws IOException {
+ public PlainTextByLineStream(InputStreamFactory inputStreamFactory,
+ Charset charset) throws IOException {
this.inputStreamFactory = inputStreamFactory;
this.channel = null;
this.encoding = charset.name();
@@ -56,23 +57,20 @@ public class PlainTextByLineStream implements ObjectStream<String> {
public void reset() throws IOException {
if (inputStreamFactory != null) {
- in = new BufferedReader(new InputStreamReader(inputStreamFactory.createInputStream(), encoding));
- }
- else if (channel == null) {
+ in = new BufferedReader(new InputStreamReader(inputStreamFactory.createInputStream(),
+ encoding));
+ } else if (channel == null) {
in.reset();
- }
- else {
+ } else {
channel.position(0);
in = new BufferedReader(Channels.newReader(channel, encoding));
}
}
public void close() throws IOException {
-
if (in != null && channel == null) {
in.close();
- }
- else if (channel != null) {
+ } else if (channel != null) {
channel.close();
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
index 828e99a..2cb86c0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/Sequence.java
@@ -30,24 +30,24 @@ public class Sequence implements Comparable<Sequence> {
/** Creates a new sequence of outcomes. */
public Sequence() {
- outcomes = new ArrayList<String>(1);
- probs = new ArrayList<Double>(1);
+ outcomes = new ArrayList<>(1);
+ probs = new ArrayList<>(1);
score = 0d;
}
public Sequence(Sequence s) {
- outcomes = new ArrayList<String>(s.outcomes.size() + 1);
+ outcomes = new ArrayList<>(s.outcomes.size() + 1);
outcomes.addAll(s.outcomes);
- probs = new ArrayList<Double>(s.probs.size() + 1);
+ probs = new ArrayList<>(s.probs.size() + 1);
probs.addAll(s.probs);
score = s.score;
}
public Sequence(Sequence s,String outcome, double p) {
- outcomes = new ArrayList<String>(s.outcomes.size() + 1);
+ outcomes = new ArrayList<>(s.outcomes.size() + 1);
outcomes.addAll(s.outcomes);
outcomes.add(outcome);
- probs = new ArrayList<Double>(s.probs.size() + 1);
+ probs = new ArrayList<>(s.probs.size() + 1);
probs.addAll(s.probs);
probs.add(p);
score = s.score + Math.log(p);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java b/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
index 20db24d..f0fe637 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/StringList.java
@@ -38,9 +38,7 @@ public class StringList implements Iterable<String> {
* @param singleToken one single token
*/
public StringList(String singleToken) {
- tokens = new String[] {
- singleToken.intern()
- };
+ tokens = new String[]{singleToken.intern()};
}
/**
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java b/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
index 43ac4df..6682ec0 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/StringUtil.java
@@ -73,7 +73,6 @@ public class StringUtil {
* @return lower cased String
*/
public static String toLowerCase(CharSequence string) {
-
char lowerCaseChars[] = new char[string.length()];
for (int i = 0; i < string.length(); i++) {
@@ -144,7 +143,6 @@ public class StringUtil {
* @return the distance
*/
public static int[][] levenshteinDistance(String wordForm, String lemma) {
-
int wordLength = wordForm.length();
int lemmaLength = lemma.length();
int cost;
@@ -238,7 +236,6 @@ public class StringUtil {
if (lemmaLength > 0 && (distance[wordFormLength][lemmaLength - 1]
== distance[wordFormLength][lemmaLength])) {
lemmaLength--;
- continue;
}
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/eval/CrossValidationPartitioner.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/eval/CrossValidationPartitioner.java b/opennlp-tools/src/main/java/opennlp/tools/util/eval/CrossValidationPartitioner.java
index b10ecdc..2de72d9 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/eval/CrossValidationPartitioner.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/eval/CrossValidationPartitioner.java
@@ -195,7 +195,7 @@ public class CrossValidationPartitioner<E> {
if (testSampleStream == null) {
sampleStream.reset();
- testSampleStream = new TestSampleStream<E>(sampleStream, numberOfPartitions, testIndex);
+ testSampleStream = new TestSampleStream<>(sampleStream, numberOfPartitions, testIndex);
}
return testSampleStream;
@@ -243,7 +243,7 @@ public class CrossValidationPartitioner<E> {
* @param numberOfPartitions
*/
public CrossValidationPartitioner(Collection<E> elements, int numberOfPartitions) {
- this(new CollectionObjectStream<E>(elements), numberOfPartitions);
+ this(new CollectionObjectStream<>(elements), numberOfPartitions);
}
/**
@@ -263,7 +263,7 @@ public class CrossValidationPartitioner<E> {
sampleStream.reset();
- TrainingSampleStream<E> trainingSampleStream = new TrainingSampleStream<E>(sampleStream,
+ TrainingSampleStream<E> trainingSampleStream = new TrainingSampleStream<>(sampleStream,
numberOfPartitions, testIndex);
testIndex++;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
index 1075d4c..cbf6ec3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/eval/Evaluator.java
@@ -38,8 +38,7 @@ public abstract class Evaluator<T> {
@SafeVarargs
public Evaluator(EvaluationMonitor<T>... aListeners) {
if (aListeners != null) {
- List<EvaluationMonitor<T>> listenersList = new ArrayList<>(
- aListeners.length);
+ List<EvaluationMonitor<T>> listenersList = new ArrayList<>(aListeners.length);
for (EvaluationMonitor<T> evaluationMonitor : aListeners) {
if (evaluationMonitor != null) {
listenersList.add(evaluationMonitor);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/eval/FMeasure.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/eval/FMeasure.java b/opennlp-tools/src/main/java/opennlp/tools/util/eval/FMeasure.java
index c784f87..ec02be2 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/eval/FMeasure.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/eval/FMeasure.java
@@ -134,18 +134,15 @@ public final class FMeasure {
*/
static int countTruePositives(final Object[] references, final Object[] predictions) {
- List<Object> predListSpans = new ArrayList<Object>(predictions.length);
+ List<Object> predListSpans = new ArrayList<>(predictions.length);
Collections.addAll(predListSpans, predictions);
int truePositives = 0;
Object matchedItem = null;
- for (int referenceIndex = 0; referenceIndex < references.length; referenceIndex++) {
- Object referenceName = references[referenceIndex];
-
- for (int predIndex = 0; predIndex < predListSpans.size(); predIndex++) {
-
- if (referenceName.equals(predListSpans.get(predIndex))) {
- matchedItem = predListSpans.get(predIndex);
+ for (Object referenceName : references) {
+ for (Object predListSpan : predListSpans) {
+ if (referenceName.equals(predListSpan)) {
+ matchedItem = predListSpan;
truePositives++;
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/ext/OSGiExtensionLoader.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/ext/OSGiExtensionLoader.java b/opennlp-tools/src/main/java/opennlp/tools/util/ext/OSGiExtensionLoader.java
index 6d4da8b..e7931f3 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/ext/OSGiExtensionLoader.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/ext/OSGiExtensionLoader.java
@@ -39,7 +39,6 @@ public class OSGiExtensionLoader implements BundleActivator {
public void start(BundleContext context) throws Exception {
instance = this;
this.context = context;
-
ExtensionLoader.setOSGiAvailable();
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AggregatedFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AggregatedFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AggregatedFeatureGenerator.java
index a2116d0..97c2f32 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AggregatedFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/AggregatedFeatureGenerator.java
@@ -46,7 +46,7 @@ public class AggregatedFeatureGenerator implements AdaptiveFeatureGenerator {
throw new IllegalArgumentException("null values in generators are not permitted!");
}
- this.generators = new ArrayList<AdaptiveFeatureGenerator>(generators.length);
+ this.generators = new ArrayList<>(generators.length);
Collections.addAll(this.generators, generators);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
index 0028ec1..cc55f1a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BigramNameFeatureGenerator.java
@@ -21,7 +21,8 @@ import java.util.List;
public class BigramNameFeatureGenerator implements AdaptiveFeatureGenerator {
- public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) {
+ public void createFeatures(List<String> features, String[] tokens, int index,
+ String[] previousOutcomes) {
String wc = FeatureGeneratorUtil.tokenFeature(tokens[index]);
//bi-gram features
if (index > 0) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
index ad5e64f..bad6be4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownCluster.java
@@ -30,7 +30,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
-import opennlp.tools.util.InvalidFormatException;
import opennlp.tools.util.model.ArtifactSerializer;
import opennlp.tools.util.model.SerializableArtifact;
@@ -49,8 +48,7 @@ public class BrownCluster implements SerializableArtifact {
public static class BrownClusterSerializer implements ArtifactSerializer<BrownCluster> {
- public BrownCluster create(InputStream in) throws IOException,
- InvalidFormatException {
+ public BrownCluster create(InputStream in) throws IOException {
return new BrownCluster(in);
}
@@ -70,7 +68,8 @@ public class BrownCluster implements SerializableArtifact {
*/
public BrownCluster(InputStream in) throws IOException {
- BufferedReader breader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
+ BufferedReader breader =
+ new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
String line;
while ((line = breader.readLine()) != null) {
String[] lineArray = tabPattern.split(line);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClasses.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClasses.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClasses.java
index caecb0d..0456de5 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClasses.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/BrownTokenClasses.java
@@ -39,12 +39,11 @@ public class BrownTokenClasses {
*/
public static List<String> getWordClasses(String token, BrownCluster brownLexicon) {
if (brownLexicon.lookupToken(token) == null) {
- return new ArrayList<String>(0);
+ return new ArrayList<>(0);
} else {
String brownClass = brownLexicon.lookupToken(token);
- List<String> pathLengthsList = new ArrayList<String>();
- pathLengthsList.add(brownClass.substring(0,
- Math.min(brownClass.length(), pathLengths[0])));
+ List<String> pathLengthsList = new ArrayList<>();
+ pathLengthsList.add(brownClass.substring(0, Math.min(brownClass.length(), pathLengths[0])));
for (int i = 1; i < pathLengths.length; i++) {
if (pathLengths[i - 1] < brownClass.length()) {
pathLengthsList.add(brownClass.substring(0,
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CharacterNgramFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CharacterNgramFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CharacterNgramFeatureGenerator.java
index 8c0edd9..d4b44cb 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CharacterNgramFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/CharacterNgramFeatureGenerator.java
@@ -46,12 +46,10 @@ public class CharacterNgramFeatureGenerator implements AdaptiveFeatureGenerator
}
public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) {
-
NGramModel model = new NGramModel();
model.add(tokens[index], minLength, maxLength);
for (StringList tokenList : model) {
-
if (tokenList.size() > 0) {
features.add("ng=" + StringUtil.toLowerCase(tokenList.getToken(0)));
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/GeneratorFactory.java
----------------------------------------------------------------------
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 31af680..bccbea2 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
@@ -25,6 +25,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -35,17 +36,17 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
-import opennlp.tools.dictionary.Dictionary;
-import opennlp.tools.util.InvalidFormatException;
-import opennlp.tools.util.ext.ExtensionLoader;
-import opennlp.tools.util.model.ArtifactSerializer;
-
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import opennlp.tools.dictionary.Dictionary;
+import opennlp.tools.util.InvalidFormatException;
+import opennlp.tools.util.ext.ExtensionLoader;
+import opennlp.tools.util.model.ArtifactSerializer;
+
/**
* Creates a set of feature generators based on a provided XML descriptor.
*
@@ -91,7 +92,7 @@ public class GeneratorFactory {
* an {@link AdaptiveFeatureGenerator} from an given XML {@link Element}
* which contains all necessary configuration if any.
*/
- static interface XmlFeatureGeneratorFactory {
+ interface XmlFeatureGeneratorFactory {
/**
* Creates an {@link AdaptiveFeatureGenerator} from a the describing
@@ -115,17 +116,14 @@ public class GeneratorFactory {
public AdaptiveFeatureGenerator create(Element generatorElement,
FeatureGeneratorResourceProvider resourceManager) throws InvalidFormatException {
- Collection<AdaptiveFeatureGenerator> aggregatedGenerators =
- new LinkedList<AdaptiveFeatureGenerator>();
+ Collection<AdaptiveFeatureGenerator> aggregatedGenerators = new LinkedList<>();
NodeList childNodes = generatorElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
-
if (childNode instanceof Element) {
Element aggregatedGeneratorElement = (Element) childNode;
-
aggregatedGenerators.add(
GeneratorFactory.createGenerator(aggregatedGeneratorElement, resourceManager));
}
@@ -216,7 +214,7 @@ public class GeneratorFactory {
}
/**
- * @see DefinitionFeatureGenerator
+ * @see DefinitionFeatureGeneratorFactory
*/
static class DefinitionFeatureGeneratorFactory implements XmlFeatureGeneratorFactory {
@@ -435,7 +433,7 @@ public class GeneratorFactory {
// Default to true.
boolean generateWordAndClassFeature = true;
- if (attribute != "") {
+ if (!Objects.equals(attribute, "")) {
// Anything other than "true" sets it to false.
if (!"true".equalsIgnoreCase(attribute)) {
generateWordAndClassFeature = false;
@@ -627,8 +625,7 @@ public class GeneratorFactory {
}
}
- private static Map<String, XmlFeatureGeneratorFactory> factories =
- new HashMap<String, XmlFeatureGeneratorFactory>();
+ private static Map<String, XmlFeatureGeneratorFactory> factories = new HashMap<>();
static {
AggregatedFeatureGeneratorFactory.register(factories);
@@ -679,7 +676,7 @@ public class GeneratorFactory {
}
private static org.w3c.dom.Document createDOM(InputStream xmlDescriptorIn)
- throws IOException, InvalidFormatException {
+ throws IOException {
DocumentBuilderFactory documentBuilderFacoty = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder;
@@ -719,7 +716,7 @@ public class GeneratorFactory {
* {@link InputStream}
*/
public static AdaptiveFeatureGenerator create(InputStream xmlDescriptorIn,
- FeatureGeneratorResourceProvider resourceManager) throws IOException, InvalidFormatException {
+ FeatureGeneratorResourceProvider resourceManager) throws IOException {
org.w3c.dom.Document xmlDescriptorDOM = createDOM(xmlDescriptorIn);
@@ -729,7 +726,7 @@ public class GeneratorFactory {
}
public static Map<String, ArtifactSerializer<?>> extractCustomArtifactSerializerMappings(
- InputStream xmlDescriptorIn) throws IOException, InvalidFormatException {
+ InputStream xmlDescriptorIn) throws IOException {
Map<String, ArtifactSerializer<?>> mapping = new HashMap<>();
@@ -772,9 +769,9 @@ public class GeneratorFactory {
* @throws InvalidFormatException if xml is not well-formed
*/
public static List<Element> getDescriptorElements(InputStream xmlDescriptorIn)
- throws IOException, InvalidFormatException {
+ throws IOException {
- List<Element> elements = new ArrayList<Element>();
+ List<Element> elements = new ArrayList<>();
org.w3c.dom.Document xmlDescriptorDOM = createDOM(xmlDescriptorIn);
XPath xPath = XPathFactory.newInstance().newXPath();
NodeList allElements;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/OutcomePriorFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/OutcomePriorFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/OutcomePriorFeatureGenerator.java
index c2281f5..7ea7ff4 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/OutcomePriorFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/OutcomePriorFeatureGenerator.java
@@ -25,10 +25,10 @@ import java.util.List;
*/
public class OutcomePriorFeatureGenerator implements AdaptiveFeatureGenerator {
- public static final String OUTCOME_PRIOR_FEATURE = "def";
+ private static final String OUTCOME_PRIOR_FEATURE = "def";
public void createFeatures(List<String> features, String[] tokens, int index,
- String[] previousOutcomes) {
+ String[] previousOutcomes) {
features.add(OUTCOME_PRIOR_FEATURE);
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PrefixFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PrefixFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PrefixFeatureGenerator.java
index 8d433b6..8cdd48f 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PrefixFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PrefixFeatureGenerator.java
@@ -23,9 +23,9 @@ public class PrefixFeatureGenerator implements AdaptiveFeatureGenerator {
private static final int PREFIX_LENGTH = 4;
- public static String[] getPrefixes(String lex) {
+ private static String[] getPrefixes(String lex) {
String[] prefs = new String[PREFIX_LENGTH];
- for (int li = 0, ll = PREFIX_LENGTH; li < ll; li++) {
+ for (int li = 0; li < PREFIX_LENGTH; li++) {
prefs[li] = lex.substring(0, Math.min(li + 1, lex.length()));
}
return prefs;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PreviousTwoMapFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PreviousTwoMapFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PreviousTwoMapFeatureGenerator.java
index bcb6aec..114074b 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PreviousTwoMapFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/PreviousTwoMapFeatureGenerator.java
@@ -35,7 +35,8 @@ public class PreviousTwoMapFeatureGenerator implements AdaptiveFeatureGenerator
public void createFeatures(List<String> features, String[] tokens, int index, String[] preds) {
if (index > 0) {
- features.add("ppd=" + previousMap.get(tokens[index]) + "," + previousMap.get(tokens[index - 1]));
+ features.add("ppd=" + previousMap.get(tokens[index]) + "," +
+ previousMap.get(tokens[index - 1]));
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/SuffixFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/SuffixFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/SuffixFeatureGenerator.java
index 815cc9e..a17fd47 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/SuffixFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/SuffixFeatureGenerator.java
@@ -25,7 +25,7 @@ public class SuffixFeatureGenerator implements AdaptiveFeatureGenerator {
public static String[] getSuffixes(String lex) {
String[] suffs = new String[SUFFIX_LENGTH];
- for (int li = 0, ll = SUFFIX_LENGTH; li < ll; li++) {
+ for (int li = 0; li < SUFFIX_LENGTH; li++) {
suffs[li] = lex.substring(Math.max(lex.length() - li - 1, 0));
}
return suffs;
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
index 7358d24..a82fe4a 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/TokenClassFeatureGenerator.java
@@ -45,7 +45,8 @@ public class TokenClassFeatureGenerator implements AdaptiveFeatureGenerator {
features.add(TOKEN_CLASS_PREFIX + "=" + wordClass);
if (generateWordAndClassFeature) {
- features.add(TOKEN_AND_CLASS_PREFIX + "=" + StringUtil.toLowerCase(tokens[index]) + "," + wordClass);
+ features.add(TOKEN_AND_CLASS_PREFIX + "=" + StringUtil.toLowerCase(tokens[index]) +
+ "," + wordClass);
}
}
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WindowFeatureGenerator.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WindowFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WindowFeatureGenerator.java
index cd3d931..2fc4788 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WindowFeatureGenerator.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WindowFeatureGenerator.java
@@ -91,7 +91,7 @@ public class WindowFeatureGenerator implements AdaptiveFeatureGenerator {
for (int i = 1; i < prevWindowSize + 1; i++) {
if (index - i >= 0) {
- List<String> prevFeatures = new ArrayList<String>();
+ List<String> prevFeatures = new ArrayList<>();
generator.createFeatures(prevFeatures, tokens, index - i, preds);
@@ -105,7 +105,7 @@ public class WindowFeatureGenerator implements AdaptiveFeatureGenerator {
for (int i = 1; i < nextWindowSize + 1; i++) {
if (i + index < tokens.length) {
- List<String> nextFeatures = new ArrayList<String>();
+ List<String> nextFeatures = new ArrayList<>();
generator.createFeatures(nextFeatures, tokens, index + i, preds);
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WordClusterDictionary.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WordClusterDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WordClusterDictionary.java
index 07109fc..10f16ee 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WordClusterDictionary.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/featuregen/WordClusterDictionary.java
@@ -29,7 +29,6 @@ import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import opennlp.tools.util.InvalidFormatException;
import opennlp.tools.util.model.ArtifactSerializer;
import opennlp.tools.util.model.SerializableArtifact;
@@ -37,18 +36,16 @@ public class WordClusterDictionary implements SerializableArtifact {
public static class WordClusterDictionarySerializer implements ArtifactSerializer<WordClusterDictionary> {
- public WordClusterDictionary create(InputStream in) throws IOException,
- InvalidFormatException {
+ public WordClusterDictionary create(InputStream in) throws IOException {
return new WordClusterDictionary(in);
}
- public void serialize(WordClusterDictionary artifact, OutputStream out)
- throws IOException {
+ public void serialize(WordClusterDictionary artifact, OutputStream out) throws IOException {
artifact.serialize(out);
}
}
- private Map<String, String> tokenToClusterMap = new HashMap<String, String>();
+ private Map<String, String> tokenToClusterMap = new HashMap<>();
/**
* Read word2vec and clark clustering style lexicons.
@@ -56,9 +53,7 @@ public class WordClusterDictionary implements SerializableArtifact {
* @throws IOException the io exception
*/
public WordClusterDictionary(InputStream in) throws IOException {
-
BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
-
String line;
while ((line = reader.readLine()) != null) {
String parts[] = line.split(" ");
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java
----------------------------------------------------------------------
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 22adf07..ed4e2bf 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
@@ -81,8 +81,9 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
private BaseModel(String componentName, boolean isLoadedFromSerialized) {
this.isLoadedFromSerialized = isLoadedFromSerialized;
- if (componentName == null)
+ if (componentName == null) {
throw new IllegalArgumentException("componentName must not be null!");
+ }
this.componentName = componentName;
}
@@ -108,8 +109,9 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
this(componentName, false);
- if (languageCode == null)
- throw new IllegalArgumentException("languageCode must not be null!");
+ if (languageCode == null) {
+ throw new IllegalArgumentException("languageCode must not be null!");
+ }
createBaseArtifactSerializers(artifactSerializers);
@@ -117,8 +119,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable {
manifest.setProperty(MANIFEST_VERSION_PROPERTY, "1.0");
manifest.setProperty(LANGUAGE_PROPERTY, languageCode);
manifest.setProperty(VERSION_PROPERTY, Version.currentVersion().toString());
- manifest.setProperty(TIMESTAMP_PROPERTY,
- Long.toString(System.currentTimeMillis()));
+ manifest.setProperty(TIMESTAMP_PROPERTY, Long.toString(System.currentTimeMillis()));
manifest.setProperty(COMPONENT_NAME_PROPERTY, componentName);
if (manifestInfoEntries != null) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/model/DictionarySerializer.java
----------------------------------------------------------------------
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 afd374b..9b59112 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
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.util.model;
import java.io.IOException;
@@ -24,17 +23,14 @@ import java.io.OutputStream;
import java.util.Map;
import opennlp.tools.dictionary.Dictionary;
-import opennlp.tools.util.InvalidFormatException;
class DictionarySerializer implements ArtifactSerializer<Dictionary> {
- public Dictionary create(InputStream in) throws IOException,
- InvalidFormatException {
+ public Dictionary create(InputStream in) throws IOException {
return new Dictionary(in);
}
- public void serialize(Dictionary dictionary, OutputStream out)
- throws IOException {
+ public void serialize(Dictionary dictionary, OutputStream out) throws IOException {
dictionary.serialize(out);
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/model/GenericModelSerializer.java
----------------------------------------------------------------------
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 d55b64e..516bef3 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
@@ -15,7 +15,6 @@
* limitations under the License.
*/
-
package opennlp.tools.util.model;
import java.io.IOException;
@@ -26,12 +25,10 @@ import java.util.Map;
import opennlp.tools.ml.model.AbstractModel;
import opennlp.tools.ml.model.BinaryFileDataReader;
import opennlp.tools.ml.model.GenericModelReader;
-import opennlp.tools.util.InvalidFormatException;
public class GenericModelSerializer implements ArtifactSerializer<AbstractModel> {
- public AbstractModel create(InputStream in) throws IOException,
- InvalidFormatException {
+ public AbstractModel create(InputStream in) throws IOException {
return new GenericModelReader(new BinaryFileDataReader(in)).getModel();
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/model/ModelUtil.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/ModelUtil.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/ModelUtil.java
index 48bfa58..902c07c 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/model/ModelUtil.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/model/ModelUtil.java
@@ -57,11 +57,13 @@ public final class ModelUtil {
public static void writeModel(MaxentModel model, final OutputStream out)
throws IOException, IllegalArgumentException {
- if (model == null)
+ if (model == null) {
throw new IllegalArgumentException("model parameter must not be null!");
+ }
- if (out == null)
+ if (out == null) {
throw new IllegalArgumentException("out parameter must not be null!");
+ }
GenericModelWriter modelWriter = new GenericModelWriter((AbstractModel) model,
new DataOutputStream(new OutputStream() {
@@ -88,7 +90,7 @@ public final class ModelUtil {
if (expectedOutcomes.length == model.getNumOutcomes()) {
- Set<String> expectedOutcomesSet = new HashSet<String>();
+ Set<String> expectedOutcomesSet = new HashSet<>();
expectedOutcomesSet.addAll(Arrays.asList(expectedOutcomes));
for (int i = 0; i < model.getNumOutcomes(); i++) {
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/main/java/opennlp/tools/util/model/PropertiesSerializer.java
----------------------------------------------------------------------
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 9fef59e..5d03413 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
@@ -24,15 +24,11 @@ import java.io.OutputStream;
import java.util.Map;
import java.util.Properties;
-import opennlp.tools.util.InvalidFormatException;
-
class PropertiesSerializer implements ArtifactSerializer<Properties> {
- public Properties create(InputStream in) throws IOException,
- InvalidFormatException {
+ public Properties create(InputStream in) throws IOException {
Properties properties = new Properties();
properties.load(in);
-
return properties;
}
http://git-wip-us.apache.org/repos/asf/opennlp/blob/ccc58b48/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkSampleStreamTest.java
----------------------------------------------------------------------
diff --git a/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkSampleStreamTest.java b/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkSampleStreamTest.java
index 65a1e2e..529a27e 100644
--- a/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkSampleStreamTest.java
+++ b/opennlp-tools/src/test/java/opennlp/tools/chunker/ChunkSampleStreamTest.java
@@ -17,12 +17,10 @@
package opennlp.tools.chunker;
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import org.junit.Assert;
import org.junit.Test;
import opennlp.tools.util.MockInputStreamFactory;
@@ -34,58 +32,57 @@ public class ChunkSampleStreamTest {
@Test
public void testReadingEvents() throws IOException {
- StringBuilder sample = new StringBuilder();
+ String sample = "word11 tag11 pred11" +
+ '\n' +
+ "word12 tag12 pred12" +
+ '\n' +
+ "word13 tag13 pred13" +
+ '\n' +
+ '\n' +
+ "word21 tag21 pred21" +
+ '\n' +
+ "word22 tag22 pred22" +
+ '\n' +
+ "word23 tag23 pred23" +
+ '\n';
// First sample sentence
- sample.append("word11 tag11 pred11");
- sample.append('\n');
- sample.append("word12 tag12 pred12");
- sample.append('\n');
- sample.append("word13 tag13 pred13");
- sample.append('\n');
// Start next sample sentence
- sample.append('\n');
// Second sample sentence
- sample.append("word21 tag21 pred21");
- sample.append('\n');
- sample.append("word22 tag22 pred22");
- sample.append('\n');
- sample.append("word23 tag23 pred23");
- sample.append('\n');
ObjectStream<String> stringStream = new PlainTextByLineStream(
- new MockInputStreamFactory(sample.toString()), UTF_8);
+ new MockInputStreamFactory(sample), StandardCharsets.UTF_8);
ObjectStream<ChunkSample> chunkStream = new ChunkSampleStream(stringStream);
// read first sample
ChunkSample firstSample = chunkStream.read();
- assertEquals("word11", firstSample.getSentence()[0]);
- assertEquals("tag11", firstSample.getTags()[0]);
- assertEquals("pred11", firstSample.getPreds()[0]);
- assertEquals("word12", firstSample.getSentence()[1]);
- assertEquals("tag12", firstSample.getTags()[1]);
- assertEquals("pred12", firstSample.getPreds()[1]);
- assertEquals("word13", firstSample.getSentence()[2]);
- assertEquals("tag13", firstSample.getTags()[2]);
- assertEquals("pred13", firstSample.getPreds()[2]);
+ Assert.assertEquals("word11", firstSample.getSentence()[0]);
+ Assert.assertEquals("tag11", firstSample.getTags()[0]);
+ Assert.assertEquals("pred11", firstSample.getPreds()[0]);
+ Assert.assertEquals("word12", firstSample.getSentence()[1]);
+ Assert.assertEquals("tag12", firstSample.getTags()[1]);
+ Assert.assertEquals("pred12", firstSample.getPreds()[1]);
+ Assert.assertEquals("word13", firstSample.getSentence()[2]);
+ Assert.assertEquals("tag13", firstSample.getTags()[2]);
+ Assert.assertEquals("pred13", firstSample.getPreds()[2]);
// read second sample
ChunkSample secondSample = chunkStream.read();
- assertEquals("word21", secondSample.getSentence()[0]);
- assertEquals("tag21", secondSample.getTags()[0]);
- assertEquals("pred21", secondSample.getPreds()[0]);
- assertEquals("word22", secondSample.getSentence()[1]);
- assertEquals("tag22", secondSample.getTags()[1]);
- assertEquals("pred22", secondSample.getPreds()[1]);
- assertEquals("word23", secondSample.getSentence()[2]);
- assertEquals("tag23", secondSample.getTags()[2]);
- assertEquals("pred23", secondSample.getPreds()[2]);
-
- assertNull(chunkStream.read());
+ Assert.assertEquals("word21", secondSample.getSentence()[0]);
+ Assert.assertEquals("tag21", secondSample.getTags()[0]);
+ Assert.assertEquals("pred21", secondSample.getPreds()[0]);
+ Assert.assertEquals("word22", secondSample.getSentence()[1]);
+ Assert.assertEquals("tag22", secondSample.getTags()[1]);
+ Assert.assertEquals("pred22", secondSample.getPreds()[1]);
+ Assert.assertEquals("word23", secondSample.getSentence()[2]);
+ Assert.assertEquals("tag23", secondSample.getTags()[2]);
+ Assert.assertEquals("pred23", secondSample.getPreds()[2]);
+
+ Assert.assertNull(chunkStream.read());
chunkStream.close();
}