From f2107165a1cb455ae62fa3cd190ef2fdc7b98bd0 Mon Sep 17 00:00:00 2001 From: smarthi Date: Tue, 20 Dec 2016 01:47:04 -0500 Subject: [PATCH] OPENNLP-871: Cleanup code base for release --- .../builder/MorfologikDictionayBuilder.java | 4 +- .../builder/XMLDictionaryToTableTool.java | 8 ++-- .../lemmatizer/MorfologikLemmatizer.java | 25 ++++++------ .../tagdict/MorfologikPOSTaggerFactory.java | 18 +++------ .../tagdict/MorfologikTagDictionary.java | 2 +- .../opennlp/tools/chunker/ChunkSample.java | 14 +++---- .../chunker/ChunkSampleSequenceStream.java | 2 +- .../java/opennlp/tools/chunker/Chunker.java | 8 ++-- .../chunker/ChunkerContextGenerator.java | 2 +- .../tools/chunker/ChunkerCrossValidator.java | 6 +-- .../tools/chunker/ChunkerEventStream.java | 2 +- .../opennlp/tools/chunker/ChunkerFactory.java | 4 +- .../java/opennlp/tools/chunker/ChunkerME.java | 6 +-- .../opennlp/tools/cmdline/ArgumentParser.java | 30 +++++++------- .../main/java/opennlp/tools/cmdline/CLI.java | 4 +- .../cmdline/DetailedFMeasureListener.java | 8 ++-- .../tools/cmdline/EvaluationErrorPrinter.java | 14 +++---- .../tools/cmdline/GenerateManualTool.java | 2 +- .../opennlp/tools/cmdline/ModelLoader.java | 3 +- .../tools/cmdline/StreamFactoryRegistry.java | 9 ++--- .../chunker/ChunkerCrossValidatorTool.java | 2 +- .../cmdline/chunker/ChunkerEvaluatorTool.java | 2 +- .../tools/cmdline/chunker/ChunkerMETool.java | 2 +- .../DoccatFineGrainedReportListener.java | 38 +++++++++--------- .../tools/cmdline/doccat/DoccatTool.java | 2 +- .../cmdline/doccat/DoccatTrainerTool.java | 3 +- .../entitylinker/EntityLinkerTool.java | 2 +- .../LemmatizerFineGrainedReportListener.java | 36 ++++++++--------- .../cmdline/lemmatizer/LemmatizerMETool.java | 2 +- .../cmdline/namefind/TokenNameFinderTool.java | 2 +- .../tools/cmdline/postag/POSModelLoader.java | 5 +-- .../POSTaggerFineGrainedReportListener.java | 39 +++++++++---------- .../tools/cmdline/postag/POSTaggerTool.java | 2 +- .../cmdline/postag/POSTaggerTrainerTool.java | 26 +++++++------ .../tokenizer/CommandLineTokenizer.java | 4 +- .../opennlp/tools/dictionary/Dictionary.java | 11 ++---- .../java/opennlp/tools/dictionary/Index.java | 2 +- .../dictionary/serializer/Attributes.java | 2 +- .../serializer/DictionarySerializer.java | 14 +++---- .../doccat/BagOfWordsFeatureGenerator.java | 2 +- .../tools/doccat/DoccatCrossValidator.java | 2 +- .../opennlp/tools/doccat/DoccatFactory.java | 3 +- .../opennlp/tools/doccat/DoccatModel.java | 6 +-- .../DocumentCategorizerContextGenerator.java | 2 +- .../tools/doccat/DocumentCategorizerME.java | 9 ++--- .../opennlp/tools/doccat/DocumentSample.java | 2 +- .../tools/doccat/NGramFeatureGenerator.java | 2 +- .../opennlp/tools/entitylinker/BaseLink.java | 10 +---- .../tools/entitylinker/LinkedSpan.java | 8 +--- .../formats/BioNLP2004NameSampleStream.java | 6 +-- .../formats/Conll02NameSampleStream.java | 8 ++-- .../formats/Conll03NameSampleStream.java | 11 +++--- .../tools/formats/ConllXPOSSampleStream.java | 4 +- .../tools/formats/ad/ADChunkSampleStream.java | 6 +-- .../tools/formats/ad/ADNameSampleStream.java | 19 ++++----- .../tools/formats/ad/ADPOSSampleStream.java | 8 ++-- .../formats/ad/ADPOSSampleStreamFactory.java | 4 +- .../formats/ad/ADSentenceSampleStream.java | 2 +- .../ad/ADSentenceSampleStreamFactory.java | 5 +-- .../tools/formats/ad/ADSentenceStream.java | 13 ++----- .../formats/brat/AnnotationConfiguration.java | 7 +--- .../formats/brat/BratAnnotationStream.java | 3 +- .../formats/brat/BratDocumentStream.java | 4 +- .../formats/brat/BratNameSampleStream.java | 8 ++-- .../AbstractToSentenceSampleStream.java | 2 +- .../convert/ParseToPOSSampleStream.java | 4 +- .../DefaultLemmatizerContextGenerator.java | 6 +-- .../lemmatizer/DictionaryLemmatizer.java | 6 +-- .../opennlp/tools/lemmatizer/LemmaSample.java | 12 +++--- .../lemmatizer/LemmaSampleEventStream.java | 2 +- .../lemmatizer/LemmaSampleSequenceStream.java | 2 +- .../tools/lemmatizer/LemmaSampleStream.java | 10 ++--- .../opennlp/tools/lemmatizer/Lemmatizer.java | 2 +- .../LemmatizerContextGenerator.java | 2 +- .../tools/lemmatizer/LemmatizerFactory.java | 4 +- .../tools/lemmatizer/LemmatizerME.java | 6 +-- .../java/opennlp/tools/ml/TrainerFactory.java | 8 ++-- .../opennlp/tools/ml/maxent/DataStream.java | 4 +- .../java/opennlp/tools/ml/maxent/GIS.java | 6 +-- .../tools/ml/maxent/RealBasicEventStream.java | 2 +- .../ml/maxent/io/BinaryGISModelWriter.java | 2 +- .../tools/ml/maxent/io/GISModelWriter.java | 9 ++--- .../ml/maxent/io/OldFormatGISModelReader.java | 6 +-- .../ml/maxent/io/PlainTextGISModelWriter.java | 6 +-- .../io/SuffixSensitiveGISModelReader.java | 3 +- .../quasinewton/ParallelNegLogLikelihood.java | 4 +- .../opennlp/tools/ml/model/MaxentModel.java | 18 ++++----- .../tools/ml/model/OnePassDataIndexer.java | 14 +++---- .../java/opennlp/tools/ml/model/Prior.java | 6 +-- .../tools/ml/model/SequenceStream.java | 2 +- .../tools/ml/model/TwoPassDataIndexer.java | 15 +++---- .../tools/ml/naivebayes/LogProbabilities.java | 2 +- .../tools/ml/naivebayes/NaiveBayesModel.java | 8 ++-- .../ml/naivebayes/NaiveBayesModelWriter.java | 6 +-- .../ml/naivebayes/NaiveBayesTrainer.java | 2 +- .../PlainTextNaiveBayesModelWriter.java | 6 +-- .../tools/ml/naivebayes/Probabilities.java | 6 +-- .../opennlp/tools/namefind/BilouCodec.java | 5 +-- .../java/opennlp/tools/namefind/BioCodec.java | 7 ++-- .../tools/namefind/DictionaryNameFinder.java | 2 +- .../tools/namefind/DocumentNameFinder.java | 2 +- .../tools/namefind/NameContextGenerator.java | 6 +-- .../tools/namefind/NameFinderEventStream.java | 7 ++-- .../opennlp/tools/namefind/NameFinderME.java | 13 +++---- .../opennlp/tools/namefind/NameSample.java | 8 ++-- .../namefind/NameSampleSequenceStream.java | 6 +-- .../tools/namefind/NameSampleTypeFilter.java | 6 +-- .../namefind/RegexNameFinderFactory.java | 6 +-- .../tools/namefind/TokenNameFinder.java | 4 +- .../TokenNameFinderCrossValidator.java | 6 +-- .../namefind/TokenNameFinderEvaluator.java | 8 +--- .../tools/namefind/TokenNameFinderModel.java | 19 ++++----- .../java/opennlp/tools/ngram/NGramModel.java | 2 +- .../tools/parser/AbstractBottomUpParser.java | 10 ++--- .../parser/AbstractParserEventStream.java | 14 +++---- .../tools/parser/ChunkSampleStream.java | 8 ++-- .../java/opennlp/tools/parser/GapLabeler.java | 2 +- .../java/opennlp/tools/parser/HeadRules.java | 4 +- .../main/java/opennlp/tools/parser/Parse.java | 17 ++++---- .../java/opennlp/tools/parser/Parser.java | 4 +- .../tools/parser/ParserChunkerFactory.java | 2 +- .../ParserChunkerSequenceValidator.java | 3 +- .../tools/parser/ParserCrossValidator.java | 6 +-- .../opennlp/tools/parser/ParserEvaluator.java | 4 +- .../opennlp/tools/parser/ParserModel.java | 12 +++--- .../chunking/BuildContextGenerator.java | 2 +- .../chunking/CheckContextGenerator.java | 2 +- .../opennlp/tools/parser/chunking/Parser.java | 22 +++++------ .../parser/chunking/ParserEventStream.java | 39 ++++++++++--------- .../tools/parser/lang/en/HeadRules.java | 9 ++--- .../lang/es/AncoraSpanishHeadRules.java | 9 ++--- .../postag/DefaultPOSSequenceValidator.java | 6 +-- .../tools/postag/MutableTagDictionary.java | 4 +- .../tools/postag/POSContextGenerator.java | 2 +- .../java/opennlp/tools/postag/POSTagger.java | 10 ++--- .../tools/postag/POSTaggerCrossValidator.java | 2 +- .../opennlp/tools/postag/TagDictionary.java | 2 +- .../sentdetect/EndOfSentenceScanner.java | 8 ++-- .../tools/sentdetect/SDContextGenerator.java | 2 +- .../tools/sentdetect/SentenceDetector.java | 4 +- .../opennlp/tools/stemmer/PorterStemmer.java | 35 ++++++++--------- .../java/opennlp/tools/stemmer/Stemmer.java | 2 +- .../tools/tokenize/TokenContextGenerator.java | 2 +- .../opennlp/tools/tokenize/Tokenizer.java | 4 +- .../util/BeamSearchContextGenerator.java | 2 +- .../main/java/opennlp/tools/util/Heap.java | 16 ++++---- .../tools/util/TrainingParameters.java | 6 +-- .../opennlp/tools/util/model/BaseModel.java | 18 ++++----- 148 files changed, 494 insertions(+), 621 deletions(-) diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/builder/MorfologikDictionayBuilder.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/builder/MorfologikDictionayBuilder.java index dbbca4d41..54cb95cda 100644 --- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/builder/MorfologikDictionayBuilder.java +++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/builder/MorfologikDictionayBuilder.java @@ -17,12 +17,10 @@ package opennlp.morfologik.builder; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Path; import java.util.Properties; - import morfologik.stemming.DictionaryMetadata; import morfologik.stemming.EncoderType; import morfologik.tools.DictCompile; @@ -90,7 +88,7 @@ public Path build(Path input) throws Exception { } Properties createProperties(Charset encoding, String separator, - EncoderType encoderType) throws FileNotFoundException, IOException { + EncoderType encoderType) throws IOException { Properties properties = new Properties(); properties.setProperty("fsa.dict.separator", separator); diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java index 0e7f2d58e..ef6668e6f 100644 --- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java +++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/cmdline/builder/XMLDictionaryToTableTool.java @@ -59,7 +59,7 @@ public void run(String[] args) { CmdLineUtil.checkInputFile("dictionary input file", dictInFile); CmdLineUtil.checkOutputFile("dictionary output file", dictOutFile); - POSDictionary tagDictionary = null; + POSDictionary tagDictionary; try { tagDictionary = POSDictionary.create(new FileInputStream(dictInFile)); } catch (IOException e) { @@ -116,12 +116,10 @@ private boolean valid(String word, String tag) { } private String createEntry(String word, String tag) { - - String entry = "" + SEPARATOR +// base + + return "" + SEPARATOR +// base word + SEPARATOR + tag; - - return entry; } } diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/lemmatizer/MorfologikLemmatizer.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/lemmatizer/MorfologikLemmatizer.java index 2090ce596..2798e4287 100644 --- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/lemmatizer/MorfologikLemmatizer.java +++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/lemmatizer/MorfologikLemmatizer.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; import morfologik.stemming.Dictionary; @@ -35,19 +37,18 @@ public class MorfologikLemmatizer implements DictionaryLemmatizer { private IStemmer dictLookup; - public final Set constantTags = new HashSet(Arrays.asList( - "NNP", "NP00000")); + public final Set constantTags = new HashSet<>(Arrays.asList("NNP", "NP00000")); public MorfologikLemmatizer(Path dictionaryPath) throws IllegalArgumentException, IOException { dictLookup = new DictionaryLookup(Dictionary.read(dictionaryPath)); } - private HashMap, String> getLemmaTagsDict(String word) { + private Map, String> getLemmaTagsDict(String word) { List wdList = dictLookup.lookup(word); - HashMap, String> dictMap = new HashMap, String>(); + Map, String> dictMap = new HashMap<>(); for (WordData wd : wdList) { - List wordLemmaTags = new ArrayList(); + List wordLemmaTags = new ArrayList<>(); wordLemmaTags.add(word); wordLemmaTags.add(wd.getTag().toString()); dictMap.put(wordLemmaTags, wd.getStem().toString()); @@ -56,7 +57,7 @@ private HashMap, String> getLemmaTagsDict(String word) { } private List getDictKeys(String word, String postag) { - List keys = new ArrayList(); + List keys = new ArrayList<>(); if (constantTags.contains(postag)) { keys.addAll(Arrays.asList(word, postag)); } else { @@ -65,8 +66,8 @@ private List getDictKeys(String word, String postag) { return keys; } - private HashMap, String> getDictMap(String word, String postag) { - HashMap, String> dictMap = new HashMap, String>(); + private Map, String> getDictMap(String word, String postag) { + Map, String> dictMap; if (constantTags.contains(postag)) { dictMap = this.getLemmaTagsDict(word); @@ -77,16 +78,16 @@ private HashMap, String> getDictMap(String word, String postag) { } public String lemmatize(String word, String postag) { - String lemma = null; + String lemma; List keys = this.getDictKeys(word, postag); - HashMap, String> dictMap = this.getDictMap(word, postag); + Map, String> dictMap = this.getDictMap(word, postag); // lookup lemma as value of the map String keyValue = dictMap.get(keys); if (keyValue != null) { lemma = keyValue; - } else if (keyValue == null && constantTags.contains(postag)) { + } else if (constantTags.contains(postag)) { lemma = word; - } else if (keyValue == null && word.toUpperCase() == word) { + } else if (Objects.equals(word.toUpperCase(), word)) { lemma = word; } else { lemma = word.toLowerCase(); diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java index 93d6c610f..9a6abc997 100644 --- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java +++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikPOSTaggerFactory.java @@ -26,12 +26,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; - import morfologik.stemming.DictionaryMetadata; import opennlp.tools.dictionary.Dictionary; import opennlp.tools.postag.POSTaggerFactory; import opennlp.tools.postag.TagDictionary; -import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.model.ArtifactSerializer; import opennlp.tools.util.model.ModelUtil; @@ -53,8 +51,7 @@ public class MorfologikPOSTaggerFactory extends POSTaggerFactory { public MorfologikPOSTaggerFactory() { } - public TagDictionary createTagDictionary(File dictionary) - throws InvalidFormatException, FileNotFoundException, IOException { + public TagDictionary createTagDictionary(File dictionary) throws IOException { if(!dictionary.canRead()) { throw new FileNotFoundException("Could not read dictionary: " + dictionary.getAbsolutePath()); @@ -87,9 +84,9 @@ public TagDictionary getTagDictionary() { if (artifactProvider != null) { Object obj = artifactProvider.getArtifact(MORFOLOGIK_POSDICT); if (obj != null) { - byte[] data = (byte[]) artifactProvider + byte[] data = artifactProvider .getArtifact(MORFOLOGIK_POSDICT); - byte[] info = (byte[]) artifactProvider + byte[] info = artifactProvider .getArtifact(MORFOLOGIK_DICT_INFO); try { @@ -121,7 +118,7 @@ public TagDictionary createEmptyTagDictionary() { @Override public TagDictionary createTagDictionary(InputStream in) - throws InvalidFormatException, IOException { + throws IOException { throw new UnsupportedOperationException( "Morfologik POS Tagger factory does not support this operation"); } @@ -129,8 +126,7 @@ public TagDictionary createTagDictionary(InputStream in) @Override @SuppressWarnings("rawtypes") public Map createArtifactSerializersMap() { - Map serializers = super - .createArtifactSerializersMap(); + Map serializers = super.createArtifactSerializersMap(); serializers.put(MORFOLOGIK_POSDICT_SUF, new ByteArraySerializer()); serializers.put(MORFOLOGIK_DICT_INFO_SUF, new ByteArraySerializer()); @@ -156,9 +152,7 @@ private TagDictionary createMorfologikDictionary(byte[] data, byte[] info) static class ByteArraySerializer implements ArtifactSerializer { - public byte[] create(InputStream in) throws IOException, - InvalidFormatException { - + public byte[] create(InputStream in) throws IOException { return ModelUtil.read(in); } diff --git a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikTagDictionary.java b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikTagDictionary.java index b34ca2b42..a57b4bbb8 100644 --- a/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikTagDictionary.java +++ b/opennlp-morfologik-addon/src/main/java/opennlp/morfologik/tagdict/MorfologikTagDictionary.java @@ -77,7 +77,7 @@ public String[] getTags(String word) { List data = dictLookup.lookup(word); if (data != null && data.size() > 0) { - List tags = new ArrayList(data.size()); + List tags = new ArrayList<>(data.size()); for (int i = 0; i < data.size(); i++) { tags.add(data.get(i).getTag().toString()); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java index da71d3663..c61b05126 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java @@ -47,9 +47,9 @@ public ChunkSample(String[] sentence, String[] tags, String[] preds) { validateArguments(sentence.length, tags.length, preds.length); - this.sentence = Collections.unmodifiableList(new ArrayList(Arrays.asList(sentence))); - this.tags = Collections.unmodifiableList(new ArrayList(Arrays.asList(tags))); - this.preds = Collections.unmodifiableList(new ArrayList(Arrays.asList(preds))); + this.sentence = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(sentence))); + this.tags = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tags))); + this.preds = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(preds))); } /** @@ -66,9 +66,9 @@ public ChunkSample(List sentence, List tags, List preds) validateArguments(sentence.size(), tags.size(), preds.size()); - this.sentence = Collections.unmodifiableList(new ArrayList(sentence)); - this.tags = Collections.unmodifiableList(new ArrayList(tags)); - this.preds = Collections.unmodifiableList(new ArrayList(preds)); + this.sentence = Collections.unmodifiableList(new ArrayList<>(sentence)); + this.tags = Collections.unmodifiableList(new ArrayList<>(tags)); + this.preds = Collections.unmodifiableList(new ArrayList<>(preds)); } /** Gets the training sentence */ @@ -109,7 +109,7 @@ public static Span[] phrasesAsSpanList(String[] aSentence, String[] aTags, validateArguments(aSentence.length, aTags.length, aPreds.length); // initialize with the list maximum size - List phrases = new ArrayList(aSentence.length); + List phrases = new ArrayList<>(aSentence.length); String startTag = ""; int startIndex = 0; boolean foundPhrase = false; diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java index e4da42fd2..8935829a0 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSampleSequenceStream.java @@ -53,7 +53,7 @@ public Sequence read() throws IOException { events[i] = new Event(tags[i], context); } - return new Sequence(events,sample); + return new Sequence<>(events,sample); } return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java index b26f01b94..c496d1241 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/Chunker.java @@ -33,7 +33,7 @@ public interface Chunker { * * @return an array of chunk tags for each token in the sequence. */ - public String[] chunk(String[] toks, String tags[]); + String[] chunk(String[] toks, String tags[]); /** * Generates tagged chunk spans for the given sequence returning the result in a span array. @@ -43,7 +43,7 @@ public interface Chunker { * * @return an array of spans with chunk tags for each chunk in the sequence. */ - public Span[] chunkAsSpans(String[] toks, String tags[]); + Span[] chunkAsSpans(String[] toks, String tags[]); /** * Returns the top k chunk sequences for the specified sentence with the specified pos-tags @@ -52,7 +52,7 @@ public interface Chunker { * * @return the top k chunk sequences for the specified sentence. */ - public Sequence[] topKSequences(String[] sentence, String[] tags); + Sequence[] topKSequences(String[] sentence, String[] tags); /** * Returns the top k chunk sequences for the specified sentence with the specified pos-tags @@ -62,5 +62,5 @@ public interface Chunker { * * @return the top k chunk sequences for the specified sentence. */ - public Sequence[] topKSequences(String[] sentence, String[] tags, double minSequenceScore); + Sequence[] topKSequences(String[] sentence, String[] tags, double minSequenceScore); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java index 8b1e745d5..25e531a61 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerContextGenerator.java @@ -32,5 +32,5 @@ public interface ChunkerContextGenerator extends BeamSearchContextGenerator samples, int nFolds) - throws IOException, InvalidFormatException { - CrossValidationPartitioner partitioner = new CrossValidationPartitioner( + throws IOException { + CrossValidationPartitioner partitioner = new CrossValidationPartitioner<>( samples, nFolds); while (partitioner.hasNext()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerEventStream.java index 118357c85..d72d11580 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerEventStream.java @@ -47,7 +47,7 @@ public ChunkerEventStream(ObjectStream d, ChunkerContextGenerator c protected Iterator createEvents(ChunkSample sample) { if (sample != null) { - List events = new ArrayList(); + List events = new ArrayList<>(); String[] toksArray = sample.getSentence(); String[] tagsArray = sample.getTags(); String[] predsArray = sample.getPreds(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerFactory.java index c59be295c..1cb772fc1 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerFactory.java @@ -38,9 +38,7 @@ public static ChunkerFactory create(String subclassName) return new ChunkerFactory(); } try { - ChunkerFactory theFactory = ExtensionLoader.instantiateExtension( - ChunkerFactory.class, subclassName); - return theFactory; + return ExtensionLoader.instantiateExtension(ChunkerFactory.class, subclassName); } catch (Exception e) { String msg = "Could not instantiate the " + subclassName + ". The initialization throw an exception."; diff --git a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java index e5b1073cd..3ed4f9c2c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java +++ b/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkerME.java @@ -77,7 +77,7 @@ private ChunkerME(ChunkerModel model, int beamSize, SequenceValidator se this.model = model.getChunkerSequenceModel(); } else { - this.model = new opennlp.tools.ml.BeamSearch(beamSize, + this.model = new opennlp.tools.ml.BeamSearch<>(beamSize, model.getChunkerModel(), 0); } } @@ -101,7 +101,7 @@ private ChunkerME(ChunkerModel model, int beamSize) { this.model = model.getChunkerSequenceModel(); } else { - this.model = new opennlp.tools.ml.BeamSearch(beamSize, + this.model = new opennlp.tools.ml.BeamSearch<>(beamSize, model.getChunkerModel(), 0); } } @@ -168,7 +168,7 @@ public static ChunkerModel train(String lang, ObjectStream in, beamSize = Integer.parseInt(beamSizeString); } - Map manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); TrainerType trainerType = TrainerFactory.getTrainerType(mlParams.getSettings()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java index cfc17aad9..ca9a65069 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ArgumentParser.java @@ -51,19 +51,19 @@ public class ArgumentParser { public @Retention(RetentionPolicy.RUNTIME) @interface OptionalParameter { - public static final String DEFAULT_CHARSET = "DEFAULT_CHARSET"; - public String defaultValue() default ""; + String DEFAULT_CHARSET = "DEFAULT_CHARSET"; + String defaultValue() default ""; } public @Retention(RetentionPolicy.RUNTIME) @interface ParameterDescription { - public String valueName(); - public String description() default ""; + String valueName(); + String description() default ""; } private interface ArgumentFactory { - static final String INVALID_ARG = "Invalid argument: %s %s \n"; + String INVALID_ARG = "Invalid argument: %s %s \n"; Object parseArgument(Method method, String argName, String argValue); } @@ -148,7 +148,7 @@ public Object invoke(Object proxy, Method method, Object[] args) private static final Map, ArgumentFactory> argumentFactories; static { - Map, ArgumentFactory> factories = new HashMap, ArgumentParser.ArgumentFactory>(); + Map, ArgumentFactory> factories = new HashMap<>(); factories.put(Integer.class, new IntegerArgumentFactory()); factories.put(Boolean.class, new BooleanArgumentFactory()); factories.put(String.class, new StringArgumentFactory()); @@ -205,9 +205,7 @@ private static String methodNameToParameter(String methodName) { // name length is checked to be at least 4 prior parameterNameChars[3] = Character.toLowerCase(parameterNameChars[3]); - String parameterName = "-" + new String(parameterNameChars).substring(3); - - return parameterName; + return "-" + new String(parameterNameChars).substring(3); } /** @@ -270,9 +268,9 @@ public boolean getOptional() { public static List createArguments(Class... argProxyInterfaces) { checkProxyInterfaces(argProxyInterfaces); - Set duplicateFilter = new HashSet(); + Set duplicateFilter = new HashSet<>(); - List arguments = new LinkedList(); + List arguments = new LinkedList<>(); for (Class argProxyInterface : argProxyInterfaces) { if (null != argProxyInterface) { @@ -321,7 +319,7 @@ public static List createArguments(Class... argProxyInterfaces) public static String createUsage(Class... argProxyInterfaces) { checkProxyInterfaces(argProxyInterfaces); - Set duplicateFilter = new HashSet(); + Set duplicateFilter = new HashSet<>(); StringBuilder usage = new StringBuilder(); StringBuilder details = new StringBuilder(); @@ -348,7 +346,7 @@ public static String createUsage(Class... argProxyInterfaces) { usage.append(paramName).append(' ').append(desc.valueName()); details.append('\t').append(paramName).append(' ').append(desc.valueName()).append('\n'); - if(desc.description() != null && desc.description().length() > 0) { + if(desc.description().length() > 0) { details.append("\t\t").append(desc.description()).append('\n'); } @@ -425,7 +423,7 @@ public static String validateArgumentsLoudly(String args[], Class... argP } int argumentCount = 0; - List parameters = new ArrayList(Arrays.asList(args)); + List parameters = new ArrayList<>(Arrays.asList(args)); for (Class argProxyInterface : argProxyInterfaces) { for (Method method : argProxyInterface.getMethods()) { @@ -482,7 +480,7 @@ public static T parse(String args[], Class argProxyInterface) { if (!validateArguments(args, argProxyInterface)) throw new IllegalArgumentException("Passed args must be valid!"); - Map arguments = new HashMap(); + Map arguments = new HashMap<>(); for (Method method : argProxyInterface.getMethods()) { @@ -531,7 +529,7 @@ public static T parse(String args[], Class argProxyInterface) { * @return arguments pertaining to argProxyInterface */ public static String[] filter(String args[], Class argProxyInterface) { - ArrayList parameters = new ArrayList(args.length); + ArrayList parameters = new ArrayList<>(args.length); for (Method method : argProxyInterface.getMethods()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java index 6cfe0b7e6..7abb6d495 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/CLI.java @@ -78,9 +78,9 @@ public final class CLI { private static Map toolLookupMap; static { - toolLookupMap = new LinkedHashMap(); + toolLookupMap = new LinkedHashMap<>(); - List tools = new LinkedList(); + List tools = new LinkedList<>(); // Document Categorizer tools.add(new DoccatTool()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java index ccf6884bc..4e3ec882c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/DetailedFMeasureListener.java @@ -41,7 +41,7 @@ public abstract class DetailedFMeasureListener implements private int samples = 0; private Stats generalStats = new Stats(); - private Map statsForOutcome = new HashMap(); + private Map statsForOutcome = new HashMap<>(); protected abstract Span[] asSpanArray(T sample); @@ -59,8 +59,8 @@ public void missclassified(T reference, T prediction) { Span[] references = asSpanArray(reference); Span[] predictions = asSpanArray(prediction); - Set refSet = new HashSet(Arrays.asList(references)); - Set predSet = new HashSet(Arrays.asList(predictions)); + Set refSet = new HashSet<>(Arrays.asList(references)); + Set predSet = new HashSet<>(Arrays.asList(predictions)); for (Span ref : refSet) { if (predSet.contains(ref)) { @@ -129,7 +129,7 @@ public String createReport(Locale locale) { zeroOrPositive(generalStats.getRecallScore() * 100), zeroOrPositive(generalStats.getFMeasure() * 100))); ret.append("\n"); - SortedSet set = new TreeSet(new F1Comparator()); + SortedSet set = new TreeSet<>(new F1Comparator()); set.addAll(statsForOutcome.keySet()); for (String type : set) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/EvaluationErrorPrinter.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/EvaluationErrorPrinter.java index 6fda10b07..51e11611b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/EvaluationErrorPrinter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/EvaluationErrorPrinter.java @@ -40,8 +40,8 @@ protected EvaluationErrorPrinter(OutputStream outputStream) { // for the sentence detector protected void printError(Span references[], Span predictions[], T referenceSample, T predictedSample, String sentence) { - List falseNegatives = new ArrayList(); - List falsePositives = new ArrayList(); + List falseNegatives = new ArrayList<>(); + List falsePositives = new ArrayList<>(); findErrors(references, predictions, falseNegatives, falsePositives); @@ -57,8 +57,8 @@ protected void printError(Span references[], Span predictions[], // for namefinder, chunker... protected void printError(String id, Span references[], Span predictions[], T referenceSample, T predictedSample, String[] sentenceTokens) { - List falseNegatives = new ArrayList(); - List falsePositives = new ArrayList(); + List falseNegatives = new ArrayList<>(); + List falsePositives = new ArrayList<>(); findErrors(references, predictions, falseNegatives, falsePositives); @@ -83,9 +83,9 @@ protected void printError(Span references[], Span predictions[], // for pos tagger protected void printError(String references[], String predictions[], T referenceSample, T predictedSample, String[] sentenceTokens) { - List filteredDoc = new ArrayList(); - List filteredRefs = new ArrayList(); - List filteredPreds = new ArrayList(); + List filteredDoc = new ArrayList<>(); + List filteredRefs = new ArrayList<>(); + List filteredPreds = new ArrayList<>(); for (int i = 0; i < references.length; i++) { if (!references[i].equals(predictions[i])) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java index b2a9c42fa..00074ea00 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/GenerateManualTool.java @@ -45,7 +45,7 @@ public static void main(String[] args) throws FileNotFoundException { appendHeader(sb); // organize by package name - LinkedHashMap> packageNameToolMap = new LinkedHashMap>(); + LinkedHashMap> packageNameToolMap = new LinkedHashMap<>(); for (String toolName : CLI.getToolLookupMap().keySet()) { CmdLineTool tool = CLI.getToolLookupMap().get(toolName); String packageName = tool.getClass().getPackage().getName(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ModelLoader.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ModelLoader.java index 3e5db5473..561a6f885 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/ModelLoader.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/ModelLoader.java @@ -43,8 +43,7 @@ protected ModelLoader(String modelName) { this.modelName = modelName; } - protected abstract T loadModel(InputStream modelIn) throws - IOException, InvalidFormatException; + protected abstract T loadModel(InputStream modelIn) throws IOException; public T load(File modelFile) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java index 9173c2220..2573e2e62 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/StreamFactoryRegistry.java @@ -60,8 +60,7 @@ */ public final class StreamFactoryRegistry { - private static final Map> registry = - new HashMap>(); + private static final Map> registry = new HashMap<>(); static { ChunkerSampleStreamFactory.registerFactory(); @@ -129,7 +128,7 @@ public static boolean registerFactory(Class sampleClass, boolean result; Map formats = registry.get(sampleClass); if (null == formats) { - formats = new HashMap(); + formats = new HashMap<>(); } if (!formats.containsKey(formatName)) { formats.put(formatName, factory); @@ -198,10 +197,8 @@ public static ObjectStreamFactory getFactory(Class sampleClass, try { return (ObjectStreamFactory) factoryClazz.newInstance(); - } catch (InstantiationException e) { + } catch (InstantiationException | IllegalAccessException e) { return null; - } catch (IllegalAccessException e) { - return null; } } catch (ClassNotFoundException e) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerCrossValidatorTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerCrossValidatorTool.java index a4e0a4c44..2724d880a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerCrossValidatorTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerCrossValidatorTool.java @@ -57,7 +57,7 @@ public void run(String format, String[] args) { mlParams = ModelUtil.createDefaultTrainingParameters(); } - List> listeners = new LinkedList>(); + List> listeners = new LinkedList<>(); ChunkerDetailedFMeasureListener detailedFMeasureListener = null; if (params.getMisclassified()) { listeners.add(new ChunkEvaluationErrorListener()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerEvaluatorTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerEvaluatorTool.java index 58d87031e..01324cc5f 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerEvaluatorTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerEvaluatorTool.java @@ -54,7 +54,7 @@ public void run(String format, String[] args) { ChunkerModel model = new ChunkerModelLoader().load(params.getModel()); - List> listeners = new LinkedList>(); + List> listeners = new LinkedList<>(); ChunkerDetailedFMeasureListener detailedFMeasureListener = null; if(params.getMisclassified()) { listeners.add(new ChunkEvaluationErrorListener()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java index 25c44653c..5b87c9e70 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/chunker/ChunkerMETool.java @@ -50,7 +50,7 @@ public void run(String[] args) { ChunkerME chunker = new ChunkerME(model); - ObjectStream lineStream = null; + ObjectStream lineStream; PerformanceMonitor perfMon = null; try { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatFineGrainedReportListener.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatFineGrainedReportListener.java index e07dc4f7c..0652d0b2d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatFineGrainedReportListener.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatFineGrainedReportListener.java @@ -26,14 +26,12 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; - import opennlp.tools.doccat.DoccatEvaluationMonitor; import opennlp.tools.doccat.DocumentSample; import opennlp.tools.util.Span; @@ -330,7 +328,7 @@ private void printLine(int size) { printStream.append("\n"); } - private static final String generateAlphaLabel(int index) { + private static String generateAlphaLabel(int index) { char labelChars[] = new char[3]; int i; @@ -355,20 +353,20 @@ private class Stats { private int maximumSentenceLength = Integer.MIN_VALUE; // token statistics - private final Map tokAccuracies = new HashMap(); - private final Map tokOcurrencies = new HashMap(); - private final Map tokErrors = new HashMap(); + private final Map tokAccuracies = new HashMap<>(); + private final Map tokOcurrencies = new HashMap<>(); + private final Map tokErrors = new HashMap<>(); // tag statistics - private final Map tagOcurrencies = new HashMap(); - private final Map tagErrors = new HashMap(); - private final Map tagFMeasure = new HashMap(); + private final Map tagOcurrencies = new HashMap<>(); + private final Map tagErrors = new HashMap<>(); + private final Map tagFMeasure = new HashMap<>(); // represents a Confusion Matrix that aggregates all tokens - private final Map generalConfusionMatrix = new HashMap(); + private final Map generalConfusionMatrix = new HashMap<>(); // represents a set of Confusion Matrix for each token - private final Map> tokenConfusionMatrix = new HashMap>(); + private final Map> tokenConfusionMatrix = new HashMap<>(); public void add(DocumentSample reference, DocumentSample prediction) { int length = reference.getText().length; @@ -447,13 +445,13 @@ private void add(String tok, String ref, String pred) { private void updateTagFMeasure(String[] refs, String[] preds) { // create a set with all tags - Set tags = new HashSet(Arrays.asList(refs)); + Set tags = new HashSet<>(Arrays.asList(refs)); tags.addAll(Arrays.asList(preds)); // create samples for each tag for (String tag : tags) { - List reference = new ArrayList(); - List prediction = new ArrayList(); + List reference = new ArrayList<>(); + List prediction = new ArrayList<>(); for (int i = 0; i < refs.length; i++) { if (refs[i].equals(tag)) { reference.add(new Span(i, i + 1)); @@ -509,7 +507,7 @@ public int getTokenFrequency(String token) { } public SortedSet getTokensOrderedByFrequency() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -532,7 +530,7 @@ public int compare(String o1, String o2) { } public SortedSet getTokensOrderedByNumberOfErrors() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -573,7 +571,7 @@ public double getTagPrecision(String tag) { } public SortedSet getTagsOrderedByErrors() { - SortedSet tags = new TreeSet(new Comparator() { + SortedSet tags = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -638,9 +636,9 @@ private double[][] createConfusionMatrix(SortedSet tagset, private SortedSet getConfusionMatrixTagset( Map data) { - SortedSet tags = new TreeSet(new CategoryComparator(data)); + SortedSet tags = new TreeSet<>(new CategoryComparator(data)); tags.addAll(data.keySet()); - List col = new LinkedList(); + List col = new LinkedList<>(); for (String t : tags) { col.addAll(data.get(t).line.keySet()); } @@ -693,7 +691,7 @@ public int compare(String o1, String o2) { */ private static class ConfusionMatrixLine { - private Map line = new HashMap(); + private Map line = new HashMap<>(); private String ref; private int total = 0; private int correct = 0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTool.java index d41dabb49..dbc6e6bb0 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTool.java @@ -54,7 +54,7 @@ public void run(String[] args) { DocumentCategorizerME doccat = new DocumentCategorizerME(model); - /** + /* * moved initialization to the try block to catch new IOException */ ObjectStream documentStream; diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTrainerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTrainerTool.java index 421c57fa8..91ee01976 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTrainerTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/doccat/DoccatTrainerTool.java @@ -99,8 +99,7 @@ static Tokenizer createTokenizer(String tokenizer) { static FeatureGenerator[] createFeatureGenerators(String featureGeneratorsNames) { if(featureGeneratorsNames == null) { - FeatureGenerator[] def = {new BagOfWordsFeatureGenerator()}; - return def; + return new FeatureGenerator[]{new BagOfWordsFeatureGenerator()}; } String[] classes = featureGeneratorsNames.split(","); FeatureGenerator[] featureGenerators = new FeatureGenerator[classes.length]; diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java index dbdb27abf..f82e362e6 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/entitylinker/EntityLinkerTool.java @@ -84,7 +84,7 @@ public void run(String[] args) { ObjectStream untokenizedLineStream = new PlainTextByLineStream( new SystemInputStreamFactory(), SystemInputStreamFactory.encoding()); - List document = new ArrayList(); + List document = new ArrayList<>(); String line; while ((line = untokenizedLineStream.read()) != null) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerFineGrainedReportListener.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerFineGrainedReportListener.java index 7af495c45..b72e88948 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerFineGrainedReportListener.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerFineGrainedReportListener.java @@ -459,7 +459,7 @@ private void printLine(int size) { printStream.append("\n"); } - private static final String generateAlphaLabel(int index) { + private static String generateAlphaLabel(int index) { char labelChars[] = new char[3]; int i; @@ -484,20 +484,20 @@ private class Stats { private int maximumSentenceLength = Integer.MIN_VALUE; // token statistics - private final Map tokAccuracies = new HashMap(); - private final Map tokOcurrencies = new HashMap(); - private final Map tokErrors = new HashMap(); + private final Map tokAccuracies = new HashMap<>(); + private final Map tokOcurrencies = new HashMap<>(); + private final Map tokErrors = new HashMap<>(); // tag statistics - private final Map tagOcurrencies = new HashMap(); - private final Map tagErrors = new HashMap(); - private final Map tagFMeasure = new HashMap(); + private final Map tagOcurrencies = new HashMap<>(); + private final Map tagErrors = new HashMap<>(); + private final Map tagFMeasure = new HashMap<>(); // represents a Confusion Matrix that aggregates all tokens - private final Map generalConfusionMatrix = new HashMap(); + private final Map generalConfusionMatrix = new HashMap<>(); // represents a set of Confusion Matrix for each token - private final Map> tokenConfusionMatrix = new HashMap>(); + private final Map> tokenConfusionMatrix = new HashMap<>(); public void add(LemmaSample reference, LemmaSample prediction) { int length = reference.getTokens().length; @@ -576,13 +576,13 @@ private void add(String tok, String ref, String pred) { private void updateTagFMeasure(String[] refs, String[] preds) { // create a set with all tags - Set tags = new HashSet(Arrays.asList(refs)); + Set tags = new HashSet<>(Arrays.asList(refs)); tags.addAll(Arrays.asList(preds)); // create samples for each tag for (String tag : tags) { - List reference = new ArrayList(); - List prediction = new ArrayList(); + List reference = new ArrayList<>(); + List prediction = new ArrayList<>(); for (int i = 0; i < refs.length; i++) { if (refs[i].equals(tag)) { reference.add(new Span(i, i + 1)); @@ -638,7 +638,7 @@ public int getTokenFrequency(String token) { } public SortedSet getTokensOrderedByFrequency() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -661,7 +661,7 @@ public int compare(String o1, String o2) { } public SortedSet getTokensOrderedByNumberOfErrors() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -702,7 +702,7 @@ public double getTagPrecision(String tag) { } public SortedSet getTagsOrderedByErrors() { - SortedSet tags = new TreeSet(new Comparator() { + SortedSet tags = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -767,10 +767,10 @@ private double[][] createConfusionMatrix(SortedSet tagset, private SortedSet getConfusionMatrixTagset( Map data) { - SortedSet tags = new TreeSet( + SortedSet tags = new TreeSet<>( new CategoryComparator(data)); tags.addAll(data.keySet()); - List col = new LinkedList(); + List col = new LinkedList<>(); for (String t : tags) { col.addAll(data.get(t).line.keySet()); } @@ -824,7 +824,7 @@ public int compare(String o1, String o2) { */ private static class ConfusionMatrixLine { - private Map line = new HashMap(); + private Map line = new HashMap<>(); private String ref; private int total = 0; private int correct = 0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerMETool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerMETool.java index 8805bca38..966111a3a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerMETool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/lemmatizer/LemmatizerMETool.java @@ -51,7 +51,7 @@ public void run(String[] args) { LemmatizerME lemmatizer = new LemmatizerME(model); - ObjectStream lineStream = null; + ObjectStream lineStream; PerformanceMonitor perfMon = null; try { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTool.java index 7f05a78d2..6e8b86f0a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/TokenNameFinderTool.java @@ -81,7 +81,7 @@ public void run(String[] args) { } } - List names = new ArrayList(); + List names = new ArrayList<>(); for (TokenNameFinder nameFinder : nameFinders) { Collections.addAll(names, nameFinder.find(whitespaceTokenizerLine)); diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSModelLoader.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSModelLoader.java index 2bdfe7b2b..40632cf33 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSModelLoader.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSModelLoader.java @@ -19,10 +19,8 @@ import java.io.IOException; import java.io.InputStream; - import opennlp.tools.cmdline.ModelLoader; import opennlp.tools.postag.POSModel; -import opennlp.tools.util.InvalidFormatException; /** * Loads a POS Tagger Model for the command line tools. @@ -36,8 +34,7 @@ public POSModelLoader() { } @Override - protected POSModel loadModel(InputStream modelIn) throws IOException, - InvalidFormatException { + protected POSModel loadModel(InputStream modelIn) throws IOException { return new POSModel(modelIn); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerFineGrainedReportListener.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerFineGrainedReportListener.java index 1a40a9726..4149c9750 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerFineGrainedReportListener.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerFineGrainedReportListener.java @@ -466,7 +466,7 @@ private void printLine(int size) { printStream.append("\n"); } - private static final String generateAlphaLabel(int index) { + private static String generateAlphaLabel(int index) { char labelChars[] = new char[3]; int i; @@ -491,20 +491,20 @@ private class Stats { private int maximumSentenceLength = Integer.MIN_VALUE; // token statistics - private final Map tokAccuracies = new HashMap(); - private final Map tokOcurrencies = new HashMap(); - private final Map tokErrors = new HashMap(); + private final Map tokAccuracies = new HashMap<>(); + private final Map tokOcurrencies = new HashMap<>(); + private final Map tokErrors = new HashMap<>(); // tag statistics - private final Map tagOcurrencies = new HashMap(); - private final Map tagErrors = new HashMap(); - private final Map tagFMeasure = new HashMap(); + private final Map tagOcurrencies = new HashMap<>(); + private final Map tagErrors = new HashMap<>(); + private final Map tagFMeasure = new HashMap<>(); // represents a Confusion Matrix that aggregates all tokens - private final Map generalConfusionMatrix = new HashMap(); + private final Map generalConfusionMatrix = new HashMap<>(); // represents a set of Confusion Matrix for each token - private final Map> tokenConfusionMatrix = new HashMap>(); + private final Map> tokenConfusionMatrix = new HashMap<>(); public void add(POSSample reference, POSSample prediction) { int length = reference.getSentence().length; @@ -583,13 +583,13 @@ private void add(String tok, String ref, String pred) { private void updateTagFMeasure(String[] refs, String[] preds) { // create a set with all tags - Set tags = new HashSet(Arrays.asList(refs)); + Set tags = new HashSet<>(Arrays.asList(refs)); tags.addAll(Arrays.asList(preds)); // create samples for each tag for (String tag : tags) { - List reference = new ArrayList(); - List prediction = new ArrayList(); + List reference = new ArrayList<>(); + List prediction = new ArrayList<>(); for (int i = 0; i < refs.length; i++) { if (refs[i].equals(tag)) { reference.add(new Span(i, i + 1)); @@ -645,7 +645,7 @@ public int getTokenFrequency(String token) { } public SortedSet getTokensOrderedByFrequency() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -668,7 +668,7 @@ public int compare(String o1, String o2) { } public SortedSet getTokensOrderedByNumberOfErrors() { - SortedSet toks = new TreeSet(new Comparator() { + SortedSet toks = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -709,7 +709,7 @@ public double getTagPrecision(String tag) { } public SortedSet getTagsOrderedByErrors() { - SortedSet tags = new TreeSet(new Comparator() { + SortedSet tags = new TreeSet<>(new Comparator() { public int compare(String o1, String o2) { if (o1.equals(o2)) { return 0; @@ -764,8 +764,7 @@ private double[][] createConfusionMatrix(SortedSet tagset, column++; } // set accuracy - matrix[line][column] = data.get(ref) != null ? data.get(ref) - .getAccuracy() : 0; + matrix[line][column] = data.get(ref) != null ? data.get(ref).getAccuracy() : 0; line++; } @@ -774,9 +773,9 @@ private double[][] createConfusionMatrix(SortedSet tagset, private SortedSet getConfusionMatrixTagset( Map data) { - SortedSet tags = new TreeSet(new CategoryComparator(data)); + SortedSet tags = new TreeSet<>(new CategoryComparator(data)); tags.addAll(data.keySet()); - List col = new LinkedList(); + List col = new LinkedList<>(); for (String t : tags) { col.addAll(data.get(t).line.keySet()); } @@ -829,7 +828,7 @@ public int compare(String o1, String o2) { */ private static class ConfusionMatrixLine { - private Map line = new HashMap(); + private Map line = new HashMap<>(); private String ref; private int total = 0; private int correct = 0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTool.java index d2ceab87d..2c4c661fc 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTool.java @@ -51,7 +51,7 @@ public void run(String[] args) { POSTaggerME tagger = new POSTaggerME(model); - ObjectStream lineStream = null; + ObjectStream lineStream; PerformanceMonitor perfMon = null; try { diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java index 42e4aa195..c04b5efad 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/postag/POSTaggerTrainerTool.java @@ -85,7 +85,7 @@ public void run(String format, String[] args) { System.err.println("done"); } - POSTaggerFactory postaggerFactory = null; + POSTaggerFactory postaggerFactory; try { postaggerFactory = POSTaggerFactory.create(params.getFactory(), ngramDict, null); } catch (InvalidFormatException e) { @@ -149,17 +149,19 @@ static ModelType getModelType(String modelString) { if (modelString == null) modelString = "maxent"; - if (modelString.equals("maxent")) { - model = ModelType.MAXENT; - } - else if (modelString.equals("perceptron")) { - model = ModelType.PERCEPTRON; - } - else if (modelString.equals("perceptron_sequence")) { - model = ModelType.PERCEPTRON_SEQUENCE; - } - else { - model = null; + switch (modelString) { + case "maxent": + model = ModelType.MAXENT; + break; + case "perceptron": + model = ModelType.PERCEPTRON; + break; + case "perceptron_sequence": + model = ModelType.PERCEPTRON_SEQUENCE; + break; + default: + model = null; + break; } return model; } diff --git a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/CommandLineTokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/CommandLineTokenizer.java index 2c537a912..4c81d9356 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/CommandLineTokenizer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/cmdline/tokenizer/CommandLineTokenizer.java @@ -36,9 +36,9 @@ final class CommandLineTokenizer { } void process() { - ObjectStream untokenizedLineStream = null; + ObjectStream untokenizedLineStream; - ObjectStream tokenizedLineStream = null; + ObjectStream tokenizedLineStream; PerformanceMonitor perfMon = null; try { untokenizedLineStream = diff --git a/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java b/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java index aa1fef863..58b7a6e06 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java +++ b/opennlp-tools/src/main/java/opennlp/tools/dictionary/Dictionary.java @@ -28,12 +28,10 @@ import java.util.Iterator; import java.util.Set; import java.util.StringTokenizer; - 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; import opennlp.tools.util.StringUtil; @@ -91,7 +89,7 @@ public String toString() { } } - private Set entrySet = new HashSet(); + private Set entrySet = new HashSet<>(); private final boolean isCaseSensitive; private int minTokenCount = 99999; private int maxTokenCount = 0; @@ -113,9 +111,8 @@ public Dictionary(boolean caseSensitive) { * * @param in * @throws IOException - * @throws InvalidFormatException */ - public Dictionary(InputStream in) throws IOException, InvalidFormatException { + public Dictionary(InputStream in) throws IOException { isCaseSensitive = DictionarySerializer.create(in, new EntryInserter() { public void insert(Entry entry) { put(entry.getTokens()); @@ -136,9 +133,8 @@ public void insert(Entry entry) { * @param caseSensitive * has no effect * @throws IOException - * @throws InvalidFormatException */ - public Dictionary(InputStream in, boolean caseSensitive) throws IOException, InvalidFormatException { + public Dictionary(InputStream in, boolean caseSensitive) throws IOException { this(in); } @@ -173,7 +169,6 @@ public int getMaxTokenCount() { * Checks if this dictionary has the given entry. * * @param tokens - * * @return true if it contains the entry otherwise false */ public boolean contains(StringList tokens) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/dictionary/Index.java b/opennlp-tools/src/main/java/opennlp/tools/dictionary/Index.java index df4e9c5d6..7d1245efd 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/dictionary/Index.java +++ b/opennlp-tools/src/main/java/opennlp/tools/dictionary/Index.java @@ -30,7 +30,7 @@ */ public class Index { - private Set tokens = new HashSet(); + private Set tokens = new HashSet<>(); /** * Initializes the current instance with the given diff --git a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/Attributes.java b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/Attributes.java index 1b2b488f6..cd737c8fb 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/Attributes.java +++ b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/Attributes.java @@ -30,7 +30,7 @@ */ public class Attributes { - private Map mNameValueMap = new HashMap(); + private Map mNameValueMap = new HashMap<>(); /** * Retrieves the value for the given key or null if attribute it not set. diff --git a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionarySerializer.java b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionarySerializer.java index feb96a344..a0b3dcb8e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionarySerializer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionarySerializer.java @@ -59,7 +59,7 @@ private static class DictionaryContenthandler implements ContentHandler { private boolean mIsInsideTokenElement; private boolean mIsCaseSensitiveDictionary; - private List mTokenList = new LinkedList(); + private List mTokenList = new LinkedList<>(); private StringBuilder token = new StringBuilder(); @@ -209,7 +209,7 @@ public void startPrefixMapping(String prefix, String uri) * @throws InvalidFormatException */ public static boolean create(InputStream in, EntryInserter inserter) - throws IOException, InvalidFormatException { + throws IOException { DictionaryContenthandler profileContentHandler = new DictionaryContenthandler(inserter); @@ -299,8 +299,7 @@ public static void serialize(OutputStream out, Iterator entries, hd.endDocument(); } catch (SAXException e) { - //TODO update after Java6 upgrade - throw (IOException) new IOException("Error during serialization: " + e.getMessage()).initCause(e); + throw new IOException("Error during serialization: " + e.getMessage(), e); } } @@ -320,14 +319,11 @@ private static void serializeEntry(TransformerHandler hd, Entry entry) StringList tokens = entry.getTokens(); - for (Iterator it = tokens.iterator(); it.hasNext(); ) { + for (String token1 : tokens) { hd.startElement("", "", TOKEN_ELEMENT, new AttributesImpl()); - String token = it.next(); - - hd.characters(token.toCharArray(), - 0, token.length()); + hd.characters(token1.toCharArray(), 0, token1.length()); hd.endElement("", "", TOKEN_ELEMENT); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/BagOfWordsFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/BagOfWordsFeatureGenerator.java index 848f4e11a..ac39afccc 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/BagOfWordsFeatureGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/BagOfWordsFeatureGenerator.java @@ -41,7 +41,7 @@ public BagOfWordsFeatureGenerator() { @Override public Collection extractFeatures(String[] text, Map extraInformation) { - Collection bagOfWords = new ArrayList(text.length); + Collection bagOfWords = new ArrayList<>(text.length); for (String word : text) { if (useOnlyAllLetterTokens) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatCrossValidator.java index dbce077d6..106b82d2d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatCrossValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatCrossValidator.java @@ -65,7 +65,7 @@ public DoccatCrossValidator(String languageCode, TrainingParameters mlParams, public void evaluate(ObjectStream samples, int nFolds) throws IOException { - CrossValidationPartitioner partitioner = new CrossValidationPartitioner( + CrossValidationPartitioner partitioner = new CrossValidationPartitioner<>( samples, nFolds); while (partitioner.hasNext()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java index 9b30d95a6..b95671adc 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java @@ -140,8 +140,7 @@ public FeatureGenerator[] getFeatureGenerators() { } if (featureGenerators == null) { // could not load using artifact provider // load bag of words as default - FeatureGenerator[] bow = {new BagOfWordsFeatureGenerator()}; - this.featureGenerators = bow; + this.featureGenerators = new FeatureGenerator[]{new BagOfWordsFeatureGenerator()}; } } return featureGenerators; diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java index 2bbaace6b..e71b6258c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatModel.java @@ -45,15 +45,15 @@ public DoccatModel(String languageCode, MaxentModel doccatModel, checkArtifactMap(); } - public DoccatModel(InputStream in) throws IOException, InvalidFormatException { + public DoccatModel(InputStream in) throws IOException { super(COMPONENT_NAME, in); } - public DoccatModel(File modelFile) throws IOException, InvalidFormatException { + public DoccatModel(File modelFile) throws IOException { super(COMPONENT_NAME, modelFile); } - public DoccatModel(URL modelURL) throws IOException, InvalidFormatException { + public DoccatModel(URL modelURL) throws IOException { super(COMPONENT_NAME, modelURL); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java index b62d8eb47..737b9d1c9 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java @@ -33,7 +33,7 @@ class DocumentCategorizerContextGenerator { public String[] getContext(String text[], Map extraInformation) { - Collection context = new LinkedList(); + Collection context = new LinkedList<>(); for (FeatureGenerator mFeatureGenerator : mFeatureGenerators) { Collection extractedFeatures = diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java index 2c31345d5..380350e20 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java @@ -17,7 +17,6 @@ package opennlp.tools.doccat; import java.io.IOException; -import java.io.ObjectStreamException; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -25,7 +24,6 @@ import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; - import opennlp.tools.ml.EventTrainer; import opennlp.tools.ml.TrainerFactory; import opennlp.tools.ml.model.MaxentModel; @@ -33,7 +31,6 @@ import opennlp.tools.tokenize.Tokenizer; import opennlp.tools.util.ObjectStream; import opennlp.tools.util.TrainingParameters; -import opennlp.tools.util.model.ModelUtil; /** * Maxent implementation of {@link DocumentCategorizer}. @@ -119,7 +116,7 @@ public double[] categorize(String documentText) { * @return the score map */ public Map scoreMap(String text) { - Map probDist = new HashMap(); + Map probDist = new HashMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); @@ -139,7 +136,7 @@ public Map scoreMap(String text) { * @return the sorted score map */ public SortedMap> sortedScoreMap(String text) { - SortedMap> descendingMap = new TreeMap>(); + SortedMap> descendingMap = new TreeMap<>(); double[] categorize = categorize(text); int catSize = getNumberOfCategories(); for (int i = 0; i < catSize; i++) { @@ -180,7 +177,7 @@ public static DoccatModel train(String languageCode, ObjectStream manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); EventTrainer trainer = TrainerFactory.getEventTrainer( mlParams.getSettings(), manifestInfoEntries); diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java index c6c185280..47828ab22 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentSample.java @@ -50,7 +50,7 @@ public DocumentSample(String category, String text[], Map extraI } this.category = category; - this.text = Collections.unmodifiableList(new ArrayList(Arrays.asList(text))); + this.text = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(text))); if(extraInformation == null) { this.extraInformation = Collections.emptyMap(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java index 49e173630..ef5d2a3c7 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/doccat/NGramFeatureGenerator.java @@ -69,7 +69,7 @@ public NGramFeatureGenerator() { */ public Collection extractFeatures(String[] text, Map extraInfo) { - List features = new ArrayList(); + List features = new ArrayList<>(); for (int i = 0; i <= text.length - minGram; i++) { String feature = "ng="; diff --git a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/BaseLink.java b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/BaseLink.java index 089d9b74e..6e06bebaf 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/BaseLink.java +++ b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/BaseLink.java @@ -29,7 +29,7 @@ public abstract class BaseLink { private String itemID; private String itemName; private String itemType; - private HashMap scoreMap = new HashMap(); + private HashMap scoreMap = new HashMap<>(); public BaseLink() { } @@ -150,12 +150,6 @@ public boolean equals(Object obj) { if (!Objects.equals(this.itemID, other.itemID)) { return false; } - if (!Objects.equals(this.itemName, other.itemName)) { - return false; - } - if (!Objects.equals(this.itemType, other.itemType)) { - return false; - } - return true; + return Objects.equals(this.itemName, other.itemName) && Objects.equals(this.itemType, other.itemType); } } \ No newline at end of file diff --git a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java index ff4757feb..c44aec85c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java +++ b/opennlp-tools/src/main/java/opennlp/tools/entitylinker/LinkedSpan.java @@ -136,12 +136,6 @@ public boolean equals(Object obj) { if (!Objects.equals(this.linkedEntries, other.linkedEntries)) { return false; } - if (this.sentenceid != other.sentenceid) { - return false; - } - if (!Objects.equals(this.searchTerm, other.searchTerm)) { - return false; - } - return true; + return this.sentenceid == other.sentenceid && Objects.equals(this.searchTerm, other.searchTerm); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStream.java index 1d8d4e99a..6825d80df 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/BioNLP2004NameSampleStream.java @@ -82,8 +82,8 @@ public BioNLP2004NameSampleStream(InputStream in, int types) { public NameSample read() throws IOException { - List sentence = new ArrayList(); - List tags = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); boolean isClearAdaptiveData = false; @@ -116,7 +116,7 @@ public NameSample read() throws IOException { if (sentence.size() > 0) { // convert name tags into spans - List names = new ArrayList(); + List names = new ArrayList<>(); int beginIndex = -1; int endIndex = -1; diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStream.java index 8d2df4b4d..7cd3810d8 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll02NameSampleStream.java @@ -102,7 +102,7 @@ public Conll02NameSampleStream(LANGUAGE lang, InputStream in, int types) { this.types = types; } - static final Span extract(int begin, int end, String beginTag) throws InvalidFormatException { + static Span extract(int begin, int end, String beginTag) throws InvalidFormatException { String type = beginTag.substring(2); @@ -128,8 +128,8 @@ else if ("ORG".equals(type)) { public NameSample read() throws IOException { - List sentence = new ArrayList(); - List tags = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); boolean isClearAdaptiveData = false; @@ -162,7 +162,7 @@ public NameSample read() throws IOException { if (sentence.size() > 0) { // convert name tags into spans - List names = new ArrayList(); + List names = new ArrayList<>(); int beginIndex = -1; int endIndex = -1; diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStream.java index 78c0ee860..07b62e82c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/Conll03NameSampleStream.java @@ -15,15 +15,12 @@ package opennlp.tools.formats; -import static opennlp.tools.formats.Conll02NameSampleStream.extract; - import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; - import opennlp.tools.namefind.NameSample; import opennlp.tools.util.InputStreamFactory; import opennlp.tools.util.ObjectStream; @@ -31,6 +28,8 @@ import opennlp.tools.util.Span; import opennlp.tools.util.StringUtil; +import static opennlp.tools.formats.Conll02NameSampleStream.extract; + /** * An import stream which can parse the CONLL03 data. */ @@ -93,8 +92,8 @@ public Conll03NameSampleStream(LANGUAGE lang, InputStream in, int types) { public NameSample read() throws IOException { - List sentence = new ArrayList(); - List tags = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); boolean isClearAdaptiveData = false; @@ -133,7 +132,7 @@ else if (LANGUAGE.DE.equals(lang) && fields.length == 5) { if (sentence.size() > 0) { // convert name tags into spans - List names = new ArrayList(); + List names = new ArrayList<>(); int beginIndex = -1; int endIndex = -1; diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStream.java index 82ac5ebac..b3b88fc24 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ConllXPOSSampleStream.java @@ -68,8 +68,8 @@ public POSSample read() throws IOException { // paragraph get lines BufferedReader reader = new BufferedReader(new StringReader(paragraph)); - List tokens = new ArrayList(100); - List tags = new ArrayList(100); + List tokens = new ArrayList<>(100); + List tags = new ArrayList<>(100); String line; while ((line = reader.readLine()) != null) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStream.java index 10c960f52..d176f8b8f 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADChunkSampleStream.java @@ -126,9 +126,9 @@ public ChunkSample read() throws IOException { // skip this one } else { Node root = paragraph.getRoot(); - List sentence = new ArrayList(); - List tags = new ArrayList(); - List target = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); + List target = new ArrayList<>(); processRoot(root, sentence, tags, target); diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStream.java index 5e131f2fc..abf6dab18 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADNameSampleStream.java @@ -80,7 +80,7 @@ public class ADNameSampleStream implements ObjectStream { private static final Map HAREM; static { - Map harem = new HashMap(); + Map harem = new HashMap<>(); final String person = "person"; harem.put("hum", person); @@ -226,7 +226,7 @@ public ADNameSampleStream(InputStream in, String charsetName, } } - int textID = -1; + private int textID = -1; public NameSample read() throws IOException { @@ -242,8 +242,8 @@ public NameSample read() throws IOException { } Node root = paragraph.getRoot(); - List sentence = new ArrayList(); - List names = new ArrayList(); + List sentence = new ArrayList<>(); + List names = new ArrayList<>(); process(root, sentence, names); return new NameSample(sentence.toArray(new String[sentence.size()]), @@ -359,17 +359,12 @@ private void processLeaf(Leaf leaf, List sentence, } else { error = true; } - if (error) { -// Maybe it is not the same NER, skip it. -// System.err.println("Missing NER start for sentence [" + sentence -// + "] node [" + leaf + "]"); - } } } private List processLexeme(String lexemeStr) { - List out = new ArrayList(); + List out = new ArrayList<>(); String[] parts = underlinePattern.split(lexemeStr); for (String tok : parts) { if(tok.length() > 1 && !alphanumericPattern.matcher(tok).matches()) { @@ -384,8 +379,8 @@ private List processLexeme(String lexemeStr) { private List processTok(String tok) { boolean tokAdded = false; String original = tok; - List out = new ArrayList(); - LinkedList suffix = new LinkedList(); + List out = new ArrayList<>(); + LinkedList suffix = new LinkedList<>(); char first = tok.charAt(0); if (first == '«') { out.add(Character.toString(first)); diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStream.java index ed030f22c..ff57d8301 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStream.java @@ -124,8 +124,8 @@ public POSSample read() throws IOException { Sentence paragraph; while ((paragraph = this.adSentenceStream.read()) != null) { Node root = paragraph.getRoot(); - List sentence = new ArrayList(); - List tags = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); process(root, sentence, tags); return new POSSample(sentence, tags); @@ -166,8 +166,8 @@ private void processLeaf(Leaf leaf, List sentence, List tags) { StringTokenizer tokenizer = new StringTokenizer(lexeme, "_"); if (tokenizer.countTokens() > 0) { - List toks = new ArrayList(tokenizer.countTokens()); - List tagsWithCont = new ArrayList( + List toks = new ArrayList<>(tokenizer.countTokens()); + List tagsWithCont = new ArrayList<>( tokenizer.countTokens()); toks.add(tokenizer.nextToken()); tagsWithCont.add("B-" + tag); diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java index dcae4e5cb..80453525b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADPOSSampleStreamFactory.java @@ -81,10 +81,8 @@ public ObjectStream create(String[] args) { CmdLineUtil.handleCreateObjectStreamError(ex); } - ADPOSSampleStream sentenceStream = new ADPOSSampleStream(lineStream, + return new ADPOSSampleStream(lineStream, params.getExpandME(), params.getIncludeFeatures()); - - return sentenceStream; } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStream.java index ed4f58baf..d3a04df2c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStream.java @@ -129,7 +129,7 @@ public SentenceSample read() throws IOException { } StringBuilder document = new StringBuilder(); - List sentences = new ArrayList(); + List sentences = new ArrayList<>(); do { do { if (!isTitle || (isTitle && isIncludeTitles)) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java index fa02a925b..9e3cec785 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceSampleStreamFactory.java @@ -79,9 +79,6 @@ public ObjectStream create(String[] args) { CmdLineUtil.handleCreateObjectStreamError(ex); } - ADSentenceSampleStream sentenceStream = new ADSentenceSampleStream( - lineStream, includeTitle); - - return sentenceStream; + return new ADSentenceSampleStream(lineStream, includeTitle); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java index 275cf4d6c..549781609 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java @@ -138,9 +138,6 @@ public Sentence parse(String sentenceString, int para, boolean isTitle, boolean if(isBox) boxTag = " box"; if(start > 0) { meta = line.substring(0, start) + " p=" + para + titleTag + boxTag + metaFromSource; - } else { - // rare case were there is no space between id and the sentence. - // will use previous meta for now } } sentence.setText(text); @@ -154,7 +151,7 @@ public Sentence parse(String sentenceString, int para, boolean isTitle, boolean } // got the root. Add it to the stack - Stack nodeStack = new Stack(); + Stack nodeStack = new Stack<>(); root.setSyntacticTag("ROOT"); root.setLevel(0); @@ -381,7 +378,7 @@ public String getMorphologicalTag() { /** Represents the AD node */ public class Node extends TreeElement { - private List elems = new ArrayList(); + private List elems = new ArrayList<>(); public void addElement(TreeElement element) { elems.add(element); @@ -546,12 +543,10 @@ public Sentence read() throws IOException { if(sentenceStarted) { if (sentEnd.matcher(line).matches() || extEnd.matcher(line).matches()) { sentenceStarted = false; - } else if(line.startsWith("A1")) { - // skip - } else { + } else if (!line.startsWith("A1")) { sentence.append(line).append('\n'); } - } else { + } else { if (sentStart.matcher(line).matches()) { sentenceStarted = true; } else if(paraStart.matcher(line).matches()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/AnnotationConfiguration.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/AnnotationConfiguration.java index 723ddbc83..9ce5b3bee 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/AnnotationConfiguration.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/AnnotationConfiguration.java @@ -41,8 +41,7 @@ public class AnnotationConfiguration { public AnnotationConfiguration(Map typeToClassMap) { - this.typeToClassMap = Collections.unmodifiableMap( - new HashMap(typeToClassMap)); + this.typeToClassMap = Collections.unmodifiableMap(new HashMap<>(typeToClassMap)); } public String getTypeClass(String type) { @@ -51,7 +50,7 @@ public String getTypeClass(String type) { public static AnnotationConfiguration parse(InputStream in) throws IOException { - Map typeToClassMap = new HashMap(); + Map typeToClassMap = new HashMap<>(); BufferedReader reader = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8"))); @@ -63,9 +62,7 @@ public static AnnotationConfiguration parse(InputStream in) throws IOException { line = line.trim(); if (line.isEmpty()) { - continue; } else if (line.startsWith("#")) { - continue; } else if (line.startsWith("[") && line.endsWith("]")) { sectionType = line.substring(line.indexOf('[') + 1, line.indexOf(']')); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java index 9d4b0f2fe..91a29165b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratAnnotationStream.java @@ -141,8 +141,7 @@ BratAnnotation parse(Span[] values, CharSequence line) throws IOException { } } - private final Map parsers = - new HashMap(); + private final Map parsers = new HashMap<>(); private final AnnotationConfiguration config; private final BufferedReader reader; private final String id; diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratDocumentStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratDocumentStream.java index ba82089dc..4e702cc9e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratDocumentStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratDocumentStream.java @@ -33,7 +33,7 @@ public class BratDocumentStream implements ObjectStream { private AnnotationConfiguration config; - private List documentIds = new LinkedList(); + private List documentIds = new LinkedList<>(); private Iterator documentIdIterator; /** @@ -57,7 +57,7 @@ public BratDocumentStream(AnnotationConfiguration config, File bratCorpusDirecto this.config = config; - Stack directoryStack = new Stack(); + Stack directoryStack = new Stack<>(); directoryStack.add(bratCorpusDirectory); while (!directoryStack.isEmpty()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStream.java index 5bb574407..6f75c3e02 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/brat/BratNameSampleStream.java @@ -67,7 +67,7 @@ protected List read(BratDocument sample) throws IOException { // to be able to print warning a set of entities id must be maintained // to check if all entities have been used up after the matching is done - Set entityIdSet = new HashSet(); + Set entityIdSet = new HashSet<>(); for (BratAnnotation ann : sample.getAnnotations()) { if (ann instanceof SpanAnnotation) { @@ -93,7 +93,7 @@ protected List read(BratDocument sample) throws IOException { // Currently we are missing all - List samples = new ArrayList(sentences.length); + List samples = new ArrayList<>(sentences.length); for (Span sentence : sentences) { @@ -109,14 +109,14 @@ protected List read(BratDocument sample) throws IOException { // in the tokenIndexMap. // The tokenIndexMap maps to the sentence local token index. - Map tokenIndexMap = new HashMap(); + Map tokenIndexMap = new HashMap<>(); for (int i = 0; i < tokens.length; i++) { tokenIndexMap.put(-(sentence.getStart() + tokens[i].getStart()), i); tokenIndexMap.put(sentence.getStart() + tokens[i].getEnd(), i + 1); } - List names = new ArrayList(); + List names = new ArrayList<>(); for (BratAnnotation ann : sample.getAnnotations()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/AbstractToSentenceSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/AbstractToSentenceSampleStream.java index 5ef543a12..96434e77d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/AbstractToSentenceSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/AbstractToSentenceSampleStream.java @@ -54,7 +54,7 @@ public abstract class AbstractToSentenceSampleStream extends protected abstract String[] toSentence(T sample); public SentenceSample read() throws IOException { - List sentences = new ArrayList(); + List sentences = new ArrayList<>(); T posSample; int chunks = 0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStream.java index fd7dabd93..ad049e080 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/formats/convert/ParseToPOSSampleStream.java @@ -41,8 +41,8 @@ public POSSample read() throws IOException { if (parse != null) { - List sentence = new ArrayList(); - List tags = new ArrayList(); + List sentence = new ArrayList<>(); + List tags = new ArrayList<>(); for(Parse tagNode : parse.getTagNodes()) { sentence.add(tagNode.getCoveredText()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DefaultLemmatizerContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DefaultLemmatizerContextGenerator.java index e455f0187..4d6d083a6 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DefaultLemmatizerContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DefaultLemmatizerContextGenerator.java @@ -41,7 +41,7 @@ public DefaultLemmatizerContextGenerator() { protected static String[] getPrefixes(String lex) { String[] prefs = new String[PREFIX_LENGTH]; - for (int li = 1, ll = PREFIX_LENGTH; li < ll; li++) { + for (int li = 1; li < PREFIX_LENGTH; li++) { prefs[li] = lex.substring(0, Math.min(li + 1, lex.length())); } return prefs; @@ -49,7 +49,7 @@ protected static String[] getPrefixes(String lex) { protected static String[] getSuffixes(String lex) { String[] suffs = new String[SUFFIX_LENGTH]; - for (int li = 1, ll = SUFFIX_LENGTH; li < ll; li++) { + for (int li = 1; li < SUFFIX_LENGTH; li++) { suffs[li] = lex.substring(Math.max(lex.length() - li - 1, 0)); } return suffs; @@ -78,7 +78,7 @@ public String[] getContext(int index, String[] toks, String[] tags, String[] pre w0 = "w0=" + toks[index]; t0 = "t0=" + tags[index]; - List features = new ArrayList(); + List features = new ArrayList<>(); features.add(w0); features.add(t0); diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java index 0ae8e3711..dde2d089e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/DictionaryLemmatizer.java @@ -47,7 +47,7 @@ public class DictionaryLemmatizer implements Lemmatizer { * the input dictionary via inputstream */ public DictionaryLemmatizer(final InputStream dictionary) { - this.dictMap = new HashMap, String>(); + this.dictMap = new HashMap<>(); final BufferedReader breader = new BufferedReader(new InputStreamReader( dictionary)); String line; @@ -80,13 +80,13 @@ public HashMap, String> getDictMap() { * @return returns the dictionary keys */ private List getDictKeys(final String word, final String postag) { - final List keys = new ArrayList(); + final List keys = new ArrayList<>(); keys.addAll(Arrays.asList(word.toLowerCase(), postag)); return keys; } public String[] lemmatize(final String[] tokens, final String[] postags) { - List lemmas = new ArrayList(); + List lemmas = new ArrayList<>(); for (int i = 0; i < tokens.length; i++) { lemmas.add(this.apply(tokens[i], postags[i])); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java index fe6dd6946..a19adb44a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSample.java @@ -43,9 +43,9 @@ public LemmaSample(String[] tokens, String[] tags, String[] lemmas) { validateArguments(tokens.length, tags.length, lemmas.length); - this.tokens = Collections.unmodifiableList(new ArrayList(Arrays.asList(tokens))); - this.tags = Collections.unmodifiableList(new ArrayList(Arrays.asList(tags))); - this.lemmas = Collections.unmodifiableList(new ArrayList(Arrays.asList(lemmas))); + this.tokens = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tokens))); + this.tags = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(tags))); + this.lemmas = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(lemmas))); } /** @@ -58,9 +58,9 @@ public LemmaSample(List tokens, List tags, List lemmas) validateArguments(tokens.size(), tags.size(), lemmas.size()); - this.tokens = Collections.unmodifiableList(new ArrayList(tokens)); - this.tags = Collections.unmodifiableList(new ArrayList(tags)); - this.lemmas = Collections.unmodifiableList(new ArrayList(lemmas)); + this.tokens = Collections.unmodifiableList(new ArrayList<>(tokens)); + this.tags = Collections.unmodifiableList(new ArrayList<>(tags)); + this.lemmas = Collections.unmodifiableList(new ArrayList<>(lemmas)); } public String[] getTokens() { diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleEventStream.java index 2a71be2eb..1a46f4aaf 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleEventStream.java @@ -45,7 +45,7 @@ public LemmaSampleEventStream(ObjectStream d, LemmatizerContextGene protected Iterator createEvents(LemmaSample sample) { if (sample != null) { - List events = new ArrayList(); + List events = new ArrayList<>(); String[] toksArray = sample.getTokens(); String[] tagsArray = sample.getTags(); String[] lemmasArray = sample.getLemmas(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java index 1cdfbcf59..0940dc61d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleSequenceStream.java @@ -52,7 +52,7 @@ public Sequence read() throws IOException { events[i] = new Event(tags[i], context); } - return new Sequence(events,sample); + return new Sequence<>(events,sample); } return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleStream.java index b59ea076e..9a2a6f098 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmaSampleStream.java @@ -38,9 +38,9 @@ public LemmaSampleStream(ObjectStream samples) { public LemmaSample read() throws IOException { - List toks = new ArrayList(); - List tags = new ArrayList(); - List preds = new ArrayList(); + List toks = new ArrayList<>(); + List tags = new ArrayList<>(); + List preds = new ArrayList<>(); for (String line = samples.read(); line != null && !line.equals(""); line = samples.read()) { String[] parts = line.split("\t"); @@ -55,8 +55,8 @@ public LemmaSample read() throws IOException { } } if (toks.size() > 0) { - LemmaSample lemmaSample = new LemmaSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), preds.toArray(new String[preds.size()])); - return lemmaSample; + return new LemmaSample(toks.toArray(new String[toks.size()]), tags.toArray(new String[tags.size()]), + preds.toArray(new String[preds.size()])); } else { return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/Lemmatizer.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/Lemmatizer.java index 2b6ab1efd..d09a8a37f 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/Lemmatizer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/Lemmatizer.java @@ -29,6 +29,6 @@ public interface Lemmatizer { * * @return an array of lemma classes for each token in the sequence. */ - public String[] lemmatize(String[] toks, String tags[]); + String[] lemmatize(String[] toks, String tags[]); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerContextGenerator.java index 5ea10c1af..951334299 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/lemmatizer/LemmatizerContextGenerator.java @@ -31,6 +31,6 @@ public interface LemmatizerContextGenerator extends BeamSearchContextGenerator(beamSize, + this.model = new opennlp.tools.ml.BeamSearch<>(beamSize, (MaxentModel) model.getLemmatizerSequenceModel(), 0); } } @@ -97,7 +97,7 @@ public String[] lemmatize(String[] toks, String[] tags) { * @return the array of decoded lemmas */ public String[] decodeLemmas(String[] toks, String[] preds) { - List lemmas = new ArrayList(); + List lemmas = new ArrayList<>(); for (int i = 0; i < toks.length; i++) { String lemma = StringUtil.decodeShortestEditScript(toks[i].toLowerCase(), preds[i]); //System.err.println("-> DEBUG: " + toks[i].toLowerCase() + " " + preds[i] + " " + lemma); @@ -153,7 +153,7 @@ public static LemmatizerModel train(String languageCode, LemmatizerContextGenerator contextGenerator = posFactory.getContextGenerator(); - Map manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); TrainerType trainerType = TrainerFactory.getTrainerType(trainParams.getSettings()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java index 19c9a790b..207f830e7 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/TrainerFactory.java @@ -42,7 +42,7 @@ public enum TrainerType { private static final Map BUILTIN_TRAINERS; static { - Map _trainers = new HashMap(); + Map _trainers = new HashMap<>(); _trainers.put(GIS.MAXENT_VALUE, GIS.class); _trainers.put(QNTrainer.MAXENT_QN_VALUE, QNTrainer.class); _trainers.put(PerceptronTrainer.PERCEPTRON_VALUE, PerceptronTrainer.class); @@ -89,21 +89,21 @@ else if (SequenceTrainer.class.isAssignableFrom(trainerClass)) { ExtensionLoader.instantiateExtension(EventTrainer.class, alogrithmValue); return TrainerType.EVENT_MODEL_TRAINER; } - catch (ExtensionNotLoadedException e) { + catch (ExtensionNotLoadedException ignored) { } try { ExtensionLoader.instantiateExtension(EventModelSequenceTrainer.class, alogrithmValue); return TrainerType.EVENT_MODEL_SEQUENCE_TRAINER; } - catch (ExtensionNotLoadedException e) { + catch (ExtensionNotLoadedException ignored) { } try { ExtensionLoader.instantiateExtension(SequenceTrainer.class, alogrithmValue); return TrainerType.SEQUENCE_TRAINER; } - catch (ExtensionNotLoadedException e) { + catch (ExtensionNotLoadedException ignored) { } return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/DataStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/DataStream.java index 769e138fb..f8a026820 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/DataStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/DataStream.java @@ -32,13 +32,13 @@ public interface DataStream { * * @return the Object representing the data which is next in this DataStream */ - public Object nextToken(); + Object nextToken(); /** * Test whether there are any Events remaining in this EventStream. * * @return true if this DataStream has more data tokens */ - public boolean hasNext(); + boolean hasNext(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GIS.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GIS.java index 194664ef0..7a57aa750 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GIS.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/GIS.java @@ -63,11 +63,7 @@ public boolean isValid() { String algorithmName = getAlgorithm(); - if (algorithmName != null && !(MAXENT_VALUE.equals(algorithmName))) { - return false; - } - - return true; + return !(algorithmName != null && !(MAXENT_VALUE.equals(algorithmName))); } public boolean isSortAndMerge() { diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java index 97ff167f1..f2c3b82b1 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/RealBasicEventStream.java @@ -27,7 +27,7 @@ public class RealBasicEventStream implements ObjectStream { ContextGenerator cg = new BasicContextGenerator(); - ObjectStream ds; + private ObjectStream ds; public RealBasicEventStream(ObjectStream ds) { this.ds = ds; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/BinaryGISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/BinaryGISModelWriter.java index 3faf337b4..5c3503d37 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/BinaryGISModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/BinaryGISModelWriter.java @@ -31,7 +31,7 @@ * Model writer that saves models in binary format. */ public class BinaryGISModelWriter extends GISModelWriter { - DataOutputStream output; + private DataOutputStream output; /** * Constructor which takes a GISModel and a File and prepares itself to write diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java index a1120bf50..45bc5c869 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/GISModelWriter.java @@ -123,7 +123,6 @@ protected ComparablePredicate[] sortValues() { int[] predkeys = PARAMS[pid].getOutcomes(); // Arrays.sort(predkeys); int numActive = predkeys.length; - int[] activeOutcomes = predkeys; double[] activeParams = PARAMS[pid].getParameters(); numParams += numActive; @@ -135,7 +134,7 @@ protected ComparablePredicate[] sortValues() { * PARAMS[pid].getParams(oid); id++; } */ sortPreds[pid] = new ComparablePredicate(PRED_LABELS[pid], - activeOutcomes, activeParams); + predkeys, activeParams); } Arrays.sort(sortPreds); @@ -143,17 +142,17 @@ protected ComparablePredicate[] sortValues() { } protected List> compressOutcomes(ComparablePredicate[] sorted) { - List> outcomePatterns = new ArrayList>(); + List> outcomePatterns = new ArrayList<>(); if(sorted.length > 0) { ComparablePredicate cp = sorted[0]; - List newGroup = new ArrayList(); + List newGroup = new ArrayList<>(); for (int i = 0; i < sorted.length; i++) { if (cp.compareTo(sorted[i]) == 0) { newGroup.add(sorted[i]); } else { cp = sorted[i]; outcomePatterns.add(newGroup); - newGroup = new ArrayList(); + newGroup = new ArrayList<>(); newGroup.add(sorted[i]); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java index 31d60410a..831569261 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java @@ -35,7 +35,7 @@ * which stores the parameters. */ public class OldFormatGISModelReader extends PlainTextGISModelReader { - DataInputStream paramsInput; + private DataInputStream paramsInput; /** * Constructor which takes the name of the model without any suffixes, such as @@ -68,9 +68,7 @@ protected Context[] getParameters(int[][] outcomePatterns) for (int i = 0; i < outcomePatterns.length; i++) { // construct outcome pattern int[] outcomePattern = new int[outcomePatterns[i].length - 1]; - for (int k = 1; k < outcomePatterns[i].length; k++) { - outcomePattern[k - 1] = outcomePatterns[i][k]; - } + System.arraycopy(outcomePatterns[i], 1, outcomePattern, 0, outcomePatterns[i].length - 1); // populate parameters for each context which uses this outcome pattern. for (int j = 0; j < outcomePatterns[i][0]; j++) { double[] contextParameters = new double[outcomePatterns[i].length - 1]; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java index 3ef5c48fb..af94871e0 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java @@ -21,20 +21,18 @@ import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.zip.GZIPOutputStream; - import opennlp.tools.ml.model.AbstractModel; /** * Model writer that saves models in plain text format. */ public class PlainTextGISModelWriter extends GISModelWriter { - BufferedWriter output; + private BufferedWriter output; /** * Constructor which takes a GISModel and a File and prepares itself to @@ -45,7 +43,7 @@ public class PlainTextGISModelWriter extends GISModelWriter { * @param f The File in which the model is to be persisted. */ public PlainTextGISModelWriter (AbstractModel model, File f) - throws IOException, FileNotFoundException { + throws IOException { super(model); if (f.getName().endsWith(".gz")) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java index 4bc6fd6c9..b6ba70565 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java @@ -76,8 +76,7 @@ public SuffixSensitiveGISModelReader(File f) throws IOException { * inspect a few of them as plain text files. */ public static void main(String[] args) throws IOException { - AbstractModel m = new SuffixSensitiveGISModelReader(new File(args[0])) - .getModel(); + AbstractModel m = new SuffixSensitiveGISModelReader(new File(args[0])).getModel(); new SuffixSensitiveGISModelWriter(m, new File(args[1])).persist(); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java index 00cb55b6a..bbe8d1b18 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/quasinewton/ParallelNegLogLikelihood.java @@ -35,7 +35,7 @@ public class ParallelNegLogLikelihood extends NegLogLikelihood { // Number of threads - int threads; + private int threads; // Partial value of negative log-likelihood to be computed by each thread private double[] negLogLikelihoodThread; @@ -113,7 +113,7 @@ private void computeInParallel(double[] x, Class taskClas ParallelNegLogLikelihood.class, int.class, int.class, int.class, double[].class); - List> futures = new ArrayList>(); + List> futures = new ArrayList<>(); for (int i = 0; i < threads; i++) { if (i != threads - 1) futures.add(executor.submit( diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/MaxentModel.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/MaxentModel.java index e8f9e28bb..a5fd18402 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/MaxentModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/MaxentModel.java @@ -33,7 +33,7 @@ public interface MaxentModel { * outcomes, all of which sum to 1. * **/ - public double[] eval(String[] context); + double[] eval(String[] context); /** * Evaluates a context. @@ -44,7 +44,7 @@ public interface MaxentModel { * outcomes, all of which sum to 1. * @return an array of the probabilities for each of the different outcomes, all of which sum to 1. **/ - public double[] eval(String[] context, double probs[]); + double[] eval(String[] context, double probs[]); /** * Evaluates a contexts with the specified context values. @@ -53,7 +53,7 @@ public interface MaxentModel { * @param values The values associated with each context. * @return an array of the probabilities for each of the different outcomes, all of which sum to 1. */ - public double[] eval(String[] context, float[] values); + double[] eval(String[] context, float[] values); /** * Simple function to return the outcome associated with the index @@ -64,7 +64,7 @@ public interface MaxentModel { * method. * @return the String name of the best outcome **/ - public String getBestOutcome(double[] outcomes); + String getBestOutcome(double[] outcomes); /** * Return a string matching all the outcome names with all the @@ -79,7 +79,7 @@ public interface MaxentModel { * for each one. **/ // TODO: This should be removed, can't be used anyway without format spec - public String getAllOutcomes(double[] outcomes); + String getAllOutcomes(double[] outcomes); /** * Gets the String name of the outcome associated with the index @@ -89,7 +89,7 @@ public interface MaxentModel { * desired. * @return the String name of the outcome **/ - public String getOutcome(int i); + String getOutcome(int i); /** * Gets the index associated with the String name of the given @@ -100,9 +100,9 @@ public interface MaxentModel { * @return the index if the given outcome label exists for this * model, -1 if it does not. **/ - public int getIndex(String outcome); + int getIndex(String outcome); - /** + /* * Returns the data structures relevant to storing the model. **/ // public Object[] getDataStructures(); @@ -110,6 +110,6 @@ public interface MaxentModel { /** Returns the number of outcomes for this model. * @return The number of outcomes. **/ - public int getNumOutcomes(); + int getNumOutcomes(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/OnePassDataIndexer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/OnePassDataIndexer.java index 5b9b1cbe0..a01b050da 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/OnePassDataIndexer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/OnePassDataIndexer.java @@ -68,7 +68,7 @@ public OnePassDataIndexer(ObjectStream eventStream, int cutoff) */ public OnePassDataIndexer(ObjectStream eventStream, int cutoff, boolean sort) throws IOException { - Map predicateIndex = new HashMap(); + Map predicateIndex = new HashMap<>(); LinkedList events; List eventsToCompare; @@ -108,9 +108,9 @@ public OnePassDataIndexer(ObjectStream eventStream, int cutoff, boolean s */ private LinkedList computeEventCounts(ObjectStream eventStream, Map predicatesInOut, int cutoff) throws IOException { - Set predicateSet = new HashSet(); - Map counter = new HashMap(); - LinkedList events = new LinkedList(); + Set predicateSet = new HashSet<>(); + Map counter = new HashMap<>(); + LinkedList events = new LinkedList<>(); Event ev; while ((ev = eventStream.read()) != null) { events.addLast(ev); @@ -128,12 +128,12 @@ private LinkedList computeEventCounts(ObjectStream eventStream, protected List index(LinkedList events, Map predicateIndex) { - Map omap = new HashMap(); + Map omap = new HashMap<>(); int numEvents = events.size(); int outcomeCount = 0; - List eventsToCompare = new ArrayList(numEvents); - List indexedContext = new ArrayList(); + List eventsToCompare = new ArrayList<>(numEvents); + List indexedContext = new ArrayList<>(); for (int eventIndex = 0; eventIndex < numEvents; eventIndex++) { Event ev = events.removeFirst(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/Prior.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/Prior.java index 9a7fb1137..ad78172f3 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/Prior.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/Prior.java @@ -31,7 +31,7 @@ public interface Prior { * @param dist An array to be populated with the log of the prior distribution. * @param context The indices of the contextual predicates for an event. */ - public void logPrior(double[] dist, int[] context); + void logPrior(double[] dist, int[] context); /** * Populates the specified array with the the log of the distribution for the specified context. @@ -40,7 +40,7 @@ public interface Prior { * @param context The indices of the contextual predicates for an event. * @param values The values associated with the context. */ - public void logPrior(double[] dist, int[] context, float[] values); + void logPrior(double[] dist, int[] context, float[] values); /** * Method to specify the label for the outcomes and contexts. This is used to map @@ -49,5 +49,5 @@ public interface Prior { * @param outcomeLabels An array of each outcome label. * @param contextLabels An array of each context label. */ - public void setLabels(String[] outcomeLabels, String[] contextLabels); + void setLabels(String[] outcomeLabels, String[] contextLabels); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java index 7d5dc4d34..28bb44999 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/SequenceStream.java @@ -32,6 +32,6 @@ public interface SequenceStream extends ObjectStream { * @param sequence The sequence to be evaluated. * @return event array */ - public Event[] updateContext(Sequence sequence, AbstractModel model); + Event[] updateContext(Sequence sequence, AbstractModel model); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/TwoPassDataIndexer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/TwoPassDataIndexer.java index 821335bf7..86fb6a5b5 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/TwoPassDataIndexer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/TwoPassDataIndexer.java @@ -70,7 +70,7 @@ public TwoPassDataIndexer(ObjectStream eventStream, int cutoff) throws IO * observed in order to be included in the model. */ public TwoPassDataIndexer(ObjectStream eventStream, int cutoff, boolean sort) throws IOException { - Map predicateIndex = new HashMap(); + Map predicateIndex = new HashMap<>(); List eventsToCompare; System.out.println("Indexing events using cutoff of " + cutoff + "\n"); @@ -118,10 +118,11 @@ public TwoPassDataIndexer(ObjectStream eventStream, int cutoff, boolean s * @param predicatesInOut a TObjectIntHashMap value * @param cutoff an int value */ - private int computeEventCounts(ObjectStream eventStream, Writer eventStore, Map predicatesInOut, int cutoff) throws IOException { - Map counter = new HashMap(); + private int computeEventCounts(ObjectStream eventStream, Writer eventStore, + Map predicatesInOut, int cutoff) throws IOException { + Map counter = new HashMap<>(); int eventCount = 0; - Set predicateSet = new HashSet(); + Set predicateSet = new HashSet<>(); Event ev; while ((ev = eventStream.read()) != null) { @@ -142,10 +143,10 @@ private int computeEventCounts(ObjectStream eventStream, Writer eventStor } private List index(int numEvents, ObjectStream es, Map predicateIndex) throws IOException { - Map omap = new HashMap(); + Map omap = new HashMap<>(); int outcomeCount = 0; - List eventsToCompare = new ArrayList(numEvents); - List indexedContext = new ArrayList(); + List eventsToCompare = new ArrayList<>(numEvents); + List indexedContext = new ArrayList<>(); Event ev; while ((ev = es.read()) != null) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java index dd91ff923..0814cf3f5 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/LogProbabilities.java @@ -159,7 +159,7 @@ public Double getLog(T t) { public void discardCountsBelow(double i) { i = Math.log(i); - ArrayList labelsToRemove = new ArrayList(); + ArrayList labelsToRemove = new ArrayList<>(); for (T label : map.keySet()) { Double sum = map.get(label); if (sum == null) sum = Double.NEGATIVE_INFINITY; diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModel.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModel.java index 05503fad5..35eaa26b2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModel.java @@ -91,7 +91,7 @@ public static double[] eval(int[] context, double[] prior, EvalParameters model) } public static double[] eval(int[] context, float[] values, double[] prior, EvalParameters model, boolean normalize) { - Probabilities probabilities = new LogProbabilities(); + Probabilities probabilities = new LogProbabilities<>(); Context[] params = model.getParams(); double[] outcomeTotals = model instanceof NaiveBayesEvalParameters ? ((NaiveBayesEvalParameters) model).getOutcomeTotals() : new double[prior.length]; long vocabulary = model instanceof NaiveBayesEvalParameters ? ((NaiveBayesEvalParameters) model).getVocabulary() : 0; @@ -121,8 +121,7 @@ public static double[] eval(int[] context, float[] values, double[] prior, EvalP } for (int i = 0; i < outcomeTotals.length; ++i) { double numerator = outcomeTotals[i]; - double denominator = total; - probabilities.addIn(i, numerator / denominator, 1); + probabilities.addIn(i, numerator / total, 1); } for (int i = 0; i < outcomeTotals.length; ++i) { prior[i] = probabilities.get(i); @@ -141,9 +140,8 @@ else if (denominator == 0 || denominator < Double.MIN_VALUE) private static double getSmoothedProbability(double numerator, double denominator, double vocabulary) { final double delta = 0.05; // Lidstone smoothing - final double featureVocabularySize = vocabulary; - return 1.0 * (numerator + delta) / (denominator + delta * featureVocabularySize); + return 1.0 * (numerator + delta) / (denominator + delta * vocabulary); } public static void main(String[] args) throws java.io.IOException { diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java index eb17aef93..d1a9263d2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesModelWriter.java @@ -98,15 +98,15 @@ protected ComparablePredicate[] sortValues() { protected List> computeOutcomePatterns(ComparablePredicate[] sorted) { ComparablePredicate cp = sorted[0]; - List> outcomePatterns = new ArrayList>(); - List newGroup = new ArrayList(); + List> outcomePatterns = new ArrayList<>(); + List newGroup = new ArrayList<>(); for (ComparablePredicate predicate : sorted) { if (cp.compareTo(predicate) == 0) { newGroup.add(predicate); } else { cp = predicate; outcomePatterns.add(newGroup); - newGroup = new ArrayList(); + newGroup = new ArrayList<>(); newGroup.add(predicate); } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java index c3870f9a6..b39b65940 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/NaiveBayesTrainer.java @@ -147,7 +147,7 @@ private MutableContext[] findParameters() { for (int oi = 0; oi < numOutcomes; oi++) allOutcomesPattern[oi] = oi; - /** Stores the estimated parameter value of each predicate during iteration. */ + /* Stores the estimated parameter value of each predicate during iteration. */ MutableContext[] params = new MutableContext[numPreds]; for (int pi = 0; pi < numPreds; pi++) { params[pi] = new MutableContext(allOutcomesPattern, new double[numOutcomes]); diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/PlainTextNaiveBayesModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/PlainTextNaiveBayesModelWriter.java index 704741969..5aa0682df 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/PlainTextNaiveBayesModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/PlainTextNaiveBayesModelWriter.java @@ -21,20 +21,18 @@ import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.zip.GZIPOutputStream; - import opennlp.tools.ml.model.AbstractModel; /** * Model writer that saves models in plain text format. */ public class PlainTextNaiveBayesModelWriter extends NaiveBayesModelWriter { - BufferedWriter output; + private BufferedWriter output; /** * Constructor which takes a NaiveBayesModel and a File and prepares itself to @@ -45,7 +43,7 @@ public class PlainTextNaiveBayesModelWriter extends NaiveBayesModelWriter { * @param f The File in which the model is to be persisted. */ public PlainTextNaiveBayesModelWriter(AbstractModel model, File f) - throws IOException, FileNotFoundException { + throws IOException { super(model); if (f.getName().endsWith(".gz")) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java index 4c537370f..394a4c6f1 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/naivebayes/Probabilities.java @@ -26,7 +26,7 @@ * */ public abstract class Probabilities { - protected HashMap map = new HashMap(); + protected HashMap map = new HashMap<>(); protected transient boolean isNormalised = false; protected Map normalised; @@ -159,7 +159,7 @@ private Map normalize() { } protected Map createMapDataStructure() { - return new HashMap(); + return new HashMap<>(); } /** @@ -190,7 +190,7 @@ public double getMaxValue() { } public void discardCountsBelow(double i) { - ArrayList labelsToRemove = new ArrayList(); + ArrayList labelsToRemove = new ArrayList<>(); for (T label : map.keySet()) { Double sum = map.get(label); if (sum == null) sum = 0.0; diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/BilouCodec.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/BilouCodec.java index 633ba35c0..7e8508a84 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/BilouCodec.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/BilouCodec.java @@ -37,7 +37,7 @@ public class BilouCodec implements SequenceCodec { public Span[] decode(List c) { int start = -1; int end = -1; - List spans = new ArrayList(c.size()); + List spans = new ArrayList<>(c.size()); for (int li = 0; li < c.size(); li++) { String chunkTag = c.get(li); if (chunkTag.endsWith(BioCodec.START)) { @@ -57,9 +57,6 @@ else if (chunkTag.endsWith(LAST)) { else if (chunkTag.endsWith(UNIT)) { spans.add(new Span(li, li + 1, BioCodec.extractNameType(c.get(li)))); } - else if (chunkTag.endsWith(BioCodec.OTHER)) { - // in this case do nothing - } } return spans.toArray(new Span[spans.size()]); diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/BioCodec.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/BioCodec.java index 1367f2848..150208129 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/BioCodec.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/BioCodec.java @@ -33,11 +33,10 @@ public class BioCodec implements SequenceCodec { private static final Pattern typedOutcomePattern = Pattern.compile("(.+)-\\w+"); - static final String extractNameType(String outcome) { + static String extractNameType(String outcome) { Matcher matcher = typedOutcomePattern.matcher(outcome); if(matcher.matches()) { - String nameType = matcher.group(1); - return nameType; + return matcher.group(1); } return null; @@ -46,7 +45,7 @@ static final String extractNameType(String outcome) { public Span[] decode(List c) { int start = -1; int end = -1; - List spans = new ArrayList(c.size()); + List spans = new ArrayList<>(c.size()); for (int li = 0; li < c.size(); li++) { String chunkTag = c.get(li); if (chunkTag.endsWith(BioCodec.START)) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java index a8d249fa0..108efa67d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/DictionaryNameFinder.java @@ -63,7 +63,7 @@ public DictionaryNameFinder(Dictionary dictionary) { } public Span[] find(String[] textTokenized) { - List namesFound = new LinkedList(); + List namesFound = new LinkedList<>(); for (int offsetFrom = 0; offsetFrom < textTokenized.length; offsetFrom++) { Span nameFound = null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/DocumentNameFinder.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/DocumentNameFinder.java index 130699a53..c1c1b2d9d 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/DocumentNameFinder.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/DocumentNameFinder.java @@ -36,6 +36,6 @@ public interface DocumentNameFinder { * @param document An array of tokens for each sentence of a document. * @return The token spans for each sentence of the specified document. */ - public abstract Span[][] find(String[][] document); + Span[][] find(String[][] document); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameContextGenerator.java index b10db438a..be3ee2ee7 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameContextGenerator.java @@ -30,18 +30,18 @@ public interface NameContextGenerator extends BeamSearchContextGenerator * Adds a feature generator to this set of feature generators. * @param generator The feature generator to add. */ - public void addFeatureGenerator(AdaptiveFeatureGenerator generator); + void addFeatureGenerator(AdaptiveFeatureGenerator generator); /** * Informs all the feature generators for a name finder that the specified tokens have been classified with the coorisponds set of specified outcomes. * @param tokens The tokens of the sentence or other text unit which has been processed. * @param outcomes The outcomes associated with the specified tokens. */ - public void updateAdaptiveData(String[] tokens, String[] outcomes); + void updateAdaptiveData(String[] tokens, String[] outcomes); /** * Informs all the feature generators for a name finder that the context of the adaptive data (typically a document) is no longer valid. */ - public void clearAdaptiveData(); + void clearAdaptiveData(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java index b20971f00..65b01c58a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderEventStream.java @@ -39,8 +39,6 @@ public class NameFinderEventStream extends opennlp.tools.util.AbstractEventStrea private AdditionalContextFeatureGenerator additionalContextFeatureGenerator = new AdditionalContextFeatureGenerator(); - private String type; - private SequenceCodec codec; /** @@ -61,10 +59,11 @@ public NameFinderEventStream(ObjectStream dataStream, String type, N this.contextGenerator = contextGenerator; this.contextGenerator.addFeatureGenerator(new WindowFeatureGenerator(additionalContextFeatureGenerator, 8, 8)); + String type1; if (type != null) - this.type = type; + type1 = type; else - this.type = "default"; + type1 = "default"; } public NameFinderEventStream(ObjectStream dataStream) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java index 18249096e..00e001ce2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameFinderME.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - import opennlp.tools.ml.BeamSearch; import opennlp.tools.ml.EventModelSequenceTrainer; import opennlp.tools.ml.EventTrainer; @@ -54,7 +53,6 @@ import opennlp.tools.util.featuregen.TokenClassFeatureGenerator; import opennlp.tools.util.featuregen.TokenFeatureGenerator; import opennlp.tools.util.featuregen.WindowFeatureGenerator; -import opennlp.tools.util.model.ModelUtil; /** * Class for creating a maximum-entropy-based name finder. @@ -95,7 +93,7 @@ public NameFinderME(TokenNameFinderModel model) { } @Deprecated - /** + /* * @deprecated the default feature generation is now always included in the models and loaded * if not by the factory. Subclasses using this methods should do the same. */ @@ -253,7 +251,7 @@ public static TokenNameFinderModel train(String languageCode, String type, beamSize = Integer.parseInt(beamSizeString); } - Map manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); MaxentModel nameFinderModel = null; @@ -327,7 +325,7 @@ static TokenNameFinderModel train(String languageCode, String type, ObjectStream beamSize = Integer.parseInt(beamSizeString); } - Map manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); AdaptiveFeatureGenerator featureGenerator; @@ -418,11 +416,10 @@ static TokenNameFinderModel train(String languageCode, String type, * @param outcome the outcome * @return the name type, or null if not set */ - static final String extractNameType(String outcome) { + static String extractNameType(String outcome) { Matcher matcher = typedOutcomePattern.matcher(outcome); if (matcher.matches()) { - String nameType = matcher.group(1); - return nameType; + return matcher.group(1); } return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java index 1fba7583d..e1dc80198 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java @@ -55,8 +55,8 @@ public NameSample(String id, String[] sentence, Span[] names, names = new Span[0]; } - this.sentence = Collections.unmodifiableList(new ArrayList(Arrays.asList(sentence))); - this.names = Collections.unmodifiableList(new ArrayList(Arrays.asList(names))); + this.sentence = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(sentence))); + this.names = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(names))); if (additionalContext != null) { this.additionalContext = new String[additionalContext.length][]; @@ -215,8 +215,8 @@ public static NameSample parse(String taggedTokens, String defaultType, throws IOException { String[] parts = WhitespaceTokenizer.INSTANCE.tokenize(taggedTokens); - List tokenList = new ArrayList(parts.length); - List nameList = new ArrayList(); + List tokenList = new ArrayList<>(parts.length); + List nameList = new ArrayList<>(); String nameType = defaultType; int startIndex = -1; diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java index e5a9f438e..22c855068 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java @@ -70,9 +70,8 @@ public NameSampleSequenceStream(ObjectStream psi, NameContextGenerat @SuppressWarnings("unchecked") public Event[] updateContext(Sequence sequence, AbstractModel model) { - Sequence pss = sequence; TokenNameFinder tagger = new NameFinderME(new TokenNameFinderModel("x-unspecified", model, Collections.emptyMap(), null)); - String[] sentence = pss.getSource().getSentence(); + String[] sentence = ((Sequence) sequence).getSource().getSentence(); String[] tags = seqCodec.encode(tagger.find(sentence), sentence.length); Event[] events = new Event[sentence.length]; @@ -103,8 +102,7 @@ public Sequence read() throws IOException { events[i] = new Event(tags[i], context); } - Sequence sequence = new Sequence(events,sample); - return sequence; + return new Sequence<>(events,sample); } else { return null; diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleTypeFilter.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleTypeFilter.java index 7dabced17..9ae1dc918 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleTypeFilter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleTypeFilter.java @@ -38,12 +38,12 @@ public class NameSampleTypeFilter extends FilterObjectStream samples) { super(samples); - this.types = Collections.unmodifiableSet(new HashSet(Arrays.asList(types))); + this.types = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(types))); } public NameSampleTypeFilter(Set types, ObjectStream samples) { super(samples); - this.types = Collections.unmodifiableSet(new HashSet(types)); + this.types = Collections.unmodifiableSet(new HashSet<>(types)); } public NameSample read() throws IOException { @@ -52,7 +52,7 @@ public NameSample read() throws IOException { if (sample != null) { - List filteredNames = new ArrayList(); + List filteredNames = new ArrayList<>(); for (Span name : sample.getNames()) { if (types.contains(name.getType())) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java index b72d3a966..261321bd4 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java @@ -100,11 +100,11 @@ public static void main(String[] args) { } } - public static interface RegexAble { + public interface RegexAble { - public Map getRegexMap(); + Map getRegexMap(); - public String getType(); + String getType(); } public enum DEFAULT_REGEX_NAME_FINDER implements RegexAble { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java index 48451e2ee..6da6f4e51 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java @@ -28,7 +28,7 @@ public interface TokenNameFinder { * @param tokens an array of the tokens or words of the sequence, typically a sentence. * @return an array of spans for each of the names identified. */ - public Span[] find(String tokens[]); + Span[] find(String tokens[]); /** * Forgets all adaptive data which was collected during previous @@ -36,6 +36,6 @@ public interface TokenNameFinder { * * This method is typical called at the end of a document. */ - public void clearAdaptiveData(); + void clearAdaptiveData(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java index fa93bcec5..3d2547ba0 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java @@ -60,7 +60,7 @@ protected NameToDocumentSampleStream(ObjectStream samples) { public DocumentSample read() throws IOException { - List document = new ArrayList(); + List document = new ArrayList<>(); if (beginSample == null) { // Assume that the clear flag is set @@ -143,7 +143,6 @@ public NameSample read() throws IOException { private TokenNameFinderEvaluationMonitor[] listeners; private FMeasure fmeasure = new FMeasure(); - private SequenceCodec codec; private TokenNameFinderFactory factory; /** @@ -175,7 +174,6 @@ public TokenNameFinderCrossValidator(String languageCode, String type, this.params = trainParams; this.listeners = listeners; - this.codec = codec; } public TokenNameFinderCrossValidator(String languageCode, String type, @@ -209,7 +207,7 @@ public void evaluate(ObjectStream samples, int nFolds) // Note: The name samples need to be grouped on a document basis. - CrossValidationPartitioner partitioner = new CrossValidationPartitioner( + CrossValidationPartitioner partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderEvaluator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderEvaluator.java index c2146f029..fb689abea 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderEvaluator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderEvaluator.java @@ -22,9 +22,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; - import opennlp.tools.cmdline.PerformanceMonitor; -import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.ObjectStream; import opennlp.tools.util.PlainTextByLineStream; import opennlp.tools.util.Span; @@ -103,8 +101,7 @@ public FMeasure getFMeasure() { } @Deprecated - public static void main(String[] args) throws IOException, - InvalidFormatException { + public static void main(String[] args) throws IOException { if (args.length == 4) { @@ -150,8 +147,5 @@ public void close() throws IOException { System.out.println("Recall: " + evaluator.getFMeasure().getRecallScore()); System.out.println("Precision: " + evaluator.getFMeasure().getPrecisionScore()); } - else { - // usage: -encoding code test.file model.file - } } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java index 6bae7bced..a4780f544 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java @@ -116,15 +116,15 @@ public TokenNameFinderModel(String languageCode, MaxentModel nameFinderModel, this(languageCode, nameFinderModel, null, resources, manifestInfoEntries); } - public TokenNameFinderModel(InputStream in) throws IOException, InvalidFormatException { + public TokenNameFinderModel(InputStream in) throws IOException { super(COMPONENT_NAME, in); } - public TokenNameFinderModel(File modelFile) throws IOException, InvalidFormatException { + public TokenNameFinderModel(File modelFile) throws IOException { super(COMPONENT_NAME, modelFile); } - public TokenNameFinderModel(URL modelURL) throws IOException, InvalidFormatException { + public TokenNameFinderModel(URL modelURL) throws IOException { super(COMPONENT_NAME, modelURL); } @@ -291,14 +291,9 @@ boolean isModelValid(MaxentModel model) { protected void validateArtifactMap() throws InvalidFormatException { super.validateArtifactMap(); - if (artifactMap.get(MAXENT_MODEL_ENTRY_NAME) instanceof MaxentModel || - artifactMap.get(MAXENT_MODEL_ENTRY_NAME) instanceof SequenceClassificationModel) { - // TODO: Check should be performed on the possible outcomes! -// MaxentModel model = (MaxentModel) artifactMap.get(MAXENT_MODEL_ENTRY_NAME); -// isModelValid(model); - } - else { - throw new InvalidFormatException("Token Name Finder model is incomplete!"); - } + if (!(artifactMap.get(MAXENT_MODEL_ENTRY_NAME) instanceof MaxentModel) && + !(artifactMap.get(MAXENT_MODEL_ENTRY_NAME) instanceof SequenceClassificationModel)) { + throw new InvalidFormatException("Token Name Finder model is incomplete!"); + } } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramModel.java b/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramModel.java index e4b0cbc92..0e597e068 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramModel.java @@ -44,7 +44,7 @@ public class NGramModel implements Iterable{ protected static final String COUNT = "count"; - private Map mNGrams = new HashMap(); + private Map mNGrams = new HashMap<>(); /** * Initializes an empty instance. diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java index 3fabfd27a..10c3f0ec6 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java @@ -181,9 +181,9 @@ public AbstractBottomUpParser(POSTagger tagger, Chunker chunker, HeadRules headR reportFailedParse = true; this.headRules = headRules; this.punctSet = headRules.getPunctuationTags(); - odh = new ListHeap(K); - ndh = new ListHeap(K); - completeParses = new ListHeap(K); + odh = new ListHeap<>(K); + ndh = new ListHeap<>(K); + completeParses = new ListHeap<>(K); } /** @@ -217,7 +217,7 @@ public static void setParents(Parse p) { * @return An array of parses which is a subset of chunks with punctuation removed. */ public static Parse[] collapsePunctuation(Parse[] chunks, Set punctSet) { - List collapsedParses = new ArrayList(chunks.length); + List collapsedParses = new ArrayList<>(chunks.length); int lastNonPunct = -1; int nextNonPunct; for (int ci=0,cn=chunks.length;ci 0 && (completeParses.size() < M || (odh.first()).getProb() < minComplete) && derivationStage < maxDerivationLength) { - ndh = new ListHeap(K); + ndh = new ListHeap<>(K); int derivationRank = 0; for (Iterator pi = odh.iterator(); pi.hasNext() && derivationRank < K; derivationRank++) { // forearch derivation diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractParserEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractParserEventStream.java index 9d72bf896..079da7eb3 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractParserEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractParserEventStream.java @@ -66,7 +66,7 @@ else if (etype == ParserEventTypeEnum.TAG) { @Override protected Iterator createEvents(Parse sample) { - List newEvents = new ArrayList(); + List newEvents = new ArrayList<>(); Parse.pruneParse(sample); if (fixPossesives) { @@ -96,7 +96,7 @@ public AbstractParserEventStream(ObjectStream d, HeadRules rules, ParserE } public static Parse[] getInitialChunks(Parse p) { - List chunks = new ArrayList(); + List chunks = new ArrayList<>(); getInitialChunks(p, chunks); return chunks.toArray(new Parse[chunks.size()]); } @@ -134,9 +134,9 @@ private static void getInitialChunks(Parse p, List ichunks) { protected abstract void addParseEvents(List newEvents, Parse[] chunks); private void addChunkEvents(List chunkEvents, Parse[] chunks) { - List toks = new ArrayList(); - List tags = new ArrayList(); - List preds = new ArrayList(); + List toks = new ArrayList<>(); + List tags = new ArrayList<>(); + List preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { @@ -168,8 +168,8 @@ private void addChunkEvents(List chunkEvents, Parse[] chunks) { } private void addTagEvents(List tagEvents, Parse[] chunks) { - List toks = new ArrayList(); - List preds = new ArrayList(); + List toks = new ArrayList<>(); + List preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkSampleStream.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkSampleStream.java index a8b985c0b..2d8dae257 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkSampleStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkSampleStream.java @@ -57,7 +57,7 @@ private static void getInitialChunks(Parse p, List ichunks) { } public static Parse[] getInitialChunks(Parse p) { - List chunks = new ArrayList(); + List chunks = new ArrayList<>(); getInitialChunks(p, chunks); return chunks.toArray(new Parse[chunks.size()]); } @@ -68,9 +68,9 @@ public ChunkSample read() throws IOException { if (parse != null) { Parse[] chunks = getInitialChunks(parse); - List toks = new ArrayList(); - List tags = new ArrayList(); - List preds = new ArrayList(); + List toks = new ArrayList<>(); + List tags = new ArrayList<>(); + List preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/GapLabeler.java b/opennlp-tools/src/main/java/opennlp/tools/parser/GapLabeler.java index 9597d5298..dbc8c45f8 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/GapLabeler.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/GapLabeler.java @@ -29,5 +29,5 @@ public interface GapLabeler { * Labels the constituents found in the stack with gap labels if appropriate. * @param stack The stack of un-completed constituents. */ - public void labelGaps(Stack stack); + void labelGaps(Stack stack); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/HeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/HeadRules.java index 6993a201d..204bd9a2f 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/HeadRules.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/HeadRules.java @@ -32,12 +32,12 @@ public interface HeadRules { * @param type The type of a constituent which is made up of the specified constituents. * @return The constituent which is the head. */ - public Parse getHead(Parse[] constituents, String type); + Parse getHead(Parse[] constituents, String type); /** * Returns the set of punctuation tags. Attachment decisions for these tags will not be modeled. * * @return the set of punctuation tags. */ - public Set getPunctuationTags(); + Set getPunctuationTags(); } \ No newline at end of file diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java index 9bf12f341..ce3610b50 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.Stack; import java.util.TreeSet; @@ -153,7 +154,7 @@ public Parse(String text, Span span, String type, double p, int index) { this.prob = p; this.head = this; this.headIndex = index; - this.parts = new LinkedList(); + this.parts = new LinkedList<>(); this.label = null; this.parent = null; } @@ -179,7 +180,7 @@ public Parse(String text, Span span, String type, double p, Parse h) { @Override public Object clone() { Parse p = new Parse(this.text, this.span, this.type, this.prob, this.head); - p.parts = new LinkedList(); + p.parts = new LinkedList<>(); p.parts.addAll(this.parts); if (derivation != null) { @@ -843,8 +844,8 @@ public static Parse parseParse(String parse) { public static Parse parseParse(String parse, GapLabeler gl) { StringBuilder text = new StringBuilder(); int offset = 0; - Stack stack = new Stack(); - List cons = new LinkedList(); + Stack stack = new Stack<>(); + List cons = new LinkedList<>(); for (int ci = 0, cl = parse.length(); ci < cl; ci++) { char c = parse.charAt(ci); if (c == '(') { @@ -856,7 +857,7 @@ public static Parse parseParse(String parse, GapLabeler gl) { String token = getToken(rest); stack.push(new Constituent(type, new Span(offset,offset))); if (token != null) { - if (type.equals("-NONE-") && gl != null) { + if (Objects.equals(type, "-NONE-") && gl != null) { //System.err.println("stack.size="+stack.size()); gl.labelGaps(stack); } @@ -950,8 +951,8 @@ public boolean isChunk() { * @return the parse nodes which are children of this node and which are pos tags. */ public Parse[] getTagNodes() { - List tags = new LinkedList(); - List nodes = new LinkedList(); + List tags = new LinkedList<>(); + List nodes = new LinkedList<>(); nodes.addAll(this.parts); while(nodes.size() != 0) { Parse p = nodes.remove(0); @@ -978,7 +979,7 @@ public Parse getCommonParent(Parse node) { if (this == node) { return parent; } - Set parents = new HashSet(); + Set parents = new HashSet<>(); Parse cparent = this; while(cparent != null) { parents.add(cparent); diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/Parser.java b/opennlp-tools/src/main/java/opennlp/tools/parser/Parser.java index 0a7152bcd..64964f22b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/Parser.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/Parser.java @@ -34,13 +34,13 @@ public interface Parser { * @param numParses The number of parses desired. * @return the specified number of parses for the specified tokens. */ - public abstract Parse[] parse(Parse tokens, int numParses); + Parse[] parse(Parse tokens, int numParses); /** * Returns a parse for the specified parse of tokens. * @param tokens The root node of a flat parse containing only tokens. * @return A full parse of the specified tokens or the flat chunks of the tokens if a fullparse could not be found. */ - public abstract Parse parse(Parse tokens); + Parse parse(Parse tokens); } \ No newline at end of file diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerFactory.java index 87e7af8a4..b19d480f8 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerFactory.java @@ -33,7 +33,7 @@ public ChunkerContextGenerator getContextGenerator() { @Override public SequenceValidator getSequenceValidator() { - MaxentModel model = (MaxentModel) artifactProvider.getArtifact("chunker.model"); + MaxentModel model = artifactProvider.getArtifact("chunker.model"); String outcomes[] = new String[model.getNumOutcomes()]; for (int i = 0; i < outcomes.length; i++) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerSequenceValidator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerSequenceValidator.java index b507a4ee8..9cba69735 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerSequenceValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerSequenceValidator.java @@ -29,8 +29,7 @@ public class ParserChunkerSequenceValidator implements SequenceValidator public ParserChunkerSequenceValidator(String outcomes[]) { - continueStartMap = - new HashMap(outcomes.length); + continueStartMap = new HashMap<>(outcomes.length); for (int oi=0, on = outcomes.length; oi samples, int nFolds) throws IOException { - CrossValidationPartitioner partitioner = new CrossValidationPartitioner( - samples, nFolds); + CrossValidationPartitioner partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { - CrossValidationPartitioner.TrainingSampleStream trainingSampleStream = partitioner - .next(); + CrossValidationPartitioner.TrainingSampleStream trainingSampleStream = partitioner.next(); ParserModel model; diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java index 4bddbe569..97dff6c6f 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java @@ -63,14 +63,14 @@ public ParserEvaluator(final Parser aParser, final ParserEvaluationMonitor... mo */ private static Span[] getConstituencySpans(final Parse parse) { - Stack stack = new Stack(); + Stack stack = new Stack<>(); if (parse.getChildCount() > 0) { for (Parse child : parse.getChildren()) { stack.push(child); } } - List consts = new ArrayList(); + List consts = new ArrayList<>(); while (!stack.isEmpty()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java index 84d34daf3..d3802e23e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java @@ -47,8 +47,7 @@ public class ParserModel extends BaseModel { private static class POSModelSerializer implements ArtifactSerializer { - public POSModel create(InputStream in) throws IOException, - InvalidFormatException { + public POSModel create(InputStream in) throws IOException { POSModel posModel = new POSModel(new UncloseableInputStream(in)); // The 1.6.x models write the non-default beam size into the model itself. @@ -73,8 +72,7 @@ public void serialize(POSModel artifact, OutputStream out) private static class ChunkerModelSerializer implements ArtifactSerializer { - public ChunkerModel create(InputStream in) throws IOException, - InvalidFormatException { + public ChunkerModel create(InputStream in) throws IOException { ChunkerModel model = new ChunkerModel(new UncloseableInputStream(in)); @@ -176,15 +174,15 @@ public ParserModel(String languageCode, MaxentModel buildModel, MaxentModel chec chunkerTagger, headRules, type, manifestInfoEntries); } - public ParserModel(InputStream in) throws IOException, InvalidFormatException { + public ParserModel(InputStream in) throws IOException { super(COMPONENT_NAME, in); } - public ParserModel(File modelFile) throws IOException, InvalidFormatException { + public ParserModel(File modelFile) throws IOException { super(COMPONENT_NAME, modelFile); } - public ParserModel(URL modelURL) throws IOException, InvalidFormatException { + public ParserModel(URL modelURL) throws IOException { super(COMPONENT_NAME, modelURL); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/BuildContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/BuildContextGenerator.java index 42d7c0733..bff687df2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/BuildContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/BuildContextGenerator.java @@ -68,7 +68,7 @@ public String[] getContext(Object o) { * @return the context for building constituents at the specified index. */ public String[] getContext(Parse[] constituents, int index) { - List features = new ArrayList(100); + List features = new ArrayList<>(100); int ps = constituents.length; // cons(-2), cons(-1), cons(0), cons(1), cons(2) diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/CheckContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/CheckContextGenerator.java index 6dcaf080c..b8591c896 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/CheckContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/CheckContextGenerator.java @@ -53,7 +53,7 @@ public String[] getContext(Object o) { */ public String[] getContext(Parse[] constituents, String type, int start, int end) { int ps = constituents.length; - List features = new ArrayList(100); + List features = new ArrayList<>(100); //default features.add("default"); diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/Parser.java b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/Parser.java index 062e7f259..ae20e8a07 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/Parser.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/Parser.java @@ -104,8 +104,8 @@ private Parser(MaxentModel buildModel, MaxentModel checkModel, POSTagger tagger, cprobs = new double[checkModel.getNumOutcomes()]; this.buildContextGenerator = new BuildContextGenerator(); this.checkContextGenerator = new CheckContextGenerator(); - startTypeMap = new HashMap(); - contTypeMap = new HashMap(); + startTypeMap = new HashMap<>(); + contTypeMap = new HashMap<>(); for (int boi = 0, bon = buildModel.getNumOutcomes(); boi < bon; boi++) { String outcome = buildModel.getOutcome(boi); if (outcome.startsWith(START)) { @@ -134,15 +134,15 @@ protected void advanceTop(Parse p) { @Override protected Parse[] advanceParses(final Parse p, double probMass) { double q = 1 - probMass; - /** The closest previous node which has been labeled as a start node. */ + /* The closest previous node which has been labeled as a start node. */ Parse lastStartNode = null; - /** The index of the closest previous node which has been labeled as a start node. */ + /* The index of the closest previous node which has been labeled as a start node. */ int lastStartIndex = -1; - /** The type of the closest previous node which has been labeled as a start node. */ + /* The type of the closest previous node which has been labeled as a start node. */ String lastStartType = null; - /** The index of the node which will be labeled in this iteration of advancing the parse. */ + /* The index of the node which will be labeled in this iteration of advancing the parse. */ int advanceNodeIndex; - /** The node which will be labeled in this iteration of advancing the parse. */ + /* The node which will be labeled in this iteration of advancing the parse. */ Parse advanceNode=null; Parse[] originalChildren = p.getChildren(); Parse[] children = collapsePunctuation(originalChildren,punctSet); @@ -164,7 +164,7 @@ else if (startTypeMap.containsKey(advanceNode.getLabel())) { } } int originalAdvanceIndex = mapParseIndex(advanceNodeIndex,children,originalChildren); - List newParsesList = new ArrayList(buildModel.getNumOutcomes()); + List newParsesList = new ArrayList<>(buildModel.getNumOutcomes()); //call build buildModel.eval(buildContextGenerator.getContext(children, advanceNodeIndex), bprobs); double bprobSum = 0; @@ -274,12 +274,12 @@ public static ParserModel train(String languageCode, ObjectStream parseSa parseSamples.reset(); - Map manifestInfoEntries = new HashMap(); + Map manifestInfoEntries = new HashMap<>(); // build System.err.println("Training builder"); ObjectStream bes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.BUILD, mdict); - Map buildReportMap = new HashMap(); + Map buildReportMap = new HashMap<>(); EventTrainer buildTrainer = TrainerFactory.getEventTrainer(mlParams.getSettings("build"), buildReportMap); MaxentModel buildModel = buildTrainer.train(bes); mergeReportIntoManifest(manifestInfoEntries, buildReportMap, "build"); @@ -308,7 +308,7 @@ public static ParserModel train(String languageCode, ObjectStream parseSa // check System.err.println("Training checker"); ObjectStream kes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.CHECK); - Map checkReportMap = new HashMap(); + Map checkReportMap = new HashMap<>(); EventTrainer checkTrainer = TrainerFactory.getEventTrainer( mlParams.getSettings("check"), checkReportMap); MaxentModel checkModel = checkTrainer.train(kes); mergeReportIntoManifest(manifestInfoEntries, checkReportMap, "check"); diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/ParserEventStream.java b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/ParserEventStream.java index 88c4e2428..afaed995a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/ParserEventStream.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/ParserEventStream.java @@ -93,7 +93,7 @@ public static Parse[] reduceChunks(Parse[] chunks, int ci, Parse parent) { if (!type.equals(AbstractBottomUpParser.TOP_NODE)) { reducedChunks = new Parse[chunks.length-(reduceEnd-reduceStart+1)+1]; //total - num_removed + 1 (for new node) //insert nodes before reduction - for (int ri=0,rn=reduceStart;ri { - public opennlp.tools.parser.lang.en.HeadRules create(InputStream in) throws IOException, - InvalidFormatException { + public opennlp.tools.parser.lang.en.HeadRules create(InputStream in) throws IOException { return new opennlp.tools.parser.lang.en.HeadRules(new BufferedReader(new InputStreamReader(in, "UTF-8"))); } @@ -118,7 +115,7 @@ public HeadRules(Reader rulesReader) throws IOException { BufferedReader in = new BufferedReader(rulesReader); readHeadRules(in); - punctSet = new HashSet(); + punctSet = new HashSet<>(); punctSet.add("."); punctSet.add(","); punctSet.add("``"); @@ -197,7 +194,7 @@ else if ((hr = headRules.get(type)) != null) { private void readHeadRules(BufferedReader str) throws IOException { String line; - headRules = new HashMap(30); + headRules = new HashMap<>(30); while ((line = str.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String num = st.nextToken(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java index 946fa5c66..6f5e32ac2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java @@ -33,12 +33,10 @@ import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; - import opennlp.tools.parser.Constituent; import opennlp.tools.parser.GapLabeler; import opennlp.tools.parser.Parse; import opennlp.tools.parser.chunking.Parser; -import opennlp.tools.util.InvalidFormatException; import opennlp.tools.util.model.ArtifactSerializer; import opennlp.tools.util.model.SerializableArtifact; @@ -62,8 +60,7 @@ public class AncoraSpanishHeadRules implements opennlp.tools.parser.HeadRules, G public static class HeadRulesSerializer implements ArtifactSerializer { - public opennlp.tools.parser.lang.es.AncoraSpanishHeadRules create(InputStream in) throws IOException, - InvalidFormatException { + public opennlp.tools.parser.lang.es.AncoraSpanishHeadRules create(InputStream in) throws IOException { return new opennlp.tools.parser.lang.es.AncoraSpanishHeadRules(new BufferedReader(new InputStreamReader(in, "UTF-8"))); } @@ -119,7 +116,7 @@ public AncoraSpanishHeadRules(Reader rulesReader) throws IOException { BufferedReader in = new BufferedReader(rulesReader); readHeadRules(in); - punctSet = new HashSet(); + punctSet = new HashSet<>(); punctSet.add("."); punctSet.add(","); punctSet.add("``"); @@ -199,7 +196,7 @@ else if ((hr = headRules.get(type)) != null) { private void readHeadRules(BufferedReader str) throws IOException { String line; - headRules = new HashMap(60); + headRules = new HashMap<>(60); while ((line = str.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String num = st.nextToken(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java b/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java index 0d82e0b9e..3fdeb4413 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java @@ -35,11 +35,7 @@ public boolean validSequence(int i, String[] inputSequence, return true; } else { String[] tags = tagDictionary.getTags(inputSequence[i]); - if (tags == null) { - return true; - } else { - return Arrays.asList(tags).contains(outcome); - } + return tags == null || Arrays.asList(tags).contains(outcome); } } } diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java index 1e5244449..52df16dcb 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java @@ -36,7 +36,7 @@ public interface MutableTagDictionary extends TagDictionary { * @return the previous tags associated with the word, or null if there was no * mapping for word. */ - public String[] put(String word, String... tags); + String[] put(String word, String... tags); /** * Whether if the dictionary is case sensitive or not @@ -45,6 +45,6 @@ public interface MutableTagDictionary extends TagDictionary { */ // TODO: move to TagDictionary, can't do it now because of backward // compatibility. - public boolean isCaseSensitive(); + boolean isCaseSensitive(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSContextGenerator.java index 6f3e83147..29c90d55b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSContextGenerator.java @@ -25,5 +25,5 @@ * The interface for a context generator for the POS Tagger. */ public interface POSContextGenerator extends BeamSearchContextGenerator { - public String[] getContext(int pos, String[] tokens, String[] prevTags, Object[] ac); + String[] getContext(int pos, String[] tokens, String[] prevTags, Object[] ac); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTagger.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTagger.java index f08191612..bc334ea03 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTagger.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTagger.java @@ -17,8 +17,6 @@ package opennlp.tools.postag; -import java.util.List; - import opennlp.tools.util.Sequence; /** @@ -31,11 +29,11 @@ public interface POSTagger { * @param sentence The sentece of tokens to be tagged. * @return an array of pos tags for each token provided in sentence. */ - public String[] tag(String[] sentence); + String[] tag(String[] sentence); - public String[] tag(String[] sentence, Object[] additionaContext); + String[] tag(String[] sentence, Object[] additionaContext); - public Sequence[] topKSequences(String[] sentence); + Sequence[] topKSequences(String[] sentence); - public Sequence[] topKSequences(String[] sentence, Object[] additionaContext); + Sequence[] topKSequences(String[] sentence, Object[] additionaContext); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java index 27854dcfe..b4e5d12f2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java @@ -90,7 +90,7 @@ public POSTaggerCrossValidator(String languageCode, */ public void evaluate(ObjectStream samples, int nFolds) throws IOException { - CrossValidationPartitioner partitioner = new CrossValidationPartitioner( + CrossValidationPartitioner partitioner = new CrossValidationPartitioner<>( samples, nFolds); while (partitioner.hasNext()) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/TagDictionary.java b/opennlp-tools/src/main/java/opennlp/tools/postag/TagDictionary.java index cdd3db9e6..1e31d8aea 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/TagDictionary.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/TagDictionary.java @@ -31,5 +31,5 @@ public interface TagDictionary { * @return A list of valid tags for the specified word or null if no information * is available for that word. */ - public String[] getTags(String word); + String[] getTags(String word); } 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 968689f97..3e3ab4235 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java @@ -36,7 +36,7 @@ public interface EndOfSentenceScanner { * Returns an array of character which can indicate the end of a sentence. * @return an array of character which can indicate the end of a sentence. */ - public char[] getEndOfSentenceCharacters(); + char[] getEndOfSentenceCharacters(); /** * The receiver scans the specified string for sentence ending characters and @@ -45,7 +45,7 @@ public interface EndOfSentenceScanner { * @param s a String value * @return a List of Integer objects. */ - public List getPositions(String s); + List getPositions(String s); /** * The receiver scans `buf' for sentence ending characters and @@ -54,7 +54,7 @@ public interface EndOfSentenceScanner { * @param buf a StringBuffer value * @return a List of Integer objects. */ - public List getPositions(StringBuffer buf); + List getPositions(StringBuffer buf); /** * The receiver scans `cbuf' for sentence ending characters and @@ -63,5 +63,5 @@ public interface EndOfSentenceScanner { * @param cbuf a char[] value * @return a List of Integer objects. */ - public List getPositions(char[] cbuf); + List getPositions(char[] cbuf); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDContextGenerator.java index 16989eb09..ade9d6a66 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDContextGenerator.java @@ -33,5 +33,5 @@ public interface SDContextGenerator { * @return an array of contextual features for the potential sentence boundary at the * specified position within the specified string buffer. */ - public abstract String[] getContext(CharSequence s, int position); + String[] getContext(CharSequence s, int position); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetector.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetector.java index dc8649baa..01e3d99b2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetector.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetector.java @@ -33,7 +33,7 @@ public interface SentenceDetector { * @return The String[] with the individual sentences as the array * elements. */ - public String[] sentDetect(String s); + String[] sentDetect(String s); /** * Sentence detect a string. @@ -43,5 +43,5 @@ public interface SentenceDetector { * @return The Span[] with the spans (offsets into s) for each * detected sentence as the individuals array elements. */ - public Span[] sentPosDetect(String s); + Span[] sentPosDetect(String s); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/stemmer/PorterStemmer.java b/opennlp-tools/src/main/java/opennlp/tools/stemmer/PorterStemmer.java index 28688df98..e125df76b 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/stemmer/PorterStemmer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/stemmer/PorterStemmer.java @@ -79,7 +79,8 @@ public void add(char ch) { if (b.length == i) { char[] new_b = new char[i+INC]; - for (int c = 0; c < i; c++) new_b[c] = b[c]; { + System.arraycopy(b, 0, new_b, 0, i); + { b = new_b; } } @@ -108,12 +109,12 @@ public void add(char ch) { /* cons(i) is true <=> b[i] is a consonant. */ - private final boolean cons(int i) { + private boolean cons(int i) { switch (b[i]) { case 'a': case 'e': case 'i': case 'o': case 'u': return false; case 'y': - return (i==k0) ? true : !cons(i-1); + return (i == k0) || !cons(i - 1); default: return true; } @@ -130,7 +131,7 @@ private final boolean cons(int i) { .... */ - private final int m() { + private int m() { int n = 0; int i = k0; while(true) { @@ -164,7 +165,7 @@ private final int m() { /* vowelinstem() is true <=> k0,...j contains a vowel */ - private final boolean vowelinstem() { + private boolean vowelinstem() { int i; for (i = k0; i <= j; i++) if (! cons(i)) @@ -174,12 +175,8 @@ private final boolean vowelinstem() { /* doublec(j) is true <=> j,(j-1) contain a double consonant. */ - private final boolean doublec(int j) { - if (j < k0+1) - return false; - if (b[j] != b[j-1]) - return false; - return cons(j); + private boolean doublec(int j) { + return j >= k0 + 1 && b[j] == b[j - 1] && cons(j); } /* cvc(i) is true <=> i-2,i-1,i has the form consonant - vowel - consonant @@ -191,7 +188,7 @@ private final boolean doublec(int j) { */ - private final boolean cvc(int i) { + private boolean cvc(int i) { if (i < k0+2 || !cons(i) || cons(i-1) || !cons(i-2)) return false; else { @@ -201,7 +198,7 @@ private final boolean cvc(int i) { return true; } - private final boolean ends(String s) { + private boolean ends(String s) { int l = s.length(); int o = k-l+1; if (o < k0) @@ -251,7 +248,7 @@ void setto(String s) { */ - private final void step1() { + private void step1() { if (b[k] == 's') { if (ends("sses")) k -= 2; else if (ends("ies")) setto("i"); @@ -278,7 +275,7 @@ else if (m() == 1 && cvc(k)) /* step2() turns terminal y to i when there is another vowel in the stem. */ - private final void step2() { + private void step2() { if (ends("y") && vowelinstem()) { b[k] = 'i'; dirty = true; @@ -289,7 +286,7 @@ private final void step2() { -ation) maps to -ize etc. note that the string before the suffix must give m() > 0. */ - private final void step3() { + private void step3() { if (k == k0) return; /* For Bug 1 */ switch (b[k-1]) { case 'a': @@ -333,7 +330,7 @@ private final void step3() { /* step4() deals with -ic-, -full, -ness etc. similar strategy to step3. */ - private final void step4() { + private void step4() { switch (b[k]) { case 'e': if (ends("icate")) { r("ic"); break; } @@ -355,7 +352,7 @@ private final void step4() { /* step5() takes off -ant, -ence etc., in context vcvc. */ - private final void step5() { + private void step5() { if (k == k0) return; /* for Bug 1 */ switch (b[k-1]) { case 'a': @@ -410,7 +407,7 @@ private final void step5() { /* step6() removes a final -e if m() > 1. */ - private final void step6() { + private void step6() { j = k; if (b[k] == 'e') { int a = m(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/stemmer/Stemmer.java b/opennlp-tools/src/main/java/opennlp/tools/stemmer/Stemmer.java index eab669512..750890eb6 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/stemmer/Stemmer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/stemmer/Stemmer.java @@ -22,5 +22,5 @@ */ public interface Stemmer { - public CharSequence stem(CharSequence word); + CharSequence stem(CharSequence word); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenContextGenerator.java index 863a04fae..b15fd91cb 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenContextGenerator.java @@ -31,5 +31,5 @@ public interface TokenContextGenerator { * @return an array of features for the specified sentence string at the * specified index. */ - public abstract String[] getContext(String sentence, int index); + String[] getContext(String sentence, int index); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java index 0ab4bc3a7..aae4a83be 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java @@ -52,7 +52,7 @@ public interface Tokenizer { * @return The String[] with the individual tokens as the array * elements. */ - public String[] tokenize(String s); + String[] tokenize(String s); /** * Finds the boundaries of atomic parts in a string. @@ -61,5 +61,5 @@ public interface Tokenizer { * @return The Span[] with the spans (offsets into s) for each * token as the individuals array elements. */ - public Span[] tokenizePos(String s); + Span[] tokenizePos(String s); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/BeamSearchContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/util/BeamSearchContextGenerator.java index 5cdc6aba5..4367db68a 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/util/BeamSearchContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/util/BeamSearchContextGenerator.java @@ -29,5 +29,5 @@ public interface BeamSearchContextGenerator { * @param additionalContext Any addition context specific to a class implementing this interface. * @return the context for the specified position in the specified sequence. */ - public String[] getContext(int index, T[] sequence, String[] priorDecisions, Object[] additionalContext); + String[] getContext(int index, T[] sequence, String[] priorDecisions, Object[] additionalContext); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java index 5ca8409b2..a27f333f0 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java +++ b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java @@ -31,47 +31,47 @@ public interface Heap { * Removes the smallest element from the heap and returns it. * @return The smallest element from the heap. */ - public E extract(); + E extract(); /** * Returns the smallest element of the heap. * @return The top element of the heap. */ - public E first(); + E first(); /** * Returns the largest element of the heap. * @return The largest element of the heap. */ - public E last(); + E last(); /** * Adds the specified object to the heap. * @param o The object to add to the heap. */ - public void add(E o); + void add(E o); /** * Returns the size of the heap. * @return The size of the heap. */ - public int size(); + int size(); /** * Returns whether the heap is empty. * @return true if the heap is empty; false otherwise. */ - public boolean isEmpty(); + boolean isEmpty(); /** * Returns an iterator over the elements of the heap. No specific ordering of these * elements is guaranteed. * @return An iterator over the elements of the heap. */ - public Iterator iterator(); + Iterator iterator(); /** * Clears the contents of the heap. */ - public void clear(); + void clear(); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java index 6295c141e..3677fc427 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java +++ b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java @@ -37,7 +37,7 @@ public class TrainingParameters { public static final String CUTOFF_PARAM = "Cutoff"; public static final String THREADS_PARAM = "Threads"; - private Map parameters = new HashMap(); + private Map parameters = new HashMap<>(); public TrainingParameters() { } @@ -79,7 +79,7 @@ public String algorithm() { */ public Map getSettings(String namespace) { - Map trainingParams = new HashMap(); + Map trainingParams = new HashMap<>(); for (Map.Entry entry : parameters.entrySet()) { String key = entry.getKey(); @@ -146,7 +146,7 @@ public void serialize(OutputStream out) throws IOException { properties.store(out, null); } - public static final TrainingParameters defaultParams() { + public static TrainingParameters defaultParams() { TrainingParameters mlParams = new TrainingParameters(); mlParams.put(TrainingParameters.ALGORITHM_PARAM, "MAXENT"); mlParams.put(TrainingParameters.TRAINER_TYPE_PARAM, EventTrainer.EVENT_VALUE); 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 9997a8246..6e84715c3 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 @@ -50,8 +50,6 @@ */ public abstract class BaseModel implements ArtifactProvider, Serializable { - private static int MODEL_BUFFER_SIZE_LIMIT = Integer.MAX_VALUE; - protected static final String MANIFEST_ENTRY = "manifest.properties"; protected static final String FACTORY_NAME = "factory"; @@ -173,15 +171,14 @@ protected BaseModel(String componentName, String languageCode, Map artifactMap = new HashMap(); + Map artifactMap = new HashMap<>(); ZipEntry entry; while((entry = zip.getNextEntry()) != null ) { @@ -355,7 +353,7 @@ protected ArtifactSerializer getArtifactSerializer(String resourceName) { } protected static Map createArtifactSerializers() { - Map serializers = new HashMap(); + Map serializers = new HashMap<>(); GenericModelSerializer.register(serializers); PropertiesSerializer.register(serializers);