You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/05/31 13:21:06 UTC
svn commit: r1129627 -
/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
Author: joern
Date: Tue May 31 11:21:06 2011
New Revision: 1129627
URL: http://svn.apache.org/viewvc?rev=1129627&view=rev
Log:
OPENNLP-144 It is now possible to provide custom sequence validation
Modified:
incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java?rev=1129627&r1=1129626&r2=1129627&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSTaggerME.java Tue May 31 11:21:06 2011
@@ -47,8 +47,14 @@ import opennlp.tools.util.model.ModelTyp
*/
public class POSTaggerME implements POSTagger {
- private class PosSequenceValidator implements SequenceValidator<String> {
-
+ private static class PosSequenceValidator implements SequenceValidator<String> {
+
+ private POSDictionary tagDictionary;
+
+ PosSequenceValidator(POSDictionary tagDictionary) {
+ this.tagDictionary = tagDictionary;
+ }
+
public boolean validSequence(int i, String[] inputSequence,
String[] outcomesSequence, String outcome) {
if (tagDictionary == null) {
@@ -103,16 +109,14 @@ public class POSTaggerME implements POST
*/
protected BeamSearch<String> beam;
- /**
- * Initializes the current instance with the provided model
- * and the default beam size of 3.
- *
- * @param model
- */
- public POSTaggerME(POSModel model) {
- this(model, DEFAULT_BEAM_SIZE, 0);
+ public POSTaggerME(POSModel model, int beamSize, int cacheSize, SequenceValidator<String> sequenceValidator) {
+ posModel = model.getPosModel();
+ contextGen = new DefaultPOSContextGenerator(beamSize, model.getNgramDictionary());
+ tagDictionary = model.getTagDictionary();
+ size = beamSize;
+ beam = new BeamSearch<String>(size, contextGen, posModel, sequenceValidator, cacheSize);
}
-
+
/**
* Initializes the current instance with the provided
* model and provided beam size.
@@ -121,11 +125,17 @@ public class POSTaggerME implements POST
* @param beamSize
*/
public POSTaggerME(POSModel model, int beamSize, int cacheSize) {
- posModel = model.getPosModel();
- contextGen = new DefaultPOSContextGenerator(beamSize, model.getNgramDictionary());
- tagDictionary = model.getTagDictionary();
- size = beamSize;
- beam = new BeamSearch<String>(size, contextGen, posModel, new PosSequenceValidator(), cacheSize);
+ this(model, beamSize, cacheSize, new PosSequenceValidator(model.getTagDictionary()));
+ }
+
+ /**
+ * Initializes the current instance with the provided model
+ * and the default beam size of 3.
+ *
+ * @param model
+ */
+ public POSTaggerME(POSModel model) {
+ this(model, DEFAULT_BEAM_SIZE, 0);
}
/**