You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by co...@apache.org on 2012/02/15 15:29:29 UTC

svn commit: r1244499 - in /incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools: cmdline/sentdetect/ sentdetect/ sentdetect/lang/

Author: colen
Date: Wed Feb 15 14:29:29 2012
New Revision: 1244499

URL: http://svn.apache.org/viewvc?rev=1244499&view=rev
Log:
OPENNLP-428: Just applied our format to the code changed by revision #1242761

Modified:
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTrainerTool.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorCrossValidatorTool.java Wed Feb 15 14:29:29 2012
@@ -59,14 +59,15 @@ public final class SentenceDetectorCross
     if (params.getMisclassified()) {
       errorListener = new SentenceEvaluationErrorListener();
     }
-    
+
     char[] eos = null;
-    if (params.getEosChars()!=null)
-    	eos = params.getEosChars().toCharArray();
-    
+    if (params.getEosChars() != null)
+      eos = params.getEosChars().toCharArray();
+
     try {
       Dictionary abbreviations = SentenceDetectorTrainerTool.loadDict(params.getAbbDict());
-      validator = new SDCrossValidator(factory.getLang(), mlParams, abbreviations, eos, errorListener);
+      validator = new SDCrossValidator(factory.getLang(), mlParams,
+          abbreviations, eos, errorListener);
       
       validator.evaluate(sampleStream, params.getFolds());
     }

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTrainerTool.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTrainerTool.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTrainerTool.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/cmdline/sentdetect/SentenceDetectorTrainerTool.java Wed Feb 15 14:29:29 2012
@@ -74,16 +74,16 @@ public final class SentenceDetectorTrain
     File modelOutFile = params.getModel();
     CmdLineUtil.checkOutputFile("sentence detector model", modelOutFile);
 
-     
     char[] eos = null;
-    if (params.getEosChars()!=null)
-    	eos = params.getEosChars().toCharArray();
-    
+    if (params.getEosChars() != null)
+      eos = params.getEosChars().toCharArray();
+
     SentenceModel model;
-    
+
     try {
       Dictionary dict = loadDict(params.getAbbDict());
-      model = SentenceDetectorME.train(factory.getLang(), sampleStream, true, dict, eos,mlParams);
+      model = SentenceDetectorME.train(factory.getLang(), sampleStream, true,
+          dict, eos, mlParams);
     } catch (IOException e) {
       throw new TerminateToolException(-1, "IO error while reading training data or indexing data: " + e.getMessage());
     }

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SDCrossValidator.java Wed Feb 15 14:29:29 2012
@@ -42,7 +42,7 @@ public class SDCrossValidator {
   private SentenceDetectorEvaluationMonitor[] listeners;
   
   private char[] eosCharacters;
-  
+
   public SDCrossValidator(String languageCode, TrainingParameters params,
       Dictionary abbreviations, char[] eosCharacters, SentenceDetectorEvaluationMonitor... listeners) {
     this.languageCode = languageCode;
@@ -61,7 +61,7 @@ public class SDCrossValidator {
   }
   
   public SDCrossValidator(String languageCode, TrainingParameters params) {
-    this(languageCode, params, (Dictionary)null,null);
+    this(languageCode, params, (Dictionary) null, null);
   }
   
   /**
@@ -70,7 +70,8 @@ public class SDCrossValidator {
    */
   @Deprecated
   public SDCrossValidator(String languageCode, int cutoff, int iterations, Dictionary abbreviations) {
-    this(languageCode, ModelUtil.createTrainingParameters(cutoff, iterations), abbreviations,null);
+    this(languageCode, ModelUtil.createTrainingParameters(cutoff, iterations),
+        abbreviations, null);
   }
   
   public SDCrossValidator(String languageCode, TrainingParameters params,

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java Wed Feb 15 14:29:29 2012
@@ -92,14 +92,16 @@ public class SentenceDetectorME implemen
 
   public SentenceDetectorME(SentenceModel model, Factory factory) {
     this.model = model.getMaxentModel();
-    // if the model has custom EOS characters set, use this to get the context 
+    // if the model has custom EOS characters set, use this to get the context
     // generator and the EOS scanner; otherwise use language-specific defaults
     char[] customEOSCharacters = model.getEosCharacters();
     if (customEOSCharacters == null) {
-      cgen = factory.createSentenceContextGenerator(model.getLanguage(), getAbbreviations(model.getAbbreviations()));
+      cgen = factory.createSentenceContextGenerator(model.getLanguage(),
+          getAbbreviations(model.getAbbreviations()));
       scanner = factory.createEndOfSentenceScanner(model.getLanguage());
     } else {
-      cgen = factory.createSentenceContextGenerator(getAbbreviations(model.getAbbreviations()),customEOSCharacters);
+      cgen = factory.createSentenceContextGenerator(
+          getAbbreviations(model.getAbbreviations()), customEOSCharacters);
       scanner = factory.createEndOfSentenceScanner(customEOSCharacters);
     }
     useTokenEnd = model.useTokenEnd();
@@ -276,13 +278,17 @@ public class SentenceDetectorME implemen
     return true;
   }
   
-  public static SentenceModel train(String languageCode, ObjectStream<SentenceSample> samples,
-	      boolean useTokenEnd, Dictionary abbreviations, TrainingParameters mlParams) throws IOException {
-	  return train(languageCode, samples, useTokenEnd, abbreviations, null, mlParams);
+  public static SentenceModel train(String languageCode,
+      ObjectStream<SentenceSample> samples, boolean useTokenEnd,
+      Dictionary abbreviations, TrainingParameters mlParams) throws IOException {
+    return train(languageCode, samples, useTokenEnd, abbreviations, null,
+        mlParams);
   }
   
-  public static SentenceModel train(String languageCode, ObjectStream<SentenceSample> samples,
-      boolean useTokenEnd, Dictionary abbreviations, char[] eosCharacters, TrainingParameters mlParams) throws IOException {
+  public static SentenceModel train(String languageCode,
+      ObjectStream<SentenceSample> samples, boolean useTokenEnd,
+      Dictionary abbreviations, char[] eosCharacters,
+      TrainingParameters mlParams) throws IOException {
     
     Map<String, String> manifestInfoEntries = new HashMap<String, String>();
     
@@ -290,23 +296,25 @@ public class SentenceDetectorME implemen
     
     // TODO: Fix the EventStream to throw exceptions when training goes wrong
     
-    // if the model has custom EOS characters set, use this to get the context 
+    // if the model has custom EOS characters set, use this to get the context
     // generator and the EOS scanner; otherwise use language-specific defaults
     EventStream eventStream = null;
-    if (eosCharacters!=null) {
+    if (eosCharacters != null) {
       eventStream = new SDEventStream(samples,
-          factory.createSentenceContextGenerator(getAbbreviations(abbreviations),eosCharacters),
-    	  factory.createEndOfSentenceScanner(eosCharacters));  
+          factory.createSentenceContextGenerator(
+              getAbbreviations(abbreviations), eosCharacters),
+          factory.createEndOfSentenceScanner(eosCharacters));
     } else {
       eventStream = new SDEventStream(samples,
-          factory.createSentenceContextGenerator(languageCode, getAbbreviations(abbreviations)),
+          factory.createSentenceContextGenerator(languageCode,
+              getAbbreviations(abbreviations)),
           factory.createEndOfSentenceScanner(languageCode));
     }
-    
+
     AbstractModel sentModel = TrainUtil.train(eventStream, mlParams.getSettings(), manifestInfoEntries);
     
-    return new SentenceModel(languageCode, sentModel,
-        useTokenEnd, abbreviations, eosCharacters, manifestInfoEntries);
+    return new SentenceModel(languageCode, sentModel, useTokenEnd,
+        abbreviations, eosCharacters, manifestInfoEntries);
   }
   
   /**

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/SentenceModel.java Wed Feb 15 14:29:29 2012
@@ -46,11 +46,9 @@ public class SentenceModel extends BaseM
   private static final String MAXENT_MODEL_ENTRY_NAME = "sent.model";
   private static final String ABBREVIATIONS_ENTRY_NAME = "abbreviations.dictionary";
   private static final String EOS_CHARACTERS_PROPERTY = "eosCharacters";
-  
-  private static final String TOKEN_END_PROPERTY = "useTokenEnd";
 
+  private static final String TOKEN_END_PROPERTY = "useTokenEnd";
 
-  
   public SentenceModel(String languageCode, AbstractModel sentModel,
       boolean useTokenEnd, Dictionary abbreviations, char[] eosCharacters, Map<String, String> manifestInfoEntries) {
 
@@ -63,18 +61,18 @@ public class SentenceModel extends BaseM
     // Abbreviations are optional
     if (abbreviations != null)
       artifactMap.put(ABBREVIATIONS_ENTRY_NAME, abbreviations);
-    
+
     // EOS characters are optional
-    if (eosCharacters!=null)
-      setManifestProperty(EOS_CHARACTERS_PROPERTY, eosCharArrayToString(eosCharacters));
+    if (eosCharacters != null)
+      setManifestProperty(EOS_CHARACTERS_PROPERTY,
+          eosCharArrayToString(eosCharacters));
     checkArtifactMap();
   }
 
-
-  
   public SentenceModel(String languageCode, AbstractModel sentModel,
       boolean useTokenEnd, Dictionary abbreviations, char[] eosCharacters) {
-    this (languageCode, sentModel, useTokenEnd, abbreviations, eosCharacters, null);
+    this(languageCode, sentModel, useTokenEnd, abbreviations, eosCharacters,
+        null);
   }
   
   public SentenceModel(InputStream in) throws IOException, InvalidFormatException {
@@ -120,23 +118,23 @@ public class SentenceModel extends BaseM
 
   public char[] getEosCharacters() {
     String prop = getManifestProperty(EOS_CHARACTERS_PROPERTY);
-	if (prop != null)
-	  return eosStringToCharArray(getManifestProperty(EOS_CHARACTERS_PROPERTY));
-	else 
-	  return null;
+    if (prop != null)
+      return eosStringToCharArray(getManifestProperty(EOS_CHARACTERS_PROPERTY));
+    else
+      return null;
   }
-  
+
   private String eosCharArrayToString(char[] eosCharacters) {
-	String eosString = "";
-	for (int i = 0; i < eosCharacters.length; i++) 
-	  eosString += eosCharacters[i];
-	return eosString;
+    String eosString = "";
+    for (int i = 0; i < eosCharacters.length; i++)
+      eosString += eosCharacters[i];
+    return eosString;
   }
-  
+
   private char[] eosStringToCharArray(String eosCharacters) {
-	return eosCharacters.toCharArray();
+    return eosCharacters.toCharArray();
   }
-  
+
   public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
     if (args.length < 3){
       System.err.println("SentenceModel [-abbreviationsDictionary] [-useTokenEnd] languageCode packageName modelName");
@@ -162,7 +160,8 @@ public class SentenceModel extends BaseM
     String modelName = args[ai];
 
     AbstractModel model = new GenericModelReader(new File(modelName)).getModel();
-    SentenceModel packageModel = new SentenceModel(languageCode, model, useTokenEnd, abbreviations,null);
+    SentenceModel packageModel = new SentenceModel(languageCode, model,
+        useTokenEnd, abbreviations, null);
     packageModel.serialize(new FileOutputStream(packageName));
   }
 }

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java?rev=1244499&r1=1244498&r2=1244499&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/sentdetect/lang/Factory.java Wed Feb 15 14:29:29 2012
@@ -43,9 +43,10 @@ public class Factory {
 
     return new DefaultEndOfSentenceScanner(defaultEosCharacters);
   }
-  
-  public EndOfSentenceScanner createEndOfSentenceScanner(char[] customEOSCharacters) {
-	  return new DefaultEndOfSentenceScanner(customEOSCharacters);
+
+  public EndOfSentenceScanner createEndOfSentenceScanner(
+      char[] customEOSCharacters) {
+    return new DefaultEndOfSentenceScanner(customEOSCharacters);
   }
 
   public SDContextGenerator createSentenceContextGenerator(String languageCode, Set<String> abbreviations) {
@@ -58,17 +59,19 @@ public class Factory {
 
     return new DefaultSDContextGenerator(abbreviations, defaultEosCharacters);
   }
-  
-  
-  public SDContextGenerator createSentenceContextGenerator(Set<String> abbreviations,char[] customEOSCharacters) {
-	return new DefaultSDContextGenerator(abbreviations, customEOSCharacters);
+
+  public SDContextGenerator createSentenceContextGenerator(
+      Set<String> abbreviations, char[] customEOSCharacters) {
+    return new DefaultSDContextGenerator(abbreviations, customEOSCharacters);
   }
-  
+
   public SDContextGenerator createSentenceContextGenerator(String languageCode) {
     return createSentenceContextGenerator(languageCode, Collections.<String>emptySet());
   }
-  
-  public SDContextGenerator createSentenceContextGenerator(char[] customEOSCharacters) {
-	 return createSentenceContextGenerator(Collections.<String>emptySet(),customEOSCharacters);
+
+  public SDContextGenerator createSentenceContextGenerator(
+      char[] customEOSCharacters) {
+    return createSentenceContextGenerator(Collections.<String> emptySet(),
+        customEOSCharacters);
   }
 }
\ No newline at end of file