Repository: opennlp Updated Branches: refs/heads/trunk f1cbfeab3 -> 477de7f77
Remove deprecated POSDictionaryWriter class This class isn't used anymore in OpenNLP and was deprecated long enough to be removed. Since 1.5.x the Dictionary is used instead. The CountedSet is only used by this class and is now marked as deprecated to also remove it one day. See issue OPENNLP-878 Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/477de7f7 Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/477de7f7 Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/477de7f7 Branch: refs/heads/trunk Commit: 477de7f777d5ea8ff28654fc5179eb87d2cc1daf Parents: f1cbfea Author: Jörn Kottmann <[email protected]> Authored: Wed Nov 2 22:29:52 2016 +0100 Committer: Jörn Kottmann <[email protected]> Committed: Wed Nov 2 22:29:52 2016 +0100 ---------------------------------------------------------------------- .../tools/postag/POSDictionaryWriter.java | 138 ------------------- .../java/opennlp/tools/util/CountedSet.java | 3 + 2 files changed, 3 insertions(+), 138 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/opennlp/blob/477de7f7/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionaryWriter.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionaryWriter.java b/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionaryWriter.java deleted file mode 100644 index 402bb61..0000000 --- a/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionaryWriter.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package opennlp.tools.postag; - -import java.io.BufferedReader; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import opennlp.tools.util.CountedSet; - -/** - * Class for writing a pos-tag-dictionary to a file. - */ -@Deprecated -public class POSDictionaryWriter { - - private Writer dictFile; - private Map<String, Set<String>> dictionary; - private CountedSet<String> wordCounts; - private String newline = System.getProperty("line.separator"); - - public POSDictionaryWriter(String file, String encoding) throws IOException { - if (encoding != null) { - dictFile = new OutputStreamWriter(new FileOutputStream(file),encoding); - } - else { - dictFile = new FileWriter(file); - } - dictionary = new HashMap<String, Set<String>>(); - wordCounts = new CountedSet<String>(); - } - - public POSDictionaryWriter(String file) throws IOException { - this(file,null); - } - - public void addEntry(String word, String tag) { - Set<String> tags = dictionary.get(word); - if (tags == null) { - tags = new HashSet<String>(); - dictionary.put(word,tags); - } - tags.add(tag); - wordCounts.add(word); - } - - public void write() throws IOException { - write(5); - } - - public void write(int cutoff) throws IOException { - for (Iterator<String> wi = wordCounts.iterator(); wi.hasNext();) { - String word = wi.next(); - if (wordCounts.getCount(word) >= cutoff) { - dictFile.write(word); - Set<String> tags = dictionary.get(word); - for (Iterator<String> ti=tags.iterator();ti.hasNext();) { - dictFile.write(" "); - dictFile.write(ti.next()); - } - dictFile.write(newline); - } - } - dictFile.close(); - } - - private static void usage() { - System.err.println("Usage: POSDictionaryWriter [-encoding encoding] dictionary tag_files"); - System.exit(1); - } - - public static void main(String[] args) throws IOException { - if (args.length == 0) { - usage(); - } - int ai=0; - String encoding = null; - if (args[ai].startsWith("-encoding")) { - if (ai+1 >= args.length) { - usage(); - } - else { - encoding = args[ai+1]; - ai+=2; - } - } - String dictionaryFile = args[ai++]; - POSDictionaryWriter dict = new POSDictionaryWriter(dictionaryFile,encoding); - for (int fi=ai;fi<args.length;fi++) { - BufferedReader in; - if (encoding == null) { - in = new BufferedReader(new FileReader(args[fi])); - } - else { - in = new BufferedReader(new InputStreamReader(new FileInputStream(args[fi]),encoding)); - } - for (String line=in.readLine();line != null; line = in.readLine()) { - if (!line.equals("")) { - String[] parts = line.split("\\s+"); - for (int pi=0;pi<parts.length;pi++) { - int index = parts[pi].lastIndexOf('_'); - String word = parts[pi].substring(0,index); - String tag = parts[pi].substring(index+1); - dict.addEntry(word,tag); - } - } - } - } - dict.write(); - } -} http://git-wip-us.apache.org/repos/asf/opennlp/blob/477de7f7/opennlp-tools/src/main/java/opennlp/tools/util/CountedSet.java ---------------------------------------------------------------------- diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/CountedSet.java b/opennlp-tools/src/main/java/opennlp/tools/util/CountedSet.java index 5b90926..53659b1 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/util/CountedSet.java +++ b/opennlp-tools/src/main/java/opennlp/tools/util/CountedSet.java @@ -32,7 +32,10 @@ import java.util.Set; /** * Set which counts the number of times a values are added to it. * This value can be accessed with the #getCount method. + * + * @deprecated this class is no longer used in OpenNLP and will be removed */ +@Deprecated public class CountedSet<E> implements Set<E> { private Map<E, Integer> cset;
