Repository: opennlp Updated Branches: refs/heads/trunk 664d80330 -> afc6b65b7
http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleSequenceStream.java ---------------------------------------------------------------------- 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 e5a9f43..22c8550 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 class NameSampleSequenceStream implements SequenceStream { @SuppressWarnings("unchecked") public Event[] updateContext(Sequence sequence, AbstractModel model) { - Sequence<NameSample> pss = sequence; TokenNameFinder tagger = new NameFinderME(new TokenNameFinderModel("x-unspecified", model, Collections.<String, Object>emptyMap(), null)); - String[] sentence = pss.getSource().getSentence(); + String[] sentence = ((Sequence<NameSample>) sequence).getSource().getSentence(); String[] tags = seqCodec.encode(tagger.find(sentence), sentence.length); Event[] events = new Event[sentence.length]; @@ -103,8 +102,7 @@ public class NameSampleSequenceStream implements SequenceStream { events[i] = new Event(tags[i], context); } - Sequence<NameSample> sequence = new Sequence<NameSample>(events,sample); - return sequence; + return new Sequence<>(events,sample); } else { return null; http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSampleTypeFilter.java ---------------------------------------------------------------------- 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 7dabced..9ae1dc9 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<NameSample, NameSam public NameSampleTypeFilter(String[] types, ObjectStream<NameSample> samples) { super(samples); - this.types = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(types))); + this.types = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(types))); } public NameSampleTypeFilter(Set<String> types, ObjectStream<NameSample> samples) { super(samples); - this.types = Collections.unmodifiableSet(new HashSet<String>(types)); + this.types = Collections.unmodifiableSet(new HashSet<>(types)); } public NameSample read() throws IOException { @@ -52,7 +52,7 @@ public class NameSampleTypeFilter extends FilterObjectStream<NameSample, NameSam if (sample != null) { - List<Span> filteredNames = new ArrayList<Span>(); + List<Span> filteredNames = new ArrayList<>(); for (Span name : sample.getNames()) { if (types.contains(name.getType())) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinderFactory.java ---------------------------------------------------------------------- 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 b72d3a9..261321b 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 class RegexNameFinderFactory { } } - public static interface RegexAble { + public interface RegexAble { - public Map<String, Pattern[]> getRegexMap(); + Map<String, Pattern[]> getRegexMap(); - public String getType(); + String getType(); } public enum DEFAULT_REGEX_NAME_FINDER implements RegexAble { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinder.java ---------------------------------------------------------------------- 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 48451e2..6da6f4e 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(); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderCrossValidator.java ---------------------------------------------------------------------- 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 fa93bce..3d2547b 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 @@ public class TokenNameFinderCrossValidator { public DocumentSample read() throws IOException { - List<NameSample> document = new ArrayList<NameSample>(); + List<NameSample> document = new ArrayList<>(); if (beginSample == null) { // Assume that the clear flag is set @@ -143,7 +143,6 @@ public class TokenNameFinderCrossValidator { private TokenNameFinderEvaluationMonitor[] listeners; private FMeasure fmeasure = new FMeasure(); - private SequenceCodec<String> codec; private TokenNameFinderFactory factory; /** @@ -175,7 +174,6 @@ public class TokenNameFinderCrossValidator { this.params = trainParams; this.listeners = listeners; - this.codec = codec; } public TokenNameFinderCrossValidator(String languageCode, String type, @@ -209,7 +207,7 @@ public class TokenNameFinderCrossValidator { // Note: The name samples need to be grouped on a document basis. - CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<DocumentSample>( + CrossValidationPartitioner<DocumentSample> partitioner = new CrossValidationPartitioner<>( new NameToDocumentSampleStream(samples), nFolds); while (partitioner.hasNext()) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderEvaluator.java ---------------------------------------------------------------------- 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 c2146f0..fb689ab 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.FileInputStream; 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 class TokenNameFinderEvaluator extends Evaluator<NameSample> { } @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 class TokenNameFinderEvaluator extends Evaluator<NameSample> { System.out.println("Recall: " + evaluator.getFMeasure().getRecallScore()); System.out.println("Precision: " + evaluator.getFMeasure().getPrecisionScore()); } - else { - // usage: -encoding code test.file model.file - } } } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/namefind/TokenNameFinderModel.java ---------------------------------------------------------------------- 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 6bae7bc..a4780f5 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 class TokenNameFinderModel extends BaseModel { 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 @@ public class TokenNameFinderModel extends BaseModel { 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!"); + } } } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/ngram/NGramModel.java ---------------------------------------------------------------------- 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 e4b0cbc..0e597e0 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<StringList>{ protected static final String COUNT = "count"; - private Map<StringList, Integer> mNGrams = new HashMap<StringList, Integer>(); + private Map<StringList, Integer> mNGrams = new HashMap<>(); /** * Initializes an empty instance. http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractBottomUpParser.java ---------------------------------------------------------------------- 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 3fabfd2..10c3f0e 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 abstract class AbstractBottomUpParser implements Parser { reportFailedParse = true; this.headRules = headRules; this.punctSet = headRules.getPunctuationTags(); - odh = new ListHeap<Parse>(K); - ndh = new ListHeap<Parse>(K); - completeParses = new ListHeap<Parse>(K); + odh = new ListHeap<>(K); + ndh = new ListHeap<>(K); + completeParses = new ListHeap<>(K); } /** @@ -217,7 +217,7 @@ public abstract class AbstractBottomUpParser implements Parser { * @return An array of parses which is a subset of chunks with punctuation removed. */ public static Parse[] collapsePunctuation(Parse[] chunks, Set<String> punctSet) { - List<Parse> collapsedParses = new ArrayList<Parse>(chunks.length); + List<Parse> collapsedParses = new ArrayList<>(chunks.length); int lastNonPunct = -1; int nextNonPunct; for (int ci=0,cn=chunks.length;ci<cn;ci++) { @@ -274,7 +274,7 @@ public abstract class AbstractBottomUpParser implements Parser { double minComplete = 2; double bestComplete = -100000; //approximating -infinity/0 in ln domain while (odh.size() > 0 && (completeParses.size() < M || (odh.first()).getProb() < minComplete) && derivationStage < maxDerivationLength) { - ndh = new ListHeap<Parse>(K); + ndh = new ListHeap<>(K); int derivationRank = 0; for (Iterator<Parse> pi = odh.iterator(); pi.hasNext() && derivationRank < K; derivationRank++) { // forearch derivation http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/AbstractParserEventStream.java ---------------------------------------------------------------------- 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 9d72bf8..079da7e 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 @@ public abstract class AbstractParserEventStream extends opennlp.tools.util.Abstr @Override protected Iterator<Event> createEvents(Parse sample) { - List<Event> newEvents = new ArrayList<Event>(); + List<Event> newEvents = new ArrayList<>(); Parse.pruneParse(sample); if (fixPossesives) { @@ -96,7 +96,7 @@ public abstract class AbstractParserEventStream extends opennlp.tools.util.Abstr } public static Parse[] getInitialChunks(Parse p) { - List<Parse> chunks = new ArrayList<Parse>(); + List<Parse> chunks = new ArrayList<>(); getInitialChunks(p, chunks); return chunks.toArray(new Parse[chunks.size()]); } @@ -134,9 +134,9 @@ public abstract class AbstractParserEventStream extends opennlp.tools.util.Abstr protected abstract void addParseEvents(List<Event> newEvents, Parse[] chunks); private void addChunkEvents(List<Event> chunkEvents, Parse[] chunks) { - List<String> toks = new ArrayList<String>(); - List<String> tags = new ArrayList<String>(); - List<String> preds = new ArrayList<String>(); + List<String> toks = new ArrayList<>(); + List<String> tags = new ArrayList<>(); + List<String> preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { @@ -168,8 +168,8 @@ public abstract class AbstractParserEventStream extends opennlp.tools.util.Abstr } private void addTagEvents(List<Event> tagEvents, Parse[] chunks) { - List<String> toks = new ArrayList<String>(); - List<String> preds = new ArrayList<String>(); + List<String> toks = new ArrayList<>(); + List<String> preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkSampleStream.java ---------------------------------------------------------------------- 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 a8b985c..2d8dae2 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 @@ public class ChunkSampleStream extends FilterObjectStream<Parse, ChunkSample> { } public static Parse[] getInitialChunks(Parse p) { - List<Parse> chunks = new ArrayList<Parse>(); + List<Parse> chunks = new ArrayList<>(); getInitialChunks(p, chunks); return chunks.toArray(new Parse[chunks.size()]); } @@ -68,9 +68,9 @@ public class ChunkSampleStream extends FilterObjectStream<Parse, ChunkSample> { if (parse != null) { Parse[] chunks = getInitialChunks(parse); - List<String> toks = new ArrayList<String>(); - List<String> tags = new ArrayList<String>(); - List<String> preds = new ArrayList<String>(); + List<String> toks = new ArrayList<>(); + List<String> tags = new ArrayList<>(); + List<String> preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/GapLabeler.java ---------------------------------------------------------------------- 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 9597d52..dbc8c45 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<Constituent> stack); + void labelGaps(Stack<Constituent> stack); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/HeadRules.java ---------------------------------------------------------------------- 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 6993a20..204bd9a 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<String> getPunctuationTags(); + Set<String> getPunctuationTags(); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java ---------------------------------------------------------------------- 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 9bf12f3..ce3610b 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.HashSet; 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 class Parse implements Cloneable, Comparable<Parse> { this.prob = p; this.head = this; this.headIndex = index; - this.parts = new LinkedList<Parse>(); + this.parts = new LinkedList<>(); this.label = null; this.parent = null; } @@ -179,7 +180,7 @@ public class Parse implements Cloneable, Comparable<Parse> { @Override public Object clone() { Parse p = new Parse(this.text, this.span, this.type, this.prob, this.head); - p.parts = new LinkedList<Parse>(); + p.parts = new LinkedList<>(); p.parts.addAll(this.parts); if (derivation != null) { @@ -843,8 +844,8 @@ public class Parse implements Cloneable, Comparable<Parse> { public static Parse parseParse(String parse, GapLabeler gl) { StringBuilder text = new StringBuilder(); int offset = 0; - Stack<Constituent> stack = new Stack<Constituent>(); - List<Constituent> cons = new LinkedList<Constituent>(); + Stack<Constituent> stack = new Stack<>(); + List<Constituent> 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 class Parse implements Cloneable, Comparable<Parse> { 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 class Parse implements Cloneable, Comparable<Parse> { * @return the parse nodes which are children of this node and which are pos tags. */ public Parse[] getTagNodes() { - List<Parse> tags = new LinkedList<Parse>(); - List<Parse> nodes = new LinkedList<Parse>(); + List<Parse> tags = new LinkedList<>(); + List<Parse> nodes = new LinkedList<>(); nodes.addAll(this.parts); while(nodes.size() != 0) { Parse p = nodes.remove(0); @@ -978,7 +979,7 @@ public class Parse implements Cloneable, Comparable<Parse> { if (this == node) { return parent; } - Set<Parse> parents = new HashSet<Parse>(); + Set<Parse> parents = new HashSet<>(); Parse cparent = this; while(cparent != null) { parents.add(cparent); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/Parser.java ---------------------------------------------------------------------- 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 0a7152b..64964f2 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 http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerFactory.java ---------------------------------------------------------------------- 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 87e7af8..b19d480 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 class ParserChunkerFactory extends ChunkerFactory { @Override public SequenceValidator<String> 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++) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserChunkerSequenceValidator.java ---------------------------------------------------------------------- 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 b507a4e..9cba697 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<String> public ParserChunkerSequenceValidator(String outcomes[]) { - continueStartMap = - new HashMap<String, String>(outcomes.length); + continueStartMap = new HashMap<>(outcomes.length); for (int oi=0, on = outcomes.length; oi<on; oi++) { String outcome = outcomes[oi]; if (outcome.startsWith(Parser.CONT)){ http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserCrossValidator.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserCrossValidator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserCrossValidator.java index 938004c..f50f277 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ParserCrossValidator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserCrossValidator.java @@ -48,12 +48,10 @@ public class ParserCrossValidator { public void evaluate(ObjectStream<Parse> samples, int nFolds) throws IOException { - CrossValidationPartitioner<Parse> partitioner = new CrossValidationPartitioner<Parse>( - samples, nFolds); + CrossValidationPartitioner<Parse> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { - CrossValidationPartitioner.TrainingSampleStream<Parse> trainingSampleStream = partitioner - .next(); + CrossValidationPartitioner.TrainingSampleStream<Parse> trainingSampleStream = partitioner.next(); ParserModel model; http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserEvaluator.java ---------------------------------------------------------------------- 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 4bddbe5..97dff6c 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 class ParserEvaluator extends Evaluator<Parse> { */ private static Span[] getConstituencySpans(final Parse parse) { - Stack<Parse> stack = new Stack<Parse>(); + Stack<Parse> stack = new Stack<>(); if (parse.getChildCount() > 0) { for (Parse child : parse.getChildren()) { stack.push(child); } } - List<Span> consts = new ArrayList<Span>(); + List<Span> consts = new ArrayList<>(); while (!stack.isEmpty()) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/ParserModel.java ---------------------------------------------------------------------- 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 84d34da..d3802e2 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<POSModel> { - 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 class ParserModel extends BaseModel { private static class ChunkerModelSerializer implements ArtifactSerializer<ChunkerModel> { - 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 class ParserModel extends BaseModel { 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/BuildContextGenerator.java ---------------------------------------------------------------------- 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 42d7c07..bff687d 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 class BuildContextGenerator extends AbstractContextGenerator { * @return the context for building constituents at the specified index. */ public String[] getContext(Parse[] constituents, int index) { - List<String> features = new ArrayList<String>(100); + List<String> features = new ArrayList<>(100); int ps = constituents.length; // cons(-2), cons(-1), cons(0), cons(1), cons(2) http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/CheckContextGenerator.java ---------------------------------------------------------------------- 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 6dcaf08..b8591c8 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 class CheckContextGenerator extends AbstractContextGenerator { */ public String[] getContext(Parse[] constituents, String type, int start, int end) { int ps = constituents.length; - List<String> features = new ArrayList<String>(100); + List<String> features = new ArrayList<>(100); //default features.add("default"); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/Parser.java ---------------------------------------------------------------------- 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 062e7f2..ae20e8a 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 @@ public class Parser extends AbstractBottomUpParser { cprobs = new double[checkModel.getNumOutcomes()]; this.buildContextGenerator = new BuildContextGenerator(); this.checkContextGenerator = new CheckContextGenerator(); - startTypeMap = new HashMap<String, String>(); - contTypeMap = new HashMap<String, String>(); + 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 @@ public class Parser extends AbstractBottomUpParser { @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 @@ public class Parser extends AbstractBottomUpParser { } } int originalAdvanceIndex = mapParseIndex(advanceNodeIndex,children,originalChildren); - List<Parse> newParsesList = new ArrayList<Parse>(buildModel.getNumOutcomes()); + List<Parse> newParsesList = new ArrayList<>(buildModel.getNumOutcomes()); //call build buildModel.eval(buildContextGenerator.getContext(children, advanceNodeIndex), bprobs); double bprobSum = 0; @@ -274,12 +274,12 @@ public class Parser extends AbstractBottomUpParser { parseSamples.reset(); - Map<String, String> manifestInfoEntries = new HashMap<String, String>(); + Map<String, String> manifestInfoEntries = new HashMap<>(); // build System.err.println("Training builder"); ObjectStream<Event> bes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.BUILD, mdict); - Map<String, String> buildReportMap = new HashMap<String, String>(); + Map<String, String> 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 class Parser extends AbstractBottomUpParser { // check System.err.println("Training checker"); ObjectStream<Event> kes = new ParserEventStream(parseSamples, rules, ParserEventTypeEnum.CHECK); - Map<String, String> checkReportMap = new HashMap<String, String>(); + Map<String, String> checkReportMap = new HashMap<>(); EventTrainer checkTrainer = TrainerFactory.getEventTrainer( mlParams.getSettings("check"), checkReportMap); MaxentModel checkModel = checkTrainer.train(kes); mergeReportIntoManifest(manifestInfoEntries, checkReportMap, "check"); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/chunking/ParserEventStream.java ---------------------------------------------------------------------- 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 88c4e24..afaed99 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 class ParserEventStream extends AbstractParserEventStream { 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<rn;ri++) { + for (int ri = 0; ri< reduceStart; ri++) { reducedChunks[ri]=chunks[ri]; } //insert reduced node @@ -177,24 +177,25 @@ public class ParserEventStream extends AbstractParserEventStream { boolean fun = false; int ai = 0; while (ai < args.length && args[ai].startsWith("-")) { - if (args[ai].equals("-build")) { - etype = ParserEventTypeEnum.BUILD; - } - else if (args[ai].equals("-check")) { - etype = ParserEventTypeEnum.CHECK; - } - else if (args[ai].equals("-chunk")) { - etype = ParserEventTypeEnum.CHUNK; - } - else if (args[ai].equals("-tag")) { - etype = ParserEventTypeEnum.TAG; - } - else if (args[ai].equals("-fun")) { - fun = true; - } - else { - System.err.println("Invalid option " + args[ai]); - System.exit(1); + switch (args[ai]) { + case "-build": + etype = ParserEventTypeEnum.BUILD; + break; + case "-check": + etype = ParserEventTypeEnum.CHECK; + break; + case "-chunk": + etype = ParserEventTypeEnum.CHUNK; + break; + case "-tag": + etype = ParserEventTypeEnum.TAG; + break; + case "-fun": + fun = true; + break; + default: + System.err.println("Invalid option " + args[ai]); + System.exit(1); } ai++; } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java index 8a5a947..86b74cc 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/en/HeadRules.java @@ -34,12 +34,10 @@ import java.util.Map; 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; @@ -50,8 +48,7 @@ public class HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler, Se public static class HeadRulesSerializer implements ArtifactSerializer<opennlp.tools.parser.lang.en.HeadRules> { - 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 class HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler, Se BufferedReader in = new BufferedReader(rulesReader); readHeadRules(in); - punctSet = new HashSet<String>(); + punctSet = new HashSet<>(); punctSet.add("."); punctSet.add(","); punctSet.add("``"); @@ -197,7 +194,7 @@ public class HeadRules implements opennlp.tools.parser.HeadRules, GapLabeler, Se private void readHeadRules(BufferedReader str) throws IOException { String line; - headRules = new HashMap<String, HeadRule>(30); + headRules = new HashMap<>(30); while ((line = str.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String num = st.nextToken(); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/parser/lang/es/AncoraSpanishHeadRules.java ---------------------------------------------------------------------- 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 946fa5c..6f5e32a 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.Map; 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<opennlp.tools.parser.lang.es.AncoraSpanishHeadRules> { - 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 class AncoraSpanishHeadRules implements opennlp.tools.parser.HeadRules, G BufferedReader in = new BufferedReader(rulesReader); readHeadRules(in); - punctSet = new HashSet<String>(); + punctSet = new HashSet<>(); punctSet.add("."); punctSet.add(","); punctSet.add("``"); @@ -199,7 +196,7 @@ public class AncoraSpanishHeadRules implements opennlp.tools.parser.HeadRules, G private void readHeadRules(BufferedReader str) throws IOException { String line; - headRules = new HashMap<String, HeadRule>(60); + headRules = new HashMap<>(60); while ((line = str.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); String num = st.nextToken(); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/DefaultPOSSequenceValidator.java ---------------------------------------------------------------------- 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 0d82e0b..3fdeb44 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 class DefaultPOSSequenceValidator implements SequenceValidator<String> { 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); } } } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/MutableTagDictionary.java ---------------------------------------------------------------------- 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 1e52444..52df16d 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(); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/POSContextGenerator.java ---------------------------------------------------------------------- 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 6f3e831..29c90d5 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 @@ import opennlp.tools.util.BeamSearchContextGenerator; * The interface for a context generator for the POS Tagger. */ public interface POSContextGenerator extends BeamSearchContextGenerator<String> { - public String[] getContext(int pos, String[] tokens, String[] prevTags, Object[] ac); + String[] getContext(int pos, String[] tokens, String[] prevTags, Object[] ac); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTagger.java ---------------------------------------------------------------------- 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 f081916..bc334ea 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerCrossValidator.java ---------------------------------------------------------------------- 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 27854dc..b4e5d12 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 class POSTaggerCrossValidator { */ public void evaluate(ObjectStream<POSSample> samples, int nFolds) throws IOException { - CrossValidationPartitioner<POSSample> partitioner = new CrossValidationPartitioner<POSSample>( + CrossValidationPartitioner<POSSample> partitioner = new CrossValidationPartitioner<>( samples, nFolds); while (partitioner.hasNext()) { http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/postag/TagDictionary.java ---------------------------------------------------------------------- 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 cdd3db9..1e31d8a 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/EndOfSentenceScanner.java index 968689f..3e3ab42 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 <code>String</code> value * @return a <code>List</code> of Integer objects. */ - public List<Integer> getPositions(String s); + List<Integer> getPositions(String s); /** * The receiver scans `buf' for sentence ending characters and @@ -54,7 +54,7 @@ public interface EndOfSentenceScanner { * @param buf a <code>StringBuffer</code> value * @return a <code>List</code> of Integer objects. */ - public List<Integer> getPositions(StringBuffer buf); + List<Integer> getPositions(StringBuffer buf); /** * The receiver scans `cbuf' for sentence ending characters and @@ -63,5 +63,5 @@ public interface EndOfSentenceScanner { * @param cbuf a <code>char[]</code> value * @return a <code>List</code> of Integer objects. */ - public List<Integer> getPositions(char[] cbuf); + List<Integer> getPositions(char[] cbuf); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDContextGenerator.java ---------------------------------------------------------------------- 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 16989eb..ade9d6a 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetector.java ---------------------------------------------------------------------- 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 dc8649b..01e3d99 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/stemmer/PorterStemmer.java ---------------------------------------------------------------------- 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 28688df..e125df7 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 class PorterStemmer implements Stemmer { 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 class PorterStemmer implements Stemmer { /* 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 @@ public class PorterStemmer implements Stemmer { .... */ - private final int m() { + private int m() { int n = 0; int i = k0; while(true) { @@ -164,7 +165,7 @@ public class PorterStemmer implements Stemmer { /* 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 @@ public class PorterStemmer implements Stemmer { /* 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 @@ public class PorterStemmer implements Stemmer { */ - 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 @@ public class PorterStemmer implements Stemmer { 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 @@ public class PorterStemmer implements Stemmer { */ - 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 @@ public class PorterStemmer implements Stemmer { /* 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 @@ public class PorterStemmer implements Stemmer { -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 @@ public class PorterStemmer implements Stemmer { /* 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 @@ public class PorterStemmer implements Stemmer { /* step5() takes off -ant, -ence etc., in context <c>vcvc<v>. */ - private final void step5() { + private void step5() { if (k == k0) return; /* for Bug 1 */ switch (b[k-1]) { case 'a': @@ -410,7 +407,7 @@ public class PorterStemmer implements Stemmer { /* step6() removes a final -e if m() > 1. */ - private final void step6() { + private void step6() { j = k; if (b[k] == 'e') { int a = m(); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/stemmer/Stemmer.java ---------------------------------------------------------------------- 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 eab6695..750890e 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 @@ package opennlp.tools.stemmer; */ public interface Stemmer { - public CharSequence stem(CharSequence word); + CharSequence stem(CharSequence word); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/tokenize/TokenContextGenerator.java ---------------------------------------------------------------------- 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 863a04f..b15fd91 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/tokenize/Tokenizer.java ---------------------------------------------------------------------- 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 0ab4bc3..aae4a83 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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/util/BeamSearchContextGenerator.java ---------------------------------------------------------------------- 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 5cdc6ab..4367db6 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<T> { * @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); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/util/Heap.java ---------------------------------------------------------------------- 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 5ca8409..a27f333 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<E> { * 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<E> iterator(); + Iterator<E> iterator(); /** * Clears the contents of the heap. */ - public void clear(); + void clear(); } http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/util/TrainingParameters.java ---------------------------------------------------------------------- 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 6295c14..3677fc4 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<String, String> parameters = new HashMap<String, String>(); + private Map<String, String> parameters = new HashMap<>(); public TrainingParameters() { } @@ -79,7 +79,7 @@ public class TrainingParameters { */ public Map<String, String> getSettings(String namespace) { - Map<String, String> trainingParams = new HashMap<String, String>(); + Map<String, String> trainingParams = new HashMap<>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { String key = entry.getKey(); @@ -146,7 +146,7 @@ public class TrainingParameters { 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); http://git-wip-us.apache.org/repos/asf/opennlp/blob/afc6b65b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java b/opennlp-tools/src/main/java/opennlp/tools/util/model/BaseModel.java index 9997a82..6e84715 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 @@ import opennlp.tools.util.ext.ExtensionLoader; */ 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 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { * @param in the input stream containing the model * * @throws IOException - * @throws InvalidFormatException */ - protected BaseModel(String componentName, InputStream in) throws IOException, InvalidFormatException { + protected BaseModel(String componentName, InputStream in) throws IOException { this(componentName, true); loadModel(in); } - protected BaseModel(String componentName, File modelFile) throws IOException, InvalidFormatException { + protected BaseModel(String componentName, File modelFile) throws IOException { this(componentName, true); try (InputStream in = new BufferedInputStream(new FileInputStream(modelFile))) { @@ -189,7 +186,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { } } - protected BaseModel(String componentName, URL modelURL) throws IOException, InvalidFormatException { + protected BaseModel(String componentName, URL modelURL) throws IOException { this(componentName, true); try (InputStream in = new BufferedInputStream(modelURL.openStream())) { @@ -197,7 +194,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { } } - private void loadModel(InputStream in) throws IOException, InvalidFormatException { + private void loadModel(InputStream in) throws IOException { if (in == null) { throw new IllegalArgumentException("in must not be null!"); @@ -210,6 +207,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { } // TODO: Discuss this solution, the buffering should + int MODEL_BUFFER_SIZE_LIMIT = Integer.MAX_VALUE; in.mark(MODEL_BUFFER_SIZE_LIMIT); final ZipInputStream zip = new ZipInputStream(in); @@ -290,11 +288,11 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { * Finish loading the artifacts now that it knows all serializers. */ private void finishLoadingArtifacts(InputStream in) - throws InvalidFormatException, IOException { + throws IOException { final ZipInputStream zip = new ZipInputStream(in); - Map<String, Object> artifactMap = new HashMap<String, Object>(); + Map<String, Object> artifactMap = new HashMap<>(); ZipEntry entry; while((entry = zip.getNextEntry()) != null ) { @@ -355,7 +353,7 @@ public abstract class BaseModel implements ArtifactProvider, Serializable { } protected static Map<String, ArtifactSerializer> createArtifactSerializers() { - Map<String, ArtifactSerializer> serializers = new HashMap<String, ArtifactSerializer>(); + Map<String, ArtifactSerializer> serializers = new HashMap<>(); GenericModelSerializer.register(serializers); PropertiesSerializer.register(serializers);
