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/11/09 09:55:37 UTC

svn commit: r1199658 - in /incubator/opennlp/trunk: opennlp-maxent/samples/sports/ opennlp-maxent/src/main/java/opennlp/maxent/ opennlp-maxent/src/main/java/opennlp/model/ opennlp-tools/src/main/java/opennlp/tools/chunker/ opennlp-tools/src/main/java/o...

Author: joern
Date: Wed Nov  9 08:55:36 2011
New Revision: 1199658

URL: http://svn.apache.org/viewvc?rev=1199658&view=rev
Log:
OPENNLP-363 String performance handling fixes. Thanks to Aliaksandr Autayeu for providing a patch.

Modified:
    incubator/opennlp/trunk/opennlp-maxent/samples/sports/CreateModel.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/ModelTrainer.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Event.java
    incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/FileEventStream.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/PortugueseContractionUtility.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
    incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java

Modified: incubator/opennlp/trunk/opennlp-maxent/samples/sports/CreateModel.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/samples/sports/CreateModel.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/samples/sports/CreateModel.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/samples/sports/CreateModel.java Wed Nov  9 08:55:36 2011
@@ -77,7 +77,7 @@ public class CreateModel {
         }
         ai++;
       }
-      String dataFileName = new String(args[ai]);
+      String dataFileName = args[ai];
       String modelFileName =
         dataFileName.substring(0,dataFileName.lastIndexOf('.'))
         + "Model.txt";

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/ModelTrainer.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/ModelTrainer.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/ModelTrainer.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/maxent/ModelTrainer.java Wed Nov  9 08:55:36 2011
@@ -85,8 +85,8 @@ public class ModelTrainer {
       }
       ai++;
     }
-    String dataFileName = new String(args[ai++]);
-    String modelFileName = new String(args[ai]);
+    String dataFileName = args[ai++];
+    String modelFileName = args[ai];
     try {
       FileReader datafr = new FileReader(new File(dataFileName));
       EventStream es;

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Event.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Event.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Event.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/Event.java Wed Nov  9 08:55:36 2011
@@ -57,13 +57,13 @@ public class Event {
       if (context.length > 0) {
         sb.append(context[0]);
         if (values != null) {
-          sb.append("="+values[0]);
+          sb.append("=").append(values[0]);
         }
       }
       for (int ci=1;ci<context.length;ci++) {
         sb.append(" ").append(context[ci]);
         if (values != null) {
-          sb.append("="+values[ci]);
+          sb.append("=").append(values[ci]);
         }
       }
       sb.append("]");

Modified: incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/FileEventStream.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/FileEventStream.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/FileEventStream.java (original)
+++ incubator/opennlp/trunk/opennlp-maxent/src/main/java/opennlp/model/FileEventStream.java Wed Nov  9 08:55:36 2011
@@ -97,7 +97,7 @@ public class FileEventStream extends  Ab
     sb.append(event.getOutcome());
     String[] context = event.getContext();
     for (int ci=0,cl=context.length;ci<cl;ci++) {
-      sb.append(" "+context[ci]);
+      sb.append(" ").append(context[ci]);
     }
     sb.append(System.getProperty("line.separator"));
     return sb.toString();

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/chunker/ChunkSample.java Wed Nov  9 08:55:36 2011
@@ -162,7 +162,7 @@ public class ChunkSample {
     for (int tokenIndex = 0; tokenIndex < sentence.size(); tokenIndex++) {
       for (int nameIndex = 0; nameIndex < spans.length; nameIndex++) {
         if (spans[nameIndex].getStart() == tokenIndex) {
-          result.append( "[" + spans[nameIndex].getType()).append(" ");
+          result.append("[").append(spans[nameIndex].getType()).append(" ");
         }
 
         if (spans[nameIndex].getEnd() == tokenIndex) {
@@ -170,7 +170,7 @@ public class ChunkSample {
         }
       }
 
-      result.append(sentence.get(tokenIndex) + "_" + tags.get(tokenIndex) + ' ');
+      result.append(sentence.get(tokenIndex)).append("_").append(tags.get(tokenIndex)).append(' ');
     }
 
     if (sentence.size() > 1)
@@ -191,7 +191,7 @@ public class ChunkSample {
 	    StringBuilder chunkString = new StringBuilder();
 	    
 	    for (int ci=0; ci < preds.size(); ci++) {
-	    	chunkString.append(sentence.get(ci) + " " + tags.get(ci) + " " + preds.get(ci) + "\n");
+        chunkString.append(sentence.get(ci)).append(" ").append(tags.get(ci)).append(" ").append(preds.get(ci)).append("\n");
 	    }
 	    return chunkString.toString();
 	  }

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java Wed Nov  9 08:55:36 2011
@@ -407,10 +407,9 @@ public class ADSentenceStream extends
           sb.append("=");
         }
         if (this.getSyntacticTag() != null) {
-          sb.append(this.getSyntacticTag() + "(" + this.getMorphologicalTag()
-              + ") ");
+          sb.append(this.getSyntacticTag()).append("(").append(this.getMorphologicalTag()).append(") ");
         }
-        sb.append(this.word + "\n");
+        sb.append(this.word).append("\n");
         return sb.toString();
       }
 

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/PortugueseContractionUtility.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/PortugueseContractionUtility.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/PortugueseContractionUtility.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/formats/ad/PortugueseContractionUtility.java Wed Nov  9 08:55:36 2011
@@ -165,7 +165,7 @@ public class PortugueseContractionUtilit
       StringBuilder sb = new StringBuilder();
       String[] parts = left.split("_");
       for (int i = 0; i < parts.length - 1; i++) {
-        sb.append(parts[i] + " ");
+        sb.append(parts[i]).append(" ");
       }
       key = parts[parts.length - 1] + "+" + right;
       if (CONTRACTIONS.containsKey(key)) {
@@ -178,10 +178,10 @@ public class PortugueseContractionUtilit
 
         key = left + "+" + parts[0];
         if (CONTRACTIONS.containsKey(key)) {
-          sb.append(CONTRACTIONS.get(key) + " ");
+          sb.append(CONTRACTIONS.get(key)).append(" ");
 
           for (int i = 1; i < parts.length; i++) {
-            sb.append(parts[i] + " ");
+            sb.append(parts[i]).append(" ");
           }
 
           return sb.toString();

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/namefind/NameSample.java Wed Nov  9 08:55:36 2011
@@ -146,7 +146,7 @@ public class NameSample {
         }
       }
 
-      result.append(sentence.get(tokenIndex) + ' ');
+      result.append(sentence.get(tokenIndex)).append(' ');
     }
 
     if (sentence.size() > 1)

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/ChunkContextGenerator.java Wed Nov  9 08:55:36 2011
@@ -69,7 +69,7 @@ public class ChunkContextGenerator imple
     if (x_2 >= 0) {
       t_2=tags[x_2];
       p_2=preds[x_2];
-      w_2=words[x_2].toString();
+      w_2=words[x_2];
     }
     else {
       t_2=EOS;
@@ -81,7 +81,7 @@ public class ChunkContextGenerator imple
     if (x_1 >= 0) {
       t_1=tags[x_1];
       p_1=preds[x_1];
-      w_1=words[x_1].toString();
+      w_1=words[x_1];
     }
     else {
       t_1=EOS;
@@ -91,12 +91,12 @@ public class ChunkContextGenerator imple
 
     // chunkandpostag(0)
     t0=tags[x0];
-    w0=words[x0].toString();
+    w0=words[x0];
 
     // chunkandpostag(1)
     if (x1 < tags.length) {
       t1=tags[x1];
-      w1=words[x1].toString();
+      w1=words[x1];
     }
     else {
       t1=EOS;
@@ -106,7 +106,7 @@ public class ChunkContextGenerator imple
     // chunkandpostag(2)
     if (x2 < tags.length) {
       t2=tags[x2];
-      w2=words[x2].toString();
+      w2=words[x2];
     }
     else {
       t2=EOS;

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/parser/Parse.java Wed Nov  9 08:55:36 2011
@@ -362,7 +362,7 @@ public class Parse implements Cloneable,
     start = span.getStart();
     if (!type.equals(AbstractBottomUpParser.TOK_NODE)) {
       sb.append("(");
-      sb.append(type +" ");
+      sb.append(type).append(" ");
       //System.out.print(label+" ");
       //System.out.print(head+" ");
       //System.out.print(df.format(prob)+" ");

Modified: incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java?rev=1199658&r1=1199657&r2=1199658&view=diff
==============================================================================
--- incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java (original)
+++ incubator/opennlp/trunk/opennlp-tools/src/main/java/opennlp/tools/postag/POSDictionary.java Wed Nov  9 08:55:36 2011
@@ -251,7 +251,7 @@ public class POSDictionary implements It
     StringBuilder dictionaryString = new StringBuilder();
 
     for (String word : dictionary.keySet()) {
-      dictionaryString.append(word + " -> " + tagsToString(getTags(word)));
+      dictionaryString.append(word).append(" -> ").append(tagsToString(getTags(word)));
       dictionaryString.append("\n");
     }