Author: joern
Date: Fri Mar 6 14:57:37 2015
New Revision: 1664645
URL: http://svn.apache.org/r1664645
Log:
OPENNLP-762 The beam size specified in the params is now written in the model
and used in the POS Tagger
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
URL:
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java?rev=1664645&r1=1664644&r2=1664645&view=diff
==============================================================================
---
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
(original)
+++
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSModel.java
Fri Mar 6 14:57:37 2015
@@ -29,7 +29,6 @@ import opennlp.tools.ml.BeamSearch;
import opennlp.tools.ml.model.AbstractModel;
import opennlp.tools.ml.model.MaxentModel;
import opennlp.tools.ml.model.SequenceClassificationModel;
-import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.util.BaseToolFactory;
import opennlp.tools.util.InvalidFormatException;
import opennlp.tools.util.model.ArtifactSerializer;
@@ -96,6 +95,9 @@ public final class POSModel extends Base
if (posModel == null)
throw new IllegalArgumentException("The maxentPosModel param must not
be null!");
+ Properties manifest = (Properties) artifactMap.get(MANIFEST_ENTRY);
+ manifest.setProperty(BeamSearch.BEAM_SIZE_PARAMETER,
Integer.toString(beamSize));
+
artifactMap.put(POS_MODEL_ENTRY_NAME, posModel);
checkArtifactMap();
}
@@ -155,7 +157,7 @@ public final class POSModel extends Base
if (artifactMap.get(POS_MODEL_ENTRY_NAME) instanceof MaxentModel) {
String beamSizeString =
manifest.getProperty(BeamSearch.BEAM_SIZE_PARAMETER);
- int beamSize = NameFinderME.DEFAULT_BEAM_SIZE;
+ int beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;
if (beamSizeString != null) {
beamSize = Integer.parseInt(beamSizeString);
}
Modified:
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
URL:
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java?rev=1664645&r1=1664644&r2=1664645&view=diff
==============================================================================
---
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
(original)
+++
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
Fri Mar 6 14:57:37 2015
@@ -37,7 +37,6 @@ import opennlp.tools.ml.TrainerFactory.T
import opennlp.tools.ml.model.Event;
import opennlp.tools.ml.model.MaxentModel;
import opennlp.tools.ml.model.SequenceClassificationModel;
-import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.ngram.NGramModel;
import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.Sequence;
@@ -56,6 +55,8 @@ import opennlp.tools.util.model.ModelTyp
*/
public class POSTaggerME implements POSTagger {
+ public static final int DEFAULT_BEAM_SIZE = 3;
+
private POSModel modelPackage;
/**
@@ -76,7 +77,6 @@ public class POSTaggerME implements POST
*/
protected boolean useClosedClassTagsFilter = false;
- public static final int DEFAULT_BEAM_SIZE = 3;
/**
* The size of the beam to be used in determining the best sequence of pos
tags.
@@ -95,7 +95,10 @@ public class POSTaggerME implements POST
*
* @param model
* @param beamSize
+ *
+ * @deprecated the beam size should be specified in the params during
training
*/
+ @Deprecated
public POSTaggerME(POSModel model, int beamSize, int cacheSize) {
POSTaggerFactory factory = model.getFactory();
@@ -124,7 +127,32 @@ public class POSTaggerME implements POST
* @param model
*/
public POSTaggerME(POSModel model) {
- this(model, DEFAULT_BEAM_SIZE, 0);
+ POSTaggerFactory factory = model.getFactory();
+
+ int beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;
+
+ String beamSizeString =
model.getManifestProperty(BeamSearch.BEAM_SIZE_PARAMETER);
+
+ if (beamSizeString != null) {
+ beamSize = Integer.parseInt(beamSizeString);
+ }
+
+ modelPackage = model;
+
+ contextGen = factory.getPOSContextGenerator(beamSize);
+ tagDictionary = factory.getTagDictionary();
+ size = beamSize;
+
+ sequenceValidator = factory.getSequenceValidator();
+
+ if (model.getPosSequenceModel() != null) {
+ this.model = model.getPosSequenceModel();
+ }
+ else {
+ this.model = new opennlp.tools.ml.BeamSearch<String>(beamSize,
+ model.getPosModel(), 0);
+ }
+
}
/**
@@ -274,7 +302,7 @@ public class POSTaggerME implements POST
String beamSizeString =
trainParams.getSettings().get(BeamSearch.BEAM_SIZE_PARAMETER);
- int beamSize = NameFinderME.DEFAULT_BEAM_SIZE;
+ int beamSize = POSTaggerME.DEFAULT_BEAM_SIZE;
if (beamSizeString != null) {
beamSize = Integer.parseInt(beamSizeString);
}
@@ -314,7 +342,7 @@ public class POSTaggerME implements POST
}
if (posModel != null) {
- return new POSModel(languageCode, posModel, manifestInfoEntries,
posFactory);
+ return new POSModel(languageCode, posModel, beamSize,
manifestInfoEntries, posFactory);
}
else {
return new POSModel(languageCode, seqPosModel, manifestInfoEntries,
posFactory);