From 2de31fea26bacff6cd58b9a8f67b3750094a38be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Kottmann?= Date: Sun, 22 Jan 2017 11:30:43 +0100 Subject: [PATCH] OPENNLP-953: Remove deprecated model readers and writers --- .../ml/maxent/io/ObjectGISModelReader.java | 44 -------- .../ml/maxent/io/ObjectGISModelWriter.java | 63 ----------- .../ml/maxent/io/ObjectQNModelReader.java | 35 ------ .../ml/maxent/io/ObjectQNModelWriter.java | 62 ----------- .../ml/maxent/io/OldFormatGISModelReader.java | 86 --------------- .../ml/maxent/io/PlainTextGISModelReader.java | 57 ---------- .../ml/maxent/io/PlainTextGISModelWriter.java | 91 --------------- .../ml/maxent/io/PooledGISModelReader.java | 56 ---------- .../io/SuffixSensitiveGISModelReader.java | 52 --------- .../io/SuffixSensitiveGISModelWriter.java | 101 ----------------- .../tools/ml/model/GenericModelWriter.java | 23 +--- .../PlainTextPerceptronModelReader.java | 55 --------- .../PlainTextPerceptronModelWriter.java | 94 ---------------- .../SuffixSensitivePerceptronModelWriter.java | 104 ------------------ 14 files changed, 1 insertion(+), 922 deletions(-) delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelWriter.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelWriter.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PooledGISModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelWriter.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelReader.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelWriter.java delete mode 100644 opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SuffixSensitivePerceptronModelWriter.java diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelReader.java deleted file mode 100644 index 0f58f7ebd..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelReader.java +++ /dev/null @@ -1,44 +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.ml.maxent.io; - -import java.io.ObjectInputStream; - -import opennlp.tools.ml.model.ObjectDataReader; - -/** - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class ObjectGISModelReader extends GISModelReader { - - protected ObjectInputStream input; - - /** - * Constructor which directly instantiates the ObjectInputStream containing - * the model contents. - * - * @param ois The DataInputStream containing the model information. - */ - - public ObjectGISModelReader(ObjectInputStream ois) { - super(new ObjectDataReader(ois)); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelWriter.java deleted file mode 100644 index 364acc5b3..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectGISModelWriter.java +++ /dev/null @@ -1,63 +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.ml.maxent.io; - -import java.io.IOException; -import java.io.ObjectOutputStream; - -import opennlp.tools.ml.model.AbstractModel; - -/** - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class ObjectGISModelWriter extends GISModelWriter { - - protected ObjectOutputStream output; - - /** - * Constructor which takes a GISModel and a ObjectOutputStream and prepares - * itself to write the model to that stream. - * - * @param model The GISModel which is to be persisted. - * @param dos The stream which will be used to persist the model. - */ - public ObjectGISModelWriter(AbstractModel model, ObjectOutputStream dos) { - super(model); - output = dos; - } - - public void writeUTF(String s) throws IOException { - output.writeUTF(s); - } - - public void writeInt(int i) throws IOException { - output.writeInt(i); - } - - public void writeDouble(double d) throws IOException { - output.writeDouble(d); - } - - public void close() throws IOException { - output.flush(); - output.close(); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelReader.java deleted file mode 100644 index 4f7a283a9..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelReader.java +++ /dev/null @@ -1,35 +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.ml.maxent.io; - -import java.io.ObjectInputStream; - -import opennlp.tools.ml.model.ObjectDataReader; - -/** - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class ObjectQNModelReader extends QNModelReader { - - public ObjectQNModelReader(ObjectInputStream ois) { - super(new ObjectDataReader(ois)); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelWriter.java deleted file mode 100644 index c88450e2d..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/ObjectQNModelWriter.java +++ /dev/null @@ -1,62 +0,0 @@ -package opennlp.tools.ml.maxent.io; - -/* - * 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. - */ -import java.io.IOException; -import java.io.ObjectOutputStream; - -import opennlp.tools.ml.model.AbstractModel; - -/** - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class ObjectQNModelWriter extends QNModelWriter { - - protected ObjectOutputStream output; - - /** - * Constructor which takes a GISModel and a ObjectOutputStream and prepares - * itself to write the model to that stream. - * - * @param model The GISModel which is to be persisted. - * @param dos The stream which will be used to persist the model. - */ - public ObjectQNModelWriter(AbstractModel model, ObjectOutputStream dos) { - super(model); - output = dos; - } - - public void writeUTF(String s) throws IOException { - output.writeUTF(s); - } - - public void writeInt(int i) throws IOException { - output.writeInt(i); - } - - public void writeDouble(double d) throws IOException { - output.writeDouble(d); - } - - public void close() throws IOException { - output.flush(); - output.close(); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java deleted file mode 100644 index 13c29340c..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/OldFormatGISModelReader.java +++ /dev/null @@ -1,86 +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.ml.maxent.io; - -import java.io.DataInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.zip.GZIPInputStream; - -import opennlp.tools.ml.model.Context; - -/** - * A reader for GIS models stored in the format used in v1.0 of Maxent. It - * extends the PlainTextGISModelReader to read in the info and then overrides - * the getParameters method so that it can appropriately read the binary file - * which stores the parameters. - * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class OldFormatGISModelReader extends PlainTextGISModelReader { - private DataInputStream paramsInput; - - /** - * Constructor which takes the name of the model without any suffixes, such as - * ".mei.gz" or ".mep.gz". - */ - public OldFormatGISModelReader(String modelname) throws IOException { - super(new File(modelname + ".mei.gz")); - paramsInput = new DataInputStream(new GZIPInputStream(new FileInputStream( - modelname + ".mep.gz"))); - } - - /** - * Reads the parameters from a file and populates an array of context objects. - * - * @param outcomePatterns - * The outcomes patterns for the model. The first index refers to - * which outcome pattern (a set of outcomes that occurs with a - * context) is being specified. The second index specifies the number - * of contexts which use this pattern at index 0, and the index of - * each outcomes which make up this pattern in indicies 1-n. - * @return An array of context objects. - * @throws java.io.IOException - * when the model file does not match the outcome patterns or can - * not be read. - */ - protected Context[] getParameters(int[][] outcomePatterns) - throws java.io.IOException { - Context[] params = new Context[NUM_PREDS]; - int pid = 0; - for (int i = 0; i < outcomePatterns.length; i++) { - // construct outcome pattern - int[] outcomePattern = new int[outcomePatterns[i].length - 1]; - System.arraycopy(outcomePatterns[i], 1, outcomePattern, 0, outcomePatterns[i].length - 1); - // populate parameters for each context which uses this outcome pattern. - for (int j = 0; j < outcomePatterns[i][0]; j++) { - double[] contextParameters = new double[outcomePatterns[i].length - 1]; - for (int k = 1; k < outcomePatterns[i].length; k++) { - contextParameters[k - 1] = readDouble(); - } - params[pid] = new Context(outcomePattern, contextParameters); - pid++; - } - } - return params; - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelReader.java deleted file mode 100644 index 417028b55..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelReader.java +++ /dev/null @@ -1,57 +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.ml.maxent.io; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; - -import opennlp.tools.ml.model.PlainTextFileDataReader; - -/** - * A reader for GIS models stored in plain text format. - * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class PlainTextGISModelReader extends GISModelReader { - - /** - * Constructor which directly instantiates the BufferedReader containing the - * model contents. - * - * @param br - * The BufferedReader containing the model information. - */ - public PlainTextGISModelReader(BufferedReader br) { - super(new PlainTextFileDataReader(br)); - } - - /** - * Constructor which takes a File and creates a reader for it. Detects whether - * the file is gzipped or not based on whether the suffix contains ".gz". - * - * @param f - * The File in which the model is stored. - */ - public PlainTextGISModelReader(File f) throws IOException { - super(f); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java deleted file mode 100644 index 355858b4d..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PlainTextGISModelWriter.java +++ /dev/null @@ -1,91 +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.ml.maxent.io; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.zip.GZIPOutputStream; - -import opennlp.tools.ml.model.AbstractModel; - -/** - * Model writer that saves models in plain text format. - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class PlainTextGISModelWriter extends GISModelWriter { - private BufferedWriter output; - - /** - * Constructor which takes a GISModel and a File and prepares itself to - * write the model to that file. Detects whether the file is gzipped or not - * based on whether the suffix contains ".gz". - * - * @param model The GISModel which is to be persisted. - * @param f The File in which the model is to be persisted. - */ - public PlainTextGISModelWriter(AbstractModel model, File f) throws IOException { - - super(model); - if (f.getName().endsWith(".gz")) { - output = new BufferedWriter(new OutputStreamWriter( - new GZIPOutputStream(new FileOutputStream(f)))); - } - else { - output = new BufferedWriter(new FileWriter(f)); - } - } - - /** - * Constructor which takes a GISModel and a BufferedWriter and prepares - * itself to write the model to that writer. - * - * @param model The GISModel which is to be persisted. - * @param bw The BufferedWriter which will be used to persist the model. - */ - public PlainTextGISModelWriter(AbstractModel model, BufferedWriter bw) { - super(model); - output = bw; - } - - public void writeUTF(String s) throws java.io.IOException { - output.write(s); - output.newLine(); - } - - public void writeInt(int i) throws java.io.IOException { - output.write(Integer.toString(i)); - output.newLine(); - } - - public void writeDouble(double d) throws java.io.IOException { - output.write(Double.toString(d)); - output.newLine(); - } - - public void close() throws java.io.IOException { - output.flush(); - output.close(); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PooledGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PooledGISModelReader.java deleted file mode 100644 index 84a43073f..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/PooledGISModelReader.java +++ /dev/null @@ -1,56 +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.ml.maxent.io; - -import java.io.File; -import java.io.IOException; - -/** - * This class works exactly like the SuffisSensitiveGISModelReader except that it - * attempts to pool all context strings. This is useful when loading models which - * share many context strings. - * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class PooledGISModelReader extends SuffixSensitiveGISModelReader { - - /** - * A reader for GIS models which inspects the filename and invokes the - * appropriate GISModelReader depending on the filename's suffixes. - * - *

The following assumption are made about suffixes: - *

- * - * @param f - * @throws IOException - */ - public PooledGISModelReader(File f) throws IOException { - super(f); - } - - public String readUTF() throws IOException { - return super.readUTF().intern(); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java deleted file mode 100644 index a56778c2b..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelReader.java +++ /dev/null @@ -1,52 +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.ml.maxent.io; - -import java.io.File; -import java.io.IOException; - -/** - * A reader for GIS models which inspects the filename and invokes the - * appropriate GISModelReader depending on the filename's suffixes. - * - *

The following assumption are made about suffixes: - *

- * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class SuffixSensitiveGISModelReader extends GISModelReader { - protected GISModelReader suffixAppropriateReader; - - /** - * Constructor which takes a File and invokes the GISModelReader appropriate - * for the suffix. - * - * @param f - * The File in which the model is stored. - */ - public SuffixSensitiveGISModelReader(File f) throws IOException { - super(f); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelWriter.java deleted file mode 100644 index 2e5af6880..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/maxent/io/SuffixSensitiveGISModelWriter.java +++ /dev/null @@ -1,101 +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.ml.maxent.io; - -import java.io.BufferedWriter; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.zip.GZIPOutputStream; - -import opennlp.tools.ml.model.AbstractModel; - -/** - * A writer for GIS models which inspects the filename and invokes the - * appropriate GISModelWriter depending on the filename's suffixes. - * - *

The following assumption are made about suffixes: - *

- * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class SuffixSensitiveGISModelWriter extends GISModelWriter { - private final GISModelWriter suffixAppropriateWriter; - - /** - * Constructor which takes a GISModel and a File and invokes the - * GISModelWriter appropriate for the suffix. - * - * @param model The GISModel which is to be persisted. - * @param f The File in which the model is to be stored. - */ - public SuffixSensitiveGISModelWriter(AbstractModel model, File f) throws IOException { - - super(model); - - OutputStream output; - String filename = f.getName(); - - // handle the zipped/not zipped distinction - if (filename.endsWith(".gz")) { - output = new GZIPOutputStream(new FileOutputStream(f)); - filename = filename.substring(0,filename.length() - 3); - } - else { - output = new DataOutputStream(new FileOutputStream(f)); - } - - // handle the different formats - if (filename.endsWith(".bin")) { - suffixAppropriateWriter = - new BinaryGISModelWriter(model, - new DataOutputStream(output)); - } - else { // default is ".txt" - suffixAppropriateWriter = - new PlainTextGISModelWriter(model, - new BufferedWriter(new OutputStreamWriter(output))); - } - } - - public void writeUTF(String s) throws java.io.IOException { - suffixAppropriateWriter.writeUTF(s); - } - - public void writeInt(int i) throws java.io.IOException { - suffixAppropriateWriter.writeInt(i); - } - - public void writeDouble(double d) throws java.io.IOException { - suffixAppropriateWriter.writeDouble(d); - } - - public void close() throws java.io.IOException { - suffixAppropriateWriter.close(); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/model/GenericModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/model/GenericModelWriter.java index 9ab1212cf..f6a0612bb 100644 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/model/GenericModelWriter.java +++ b/opennlp-tools/src/main/java/opennlp/tools/ml/model/GenericModelWriter.java @@ -19,23 +19,18 @@ package opennlp.tools.ml.model; -import java.io.BufferedWriter; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.OutputStreamWriter; import java.util.zip.GZIPOutputStream; import opennlp.tools.ml.maxent.io.BinaryGISModelWriter; import opennlp.tools.ml.maxent.io.BinaryQNModelWriter; -import opennlp.tools.ml.maxent.io.PlainTextGISModelWriter; import opennlp.tools.ml.model.AbstractModel.ModelType; import opennlp.tools.ml.naivebayes.BinaryNaiveBayesModelWriter; -import opennlp.tools.ml.naivebayes.PlainTextNaiveBayesModelWriter; import opennlp.tools.ml.perceptron.BinaryPerceptronModelWriter; -import opennlp.tools.ml.perceptron.PlainTextPerceptronModelWriter; public class GenericModelWriter extends AbstractModelWriter { @@ -52,12 +47,7 @@ public GenericModelWriter(AbstractModel model, File file) throws IOException { os = new FileOutputStream(file); } - // handle the different formats - if (filename.endsWith(".bin")) { - init(model, new DataOutputStream(os)); - } else { // filename ends with ".txt" - init(model, new BufferedWriter(new OutputStreamWriter(os))); - } + init(model, new DataOutputStream(os)); } public GenericModelWriter(AbstractModel model, DataOutputStream dos) { @@ -77,17 +67,6 @@ private void init(AbstractModel model, DataOutputStream dos) { } } - private void init(AbstractModel model, BufferedWriter bw) { - if (model.getModelType() == ModelType.Perceptron) { - delegateWriter = new PlainTextPerceptronModelWriter(model, bw); - } else if (model.getModelType() == ModelType.Maxent) { - delegateWriter = new PlainTextGISModelWriter(model, bw); - } - if (model.getModelType() == ModelType.NaiveBayes) { - delegateWriter = new PlainTextNaiveBayesModelWriter(model, bw); - } - } - @Override public void close() throws IOException { delegateWriter.close(); diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelReader.java b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelReader.java deleted file mode 100644 index 0699c0ce2..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelReader.java +++ /dev/null @@ -1,55 +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.ml.perceptron; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; - -import opennlp.tools.ml.model.PlainTextFileDataReader; - -/* - * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class PlainTextPerceptronModelReader extends PerceptronModelReader { - - /** - * Constructor which directly instantiates the BufferedReader containing - * the model contents. - * - * @param br The BufferedReader containing the model information. - */ - public PlainTextPerceptronModelReader(BufferedReader br) { - super(new PlainTextFileDataReader(br)); - } - - /** - * Constructor which takes a File and creates a reader for it. Detects - * whether the file is gzipped or not based on whether the suffix contains - * ".gz". - * - * @param f The File in which the model is stored. - */ - public PlainTextPerceptronModelReader(File f) throws IOException { - super(f); - } -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelWriter.java deleted file mode 100644 index 55f8e336a..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/PlainTextPerceptronModelWriter.java +++ /dev/null @@ -1,94 +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.ml.perceptron; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.zip.GZIPOutputStream; - -import opennlp.tools.ml.model.AbstractModel; - -/** - * Model writer that saves models in plain text format. - * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class PlainTextPerceptronModelWriter extends PerceptronModelWriter { - private BufferedWriter output; - - /** - * Constructor which takes a PerceptronModel and a File and prepares itself to - * write the model to that file. Detects whether the file is gzipped or not - * based on whether the suffix contains ".gz". - * - * @param model The PerceptronModel which is to be persisted. - * @param f The File in which the model is to be persisted. - */ - public PlainTextPerceptronModelWriter(AbstractModel model, File f) - throws IOException { - - super(model); - if (f.getName().endsWith(".gz")) { - output = new BufferedWriter(new OutputStreamWriter( - new GZIPOutputStream(new FileOutputStream(f)))); - } - else { - output = new BufferedWriter(new FileWriter(f)); - } - } - - /** - * Constructor which takes a PerceptronModel and a BufferedWriter and prepares - * itself to write the model to that writer. - * - * @param model The PerceptronModel which is to be persisted. - * @param bw The BufferedWriter which will be used to persist the model. - */ - public PlainTextPerceptronModelWriter(AbstractModel model, BufferedWriter bw) { - super(model); - output = bw; - } - - public void writeUTF(String s) throws java.io.IOException { - output.write(s); - output.newLine(); - } - - public void writeInt(int i) throws java.io.IOException { - output.write(Integer.toString(i)); - output.newLine(); - } - - public void writeDouble(double d) throws java.io.IOException { - output.write(Double.toString(d)); - output.newLine(); - } - - public void close() throws java.io.IOException { - output.flush(); - output.close(); - } - -} diff --git a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SuffixSensitivePerceptronModelWriter.java b/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SuffixSensitivePerceptronModelWriter.java deleted file mode 100644 index 6e5e4715c..000000000 --- a/opennlp-tools/src/main/java/opennlp/tools/ml/perceptron/SuffixSensitivePerceptronModelWriter.java +++ /dev/null @@ -1,104 +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.ml.perceptron; - -import java.io.BufferedWriter; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.zip.GZIPOutputStream; - -import opennlp.tools.ml.model.AbstractModel; -import opennlp.tools.ml.model.AbstractModelWriter; - -/** - * A writer for GIS models which inspects the filename and invokes the - * appropriate GISModelWriter depending on the filename's suffixes. - * - *

The following assumption are made about suffixes: - *

- * - * @deprecated will be removed after 1.7.1 release. Don't use it. - */ -@Deprecated -public class SuffixSensitivePerceptronModelWriter extends PerceptronModelWriter { - private final AbstractModelWriter suffixAppropriateWriter; - - /** - * Constructor which takes a GISModel and a File and invokes the - * GISModelWriter appropriate for the suffix. - * - * @param model The GISModel which is to be persisted. - * @param f The File in which the model is to be stored. - */ - public SuffixSensitivePerceptronModelWriter(AbstractModel model, File f) - throws IOException { - - super(model); - - OutputStream output; - String filename = f.getName(); - - // handle the zipped/not zipped distinction - if (filename.endsWith(".gz")) { - output = new GZIPOutputStream(new FileOutputStream(f)); - filename = filename.substring(0,filename.length() - 3); - } - else { - output = new DataOutputStream(new FileOutputStream(f)); - } - - // handle the different formats - if (filename.endsWith(".bin")) { - suffixAppropriateWriter = - new BinaryPerceptronModelWriter(model, - new DataOutputStream(output)); - } - else { // default is ".txt" - suffixAppropriateWriter = - new PlainTextPerceptronModelWriter(model, - new BufferedWriter(new OutputStreamWriter(output))); - } - } - - public void writeUTF(String s) throws java.io.IOException { - suffixAppropriateWriter.writeUTF(s); - } - - public void writeInt(int i) throws java.io.IOException { - suffixAppropriateWriter.writeInt(i); - } - - public void writeDouble(double d) throws java.io.IOException { - suffixAppropriateWriter.writeDouble(d); - } - - public void close() throws java.io.IOException { - suffixAppropriateWriter.close(); - } - -}