Skip to content

Commit

Permalink
OPENNLP-1511 Remove methods and constructors long-time deprecated via…
Browse files Browse the repository at this point in the history
… JavaDoc
  • Loading branch information
mawiesne authored and rzo1 committed Aug 28, 2023
1 parent 7f86a14 commit 9dc0131
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,6 @@ public static boolean create(InputStream in, EntryInserter inserter)
return profileContentHandler.mIsCaseSensitiveDictionary;
}

/**
* Serializes the given entries to the given {@link OutputStream}.
* <p>
* <b>Note:</b>
* 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<Entry> entries)
throws IOException {
DictionaryEntryPersistor.serialize(out, entries, true);
}

/**
* Serializes the given entries to the given {@link OutputStream}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package opennlp.tools.languagemodel;

import opennlp.tools.util.StringList;

/**
* A language model can calculate the probability <i>p</i> (between 0 and 1) of a
* certain {@link opennlp.tools.util.StringList sequence of tokens}, given its underlying vocabulary.
Expand All @@ -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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Integer> sentencePosTokenMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> features = new ArrayList<>(19);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,20 +98,6 @@ public boolean equals(Object obj) {
private Map<String, HeadRule> headRules;
private final Set<String> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public POSTaggerFactory(byte[] featureGeneratorBytes, final Map<String, Object>
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);

Expand All @@ -94,8 +93,8 @@ public POSTaggerFactory(byte[] featureGeneratorBytes, final Map<String, Object>
}

// 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;
Expand Down Expand Up @@ -316,10 +315,12 @@ public SequenceValidator<String> getSequenceValidator() {
// use the SerializableArtifact interface
public static class POSDictionarySerializer implements ArtifactSerializer<POSDictionary> {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package opennlp.tools.sentdetect;

import java.io.IOException;
Expand Down Expand Up @@ -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<SentenceSample> 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<SentenceSample> samples, SentenceDetectorFactory sdFactory,
TrainingParameters mlParams) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/


package opennlp.tools.sentdetect;

import java.io.File;
Expand All @@ -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";

Expand All @@ -51,43 +50,6 @@ public SentenceModel(String languageCode, MaxentModel sentModel,
checkArtifactMap();
}

/**
* TODO: was added in 1.5.3 -&gt; 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<String, String> manifestInfoEntries) {
this(languageCode, sentModel, manifestInfoEntries,
new SentenceDetectorFactory(languageCode, useTokenEnd, abbreviations,
eosCharacters));
}

/**
* TODO: was added in 1.5.3 -&gt; 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<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9dc0131

Please sign in to comment.