Author: tommaso
Date: Wed Mar  9 09:58:42 2016
New Revision: 1734210

URL: http://svn.apache.org/viewvc?rev=1734210&view=rev
Log:
OPENNLP-659 - added missing javadocs, minor tweaks

Modified:
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatEvaluationMonitor.java
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerEventStream.java
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
    
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/FeatureGenerator.java

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatEvaluationMonitor.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatEvaluationMonitor.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatEvaluationMonitor.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatEvaluationMonitor.java
 Wed Mar  9 09:58:42 2016
@@ -19,6 +19,9 @@ package opennlp.tools.doccat;
 
 import opennlp.tools.util.eval.EvaluationMonitor;
 
+/**
+ * {@link EvaluationMonitor} for doccat.
+ */
 public interface DoccatEvaluationMonitor extends
     EvaluationMonitor<DocumentSample> {
 

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DoccatFactory.java
 Wed Mar  9 09:58:42 2016
@@ -50,8 +50,8 @@ public class DoccatFactory extends BaseT
    * Creates a {@link DoccatFactory}. Use this constructor to programmatically
    * create a factory.
    *
-   * @param tokenizer
-   * @param featureGenerators
+   * @param tokenizer         the tokenizer
+   * @param featureGenerators the feature generators
    */
   public DoccatFactory(Tokenizer tokenizer, FeatureGenerator[] 
featureGenerators) {
     this.init(tokenizer, featureGenerators);
@@ -98,7 +98,7 @@ public class DoccatFactory extends BaseT
   }
 
   public static DoccatFactory create(String subclassName, Tokenizer tokenizer,
-      FeatureGenerator[] featureGenerators) throws InvalidFormatException {
+                                     FeatureGenerator[] featureGenerators) 
throws InvalidFormatException {
     if (subclassName == null) {
       // will create the default factory
       return new DoccatFactory(tokenizer, featureGenerators);
@@ -140,7 +140,7 @@ public class DoccatFactory extends BaseT
       }
       if (featureGenerators == null) { // could not load using artifact 
provider
         // load bag of words as default
-        FeatureGenerator[] bow = { new BagOfWordsFeatureGenerator() };
+        FeatureGenerator[] bow = {new BagOfWordsFeatureGenerator()};
         this.featureGenerators = bow;
       }
     }

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerContextGenerator.java
 Wed Mar  9 09:58:42 2016
@@ -35,9 +35,9 @@ class DocumentCategorizerContextGenerato
 
     Collection<String> context = new LinkedList<String>();
 
-    for (int i = 0; i < mFeatureGenerators.length; i++) {
+    for (FeatureGenerator mFeatureGenerator : mFeatureGenerators) {
       Collection<String> extractedFeatures =
-          mFeatureGenerators[i].extractFeatures(text, extraInformation);
+          mFeatureGenerator.extractFeatures(text, extraInformation);
       context.addAll(extractedFeatures);
     }
 

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerEventStream.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerEventStream.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerEventStream.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerEventStream.java
 Wed Mar  9 09:58:42 2016
@@ -30,11 +30,11 @@ public class DocumentCategorizerEventStr
   private DocumentCategorizerContextGenerator mContextGenerator;
 
   /**
-   * Initializes the current instance.
+   * Initializes the current instance via samples and feature generators.
    *
    * @param data {@link ObjectStream} of {@link DocumentSample}s
    *
-   * @param featureGenerators
+   * @param featureGenerators the feature generators
    */
   public DocumentCategorizerEventStream(ObjectStream<DocumentSample> data, 
FeatureGenerator... featureGenerators) {
     super(data);

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/DocumentCategorizerME.java
 Wed Mar  9 09:58:42 2016
@@ -48,13 +48,12 @@ public class DocumentCategorizerME imple
   private DocumentCategorizerContextGenerator mContextGenerator;
 
   /**
-   * Initializes a the current instance with a doccat model and custom feature
+   * Initializes the current instance with a doccat model and custom feature
    * generation. The feature generation must be identical to the configuration
    * at training time.
    *
-   * @param model
-   * @param featureGenerators
-   *
+   * @param model             the doccat model
+   * @param featureGenerators the feature generators
    * @deprecated train a {@link DoccatModel} with a specific
    * {@link DoccatFactory} to customize the {@link FeatureGenerator}s
    */
@@ -67,12 +66,12 @@ public class DocumentCategorizerME imple
    * Initializes the current instance with a doccat model. Default feature
    * generation is used.
    *
-   * @param model
+   * @param model the doccat model
    */
   public DocumentCategorizerME(DoccatModel model) {
     this.model = model;
     this.mContextGenerator = new DocumentCategorizerContextGenerator(this.model
-            .getFactory().getFeatureGenerators());
+        .getFactory().getFeatureGenerators());
   }
 
   @Override
@@ -84,7 +83,7 @@ public class DocumentCategorizerME imple
   /**
    * Categorizes the given text.
    *
-   * @param text
+   * @param text the text to categorize
    */
   public double[] categorize(String text[]) {
     return this.categorize(text, Collections.<String, Object>emptyMap());
@@ -97,7 +96,7 @@ public class DocumentCategorizerME imple
    */
   @Override
   public double[] categorize(String documentText,
-      Map<String, Object> extraInformation) {
+                             Map<String, Object> extraInformation) {
     Tokenizer tokenizer = model.getFactory().getTokenizer();
     return categorize(tokenizer.tokenize(documentText), extraInformation);
   }
@@ -109,14 +108,15 @@ public class DocumentCategorizerME imple
   public double[] categorize(String documentText) {
     Tokenizer tokenizer = model.getFactory().getTokenizer();
     return categorize(tokenizer.tokenize(documentText),
-        Collections.<String, Object> emptyMap());
+        Collections.<String, Object>emptyMap());
   }
 
-/**
- * Returns a map in which the key is the category name and the value is the 
score
- * @param text the input text to classify
- * @return
- */
+  /**
+   * Returns a map in which the key is the category name and the value is the 
score
+   *
+   * @param text the input text to classify
+   * @return the score map
+   */
   public Map<String, Double> scoreMap(String text) {
     Map<String, Double> probDist = new HashMap<String, Double>();
 
@@ -129,12 +129,14 @@ public class DocumentCategorizerME imple
     return probDist;
 
   }
-/**
- * Returns a map with the score as a key in ascendng order. The value is a Set 
of categories with the score.
- * Many categories can have the same score, hence the Set as value
- * @param text the input text to classify
- * @return
- */
+
+  /**
+   * Returns a map with the score as a key in ascendng order. The value is a 
Set of categories with the score.
+   * Many categories can have the same score, hence the Set as value
+   *
+   * @param text the input text to classify
+   * @return the sorted score map
+   */
   public SortedMap<Double, Set<String>> sortedScoreMap(String text) {
     SortedMap<Double, Set<String>> descendingMap = new TreeMap<Double, 
Set<String>>();
     double[] categorize = categorize(text);
@@ -179,8 +181,8 @@ public class DocumentCategorizerME imple
    * instead.
    */
   public static DoccatModel train(String languageCode, 
ObjectStream<DocumentSample> samples,
-          TrainingParameters mlParams, FeatureGenerator... featureGenerators)
-          throws IOException {
+                                  TrainingParameters mlParams, 
FeatureGenerator... featureGenerators)
+      throws IOException {
 
     if (featureGenerators.length == 0) {
       featureGenerators = new FeatureGenerator[]{defaultFeatureGenerator};
@@ -189,21 +191,21 @@ public class DocumentCategorizerME imple
     Map<String, String> manifestInfoEntries = new HashMap<String, String>();
 
     MaxentModel model = TrainUtil.train(
-            new DocumentCategorizerEventStream(samples, featureGenerators),
-            mlParams.getSettings(), manifestInfoEntries);
+        new DocumentCategorizerEventStream(samples, featureGenerators),
+        mlParams.getSettings(), manifestInfoEntries);
 
     return new DoccatModel(languageCode, model, manifestInfoEntries);
   }
 
   public static DoccatModel train(String languageCode, 
ObjectStream<DocumentSample> samples,
-          TrainingParameters mlParams, DoccatFactory factory)
-          throws IOException {
+                                  TrainingParameters mlParams, DoccatFactory 
factory)
+      throws IOException {
 
     Map<String, String> manifestInfoEntries = new HashMap<String, String>();
 
     MaxentModel model = TrainUtil.train(
-            new DocumentCategorizerEventStream(samples, 
factory.getFeatureGenerators()),
-            mlParams.getSettings(), manifestInfoEntries);
+        new DocumentCategorizerEventStream(samples, 
factory.getFeatureGenerators()),
+        mlParams.getSettings(), manifestInfoEntries);
 
     return new DoccatModel(languageCode, model, manifestInfoEntries, factory);
   }
@@ -211,14 +213,11 @@ public class DocumentCategorizerME imple
   /**
    * Trains a doccat model with default feature generation.
    *
-   * @param languageCode
-   * @param samples
-   *
+   * @param languageCode the language code
+   * @param samples      the samples
    * @return the trained doccat model
-   *
    * @throws IOException
    * @throws ObjectStreamException
-   *
    * @deprecated Use
    * {@link #train(String, ObjectStream, TrainingParameters, DoccatFactory)}
    * instead.

Modified: 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/FeatureGenerator.java
URL: 
http://svn.apache.org/viewvc/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/FeatureGenerator.java?rev=1734210&r1=1734209&r2=1734210&view=diff
==============================================================================
--- 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/FeatureGenerator.java
 (original)
+++ 
opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/doccat/FeatureGenerator.java
 Wed Mar  9 09:58:42 2016
@@ -25,5 +25,13 @@ import java.util.Map;
  * Interface for generating features for document categorization.
  */
 public interface FeatureGenerator {
-  public Collection<String> extractFeatures(String[] text, Map<String, Object> 
extraInformation);
+
+  /**
+   * Extract features from given text fragments
+   *
+   * @param text             the text fragments to extract features from
+   * @param extraInformation optional extra information to be used by the 
feature generator
+   * @return a collection of features
+   */
+  Collection<String> extractFeatures(String[] text, Map<String, Object> 
extraInformation);
 }


Reply via email to