From 9dc0131b4ed3d28364e7e7525c5b73e979953f6c Mon Sep 17 00:00:00 2001 From: Martin Wiesner Date: Sun, 27 Aug 2023 19:48:36 +0200 Subject: [PATCH] OPENNLP-1511 Remove methods and constructors long-time deprecated via JavaDoc --- .../serializer/DictionaryEntryPersistor.java | 20 ---------- .../tools/languagemodel/LanguageModel.java | 12 ------ .../languagemodel/NGramLanguageModel.java | 25 ------------ .../namefind/DefaultNameContextGenerator.java | 11 ----- .../tools/namefind/RegexNameFinder.java | 21 ---------- .../tools/parser/ChunkContextGenerator.java | 17 -------- .../tools/parser/lang/en/HeadRules.java | 15 ------- .../tools/postag/POSTaggerFactory.java | 7 ++-- .../sentdetect/DefaultSDContextGenerator.java | 16 +------- .../tools/sentdetect/SentenceDetectorME.java | 14 ------- .../tools/sentdetect/SentenceModel.java | 40 +------------------ .../lang/th/SentenceContextGenerator.java | 3 +- .../tools/tokenize/SimpleTokenizer.java | 7 +--- 13 files changed, 9 insertions(+), 199 deletions(-) diff --git a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionaryEntryPersistor.java b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionaryEntryPersistor.java index 854f99ccc..a20891c94 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionaryEntryPersistor.java +++ b/opennlp-tools/src/main/java/opennlp/tools/dictionary/serializer/DictionaryEntryPersistor.java @@ -245,26 +245,6 @@ public static boolean create(InputStream in, EntryInserter inserter) return profileContentHandler.mIsCaseSensitiveDictionary; } - /** - * Serializes the given entries to the given {@link OutputStream}. - *

- * Note: - * After the serialization is finished the provided - * {@link OutputStream} remains open. - * - * @param out The {@link OutputStream} to serialize to. - * @param entries The {@link Entry entries} to serialize. - * - * @throws IOException Thrown if IO errors occurred. - * @throws InvalidFormatException Thrown if parameters were invalid. - * @deprecated Use {@link DictionaryEntryPersistor#serialize(OutputStream, Iterator, boolean)} instead. - */ - @Deprecated - public static void serialize(OutputStream out, Iterator entries) - throws IOException { - DictionaryEntryPersistor.serialize(out, entries, true); - } - /** * Serializes the given entries to the given {@link OutputStream}. *

diff --git a/opennlp-tools/src/main/java/opennlp/tools/languagemodel/LanguageModel.java b/opennlp-tools/src/main/java/opennlp/tools/languagemodel/LanguageModel.java index 2e8a19099..6453f627c 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/languagemodel/LanguageModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/languagemodel/LanguageModel.java @@ -17,8 +17,6 @@ package opennlp.tools.languagemodel; -import opennlp.tools.util.StringList; - /** * A language model can calculate the probability p (between 0 and 1) of a * certain {@link opennlp.tools.util.StringList sequence of tokens}, given its underlying vocabulary. @@ -34,16 +32,6 @@ public interface LanguageModel { */ double calculateProbability(String... tokens); - /** - * Predict the most probable output sequence of tokens, given an input sequence of {@code tokens}. - * - * @param tokens a sequence of tokens. - * @return the most probable subsequent token sequence - * @deprecated use {@link #predictNextTokens(String...)} - */ - @Deprecated - StringList predictNextTokens(StringList tokens); - /** * Predict the most probable output sequence of tokens, given an input sequence of {@code tokens}. * diff --git a/opennlp-tools/src/main/java/opennlp/tools/languagemodel/NGramLanguageModel.java b/opennlp-tools/src/main/java/opennlp/tools/languagemodel/NGramLanguageModel.java index 2b3888aee..02d5e75b1 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/languagemodel/NGramLanguageModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/languagemodel/NGramLanguageModel.java @@ -110,31 +110,6 @@ public double calculateProbability(String... tokens) { return probability; } - @Override - @Deprecated - public StringList predictNextTokens(StringList tokens) { - double maxProb = Double.NEGATIVE_INFINITY; - StringList token = null; - - for (StringList ngram : this) { - String[] sequence = new String[ngram.size() + tokens.size()]; - for (int i = 0; i < tokens.size(); i++) { - sequence[i] = tokens.getToken(i); - } - for (int i = 0; i < ngram.size(); i++) { - sequence[i + tokens.size()] = ngram.getToken(i); - } - StringList sample = new StringList(sequence); - double v = calculateProbability(sample); - if (v > maxProb) { - maxProb = v; - token = ngram; - } - } - - return token; - } - private double calculateProbability(StringList tokens) { double probability = 0d; if (size() > 0) { diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java index 0f4a2d0bf..712d17826 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/DefaultNameContextGenerator.java @@ -46,17 +46,6 @@ public class DefaultNameContextGenerator implements NameContextGenerator { new PreviousMapFeatureGenerator(), new BigramNameFeatureGenerator()); - /** - * Creates a name context generator. - * - * @deprecated use {@link #DefaultNameContextGenerator(AdaptiveFeatureGenerator...)} and - * always provide one or more {@link AdaptiveFeatureGenerator feature generators}. - */ - @Deprecated - public DefaultNameContextGenerator() { - this((AdaptiveFeatureGenerator[]) null); - } - /** * Creates a name context generator with the specified * {@link AdaptiveFeatureGenerator feature generators}. diff --git a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java index 13007aa5c..b8239c28e 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java +++ b/opennlp-tools/src/main/java/opennlp/tools/namefind/RegexNameFinder.java @@ -64,27 +64,6 @@ public RegexNameFinder(Pattern[] patterns, String type) { sType = type; } - - /** - * Initializes a {@link RegexNameFinder} instance. - * - * @param patterns The {@link Pattern[] patterns} to use. - * Must not be {@code null} and not be empty. - * - * @throws IllegalArgumentException Thrown if {@code patterns} were {@code null} or empty. - * @deprecated Use constructor {@link #RegexNameFinder(Pattern[], String)} - * for single types, and/or constructor {@link #RegexNameFinder(Map)} instead. - */ - @Deprecated - public RegexNameFinder(Pattern[] patterns) { - if (patterns == null || patterns.length == 0) { - throw new IllegalArgumentException("patterns must not be null or empty!"); - } - - mPatterns = patterns; - sType = null; - } - @Override public Span[] find(String[] tokens) { Map sentencePosTokenMap = new HashMap<>(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java index 0b1b85059..9766e95a9 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java @@ -52,23 +52,6 @@ public ChunkContextGenerator(int cacheSize) { } } - /** - * @deprecated Use {@link #getContext(int, String[], String[], String[])} instead. - */ - @Deprecated - public String[] getContext(Object o) { - Object[] data = (Object[]) o; - return getContext((Integer) data[0], (String[]) data[1], (String[]) data[2], (String[]) data[3]); - } - - /** - * @deprecated Use {@link #getContext(int, String[], String[], String[])} instead. - */ - @Deprecated - public String[] getContext(int i, String[] words, String[] prevDecisions, Object[] ac) { - return getContext(i,words,(String[]) ac[0],prevDecisions); - } - @Override public String[] getContext(int i, String[] words, String[] tags, String[] preds) { List features = new ArrayList<>(19); 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 eb3c2c915..dd4e8b897 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 @@ -18,7 +18,6 @@ package opennlp.tools.parser.lang.en; import java.io.BufferedReader; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -99,20 +98,6 @@ public boolean equals(Object obj) { private Map headRules; private final Set punctSet; - /** - * Creates a new set of head rules based on the specified {@code ruleFile}. - * - * @param ruleFile A string representation for a head rules file. - * - * @throws IOException Thrown if the head rules file can not be read. - * - * @deprecated Use {@link #HeadRules(Reader)} instead. - */ - @Deprecated - public HeadRules(String ruleFile) throws IOException { - this(new FileReader(ruleFile)); - } - /** * Creates a new set of head rules based on the specified reader. * diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java index c9be30537..94b0aa639 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java +++ b/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerFactory.java @@ -83,9 +83,8 @@ public POSTaggerFactory(byte[] featureGeneratorBytes, final Map this.posDictionary = posDictionary; } - // reduced visibility to ensure deprecation is respected in future versions - @Deprecated + @Deprecated(forRemoval = true) POSTaggerFactory(Dictionary ngramDictionary, TagDictionary posDictionary) { this.init(ngramDictionary, posDictionary); @@ -94,8 +93,8 @@ public POSTaggerFactory(byte[] featureGeneratorBytes, final Map } // reduced visibility to ensure deprecation is respected in future versions - @Deprecated // will be removed when only 8 series models are supported + @Deprecated(forRemoval = true) void init(Dictionary ngramDictionary, TagDictionary posDictionary) { this.ngramDictionary = ngramDictionary; this.posDictionary = posDictionary; @@ -316,10 +315,12 @@ public SequenceValidator getSequenceValidator() { // use the SerializableArtifact interface public static class POSDictionarySerializer implements ArtifactSerializer { + @Override public POSDictionary create(InputStream in) throws IOException { return POSDictionary.create(new UncloseableInputStream(in)); } + @Override public void serialize(POSDictionary artifact, OutputStream out) throws IOException { artifact.serialize(out); diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java index f972d575e..e28d3c9f2 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/DefaultSDContextGenerator.java @@ -159,21 +159,7 @@ public String[] getContext(CharSequence sb, int position) { collectFeats.clear(); return context; } - - /** - * Determines some features for the sentence detector and adds them to list features. - * - * @param prefix String preceding the eos character in the eos token. - * @param suffix String following the eos character in the eos token. - * @param previous Space delimited token preceding token containing eos character. - * @param next Space delimited token following token containing eos character. - * - * @deprecated use {@link #collectFeatures(String, String, String, String, Character)} instead. - */ - protected void collectFeatures(String prefix, String suffix, String previous, String next) { - collectFeatures(prefix, suffix, previous, next, null); - } - + /** * Determines some features for the sentence detector and adds them to list features. * diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java index 93d523c7b..970ecd2e4 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package opennlp.tools.sentdetect; import java.io.IOException; @@ -309,19 +308,6 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate return true; } - /** - * @deprecated Use - * {@link #train(String, ObjectStream, SentenceDetectorFactory, TrainingParameters)} - * and pass in af {@link SentenceDetectorFactory}. - */ - public static SentenceModel train(String languageCode, - ObjectStream samples, boolean useTokenEnd, - Dictionary abbreviations, TrainingParameters mlParams) throws IOException { - SentenceDetectorFactory sdFactory = new SentenceDetectorFactory( - languageCode, useTokenEnd, abbreviations, null); - return train(languageCode, samples, sdFactory, mlParams); - } - public static SentenceModel train(String languageCode, ObjectStream samples, SentenceDetectorFactory sdFactory, TrainingParameters mlParams) throws IOException { diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java index 8caff463d..0f164a9f3 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java @@ -15,7 +15,6 @@ * limitations under the License. */ - package opennlp.tools.sentdetect; import java.io.File; @@ -40,7 +39,7 @@ */ public class SentenceModel extends BaseModel { - private static final long serialVersionUID = -3921848998444722554L; + private static final long serialVersionUID = -8374532795287293730L; private static final String COMPONENT_NAME = "SentenceDetectorME"; private static final String MAXENT_MODEL_ENTRY_NAME = "sent.model"; @@ -51,43 +50,6 @@ public SentenceModel(String languageCode, MaxentModel sentModel, checkArtifactMap(); } - /** - * TODO: was added in 1.5.3 -> remove - * @deprecated Use - * {@link #SentenceModel(String, MaxentModel, Map, SentenceDetectorFactory)} - * instead and pass in a {@link SentenceDetectorFactory} - */ - public SentenceModel(String languageCode, MaxentModel sentModel, boolean useTokenEnd, - Dictionary abbreviations, char[] eosCharacters, Map manifestInfoEntries) { - this(languageCode, sentModel, manifestInfoEntries, - new SentenceDetectorFactory(languageCode, useTokenEnd, abbreviations, - eosCharacters)); - } - - /** - * TODO: was added in 1.5.3 -> remove - * - * @deprecated Use - * {@link #SentenceModel(String, MaxentModel, Map, SentenceDetectorFactory)} - * instead and pass in a {@link SentenceDetectorFactory} - */ - public SentenceModel(String languageCode, MaxentModel sentModel, - boolean useTokenEnd, Dictionary abbreviations, char[] eosCharacters) { - this(languageCode, sentModel, useTokenEnd, abbreviations, eosCharacters, - null); - } - - public SentenceModel(String languageCode, MaxentModel sentModel, - boolean useTokenEnd, Dictionary abbreviations, Map manifestInfoEntries) { - this(languageCode, sentModel, useTokenEnd, abbreviations, null, - manifestInfoEntries); - } - - public SentenceModel(String languageCode, MaxentModel sentModel, - boolean useTokenEnd, Dictionary abbreviations) { - this (languageCode, sentModel, useTokenEnd, abbreviations, null, null); - } - public SentenceModel(InputStream in) throws IOException { super(COMPONENT_NAME, in); } diff --git a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java index f87d6ca30..002b4f4d8 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java +++ b/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/th/SentenceContextGenerator.java @@ -31,7 +31,8 @@ public SentenceContextGenerator() { } @Override - protected void collectFeatures(String prefix, String suffix, String previous, String next) { + protected void collectFeatures(String prefix, String suffix, String previous, String next, + Character eosChar) { buf.append("p="); buf.append(prefix); collectFeats.add(buf.toString()); diff --git a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java index a2f5c14f5..d545f95c7 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java +++ b/opennlp-tools/src/main/java/opennlp/tools/tokenize/SimpleTokenizer.java @@ -56,12 +56,7 @@ public String toString() { */ public static final SimpleTokenizer INSTANCE = new SimpleTokenizer(); - /** - * @deprecated Use {@link SimpleTokenizer#INSTANCE} field instead to obtain an instance. - * This constructor will be made private in the future. - */ - @Deprecated // TODO Decide when this will be private (see deprecation note!) - public SimpleTokenizer() { + private SimpleTokenizer() { } @Override