mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r1144184 - in /mahout/trunk: core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ core/src/main/java/org/apache/mahout/common/ core/src/test/java/org/apache/mahout/common/ examples/src/main/java/org/apache/mahout/cf/taste/e...
Date Fri, 08 Jul 2011 07:40:25 GMT
Author: srowen
Date: Fri Jul  8 07:40:25 2011
New Revision: 1144184

URL: http://svn.apache.org/viewvc?rev=1144184&view=rev
Log:
MAHOUT-696 make PrintWriters flush, avoid PrintWriter where possible

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/RandomSequenceGenerator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ViterbiEvaluator.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/CommandLineUtil.java
    mahout/trunk/core/src/test/java/org/apache/mahout/common/MahoutTestCase.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/TransposeToByUser.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunAdaptiveLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/RandomSequenceGenerator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/RandomSequenceGenerator.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/RandomSequenceGenerator.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/RandomSequenceGenerator.java
Fri Jul  8 07:40:25 2011
@@ -90,7 +90,7 @@ public final class RandomSequenceGenerat
       int[] observations = HmmEvaluator.predict(model, length, System.currentTimeMillis());
 
       //writing output
-      PrintWriter writer = new PrintWriter(new FileOutputStream(output));
+      PrintWriter writer = new PrintWriter(new FileOutputStream(output), true);
       try {
         for (int observation : observations) {
           writer.print(observation);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ViterbiEvaluator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ViterbiEvaluator.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ViterbiEvaluator.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/classifier/sequencelearning/hmm/ViterbiEvaluator.java
Fri Jul  8 07:40:25 2011
@@ -113,7 +113,7 @@ public final class ViterbiEvaluator {
       int[] hiddenStates = HmmEvaluator.decode(model, observationsArray, true);
 
       //writing output
-      PrintWriter writer = new PrintWriter(new FileOutputStream(output));
+      PrintWriter writer = new PrintWriter(new FileOutputStream(output), true);
       try {
         for (int hiddenState : hiddenStates) {
           writer.print(hiddenState);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/CommandLineUtil.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/CommandLineUtil.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/CommandLineUtil.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/CommandLineUtil.java Fri Jul
 8 07:40:25 2011
@@ -51,7 +51,7 @@ public final class CommandLineUtil {
     fmt.printHelp("<command> [Generic Options] [Job-Specific Options]", 
         "Generic Options:", ops, "");
     
-    PrintWriter pw = new PrintWriter(System.out);
+    PrintWriter pw = new PrintWriter(System.out, true);
     HelpFormatter formatter = new HelpFormatter();
     formatter.setGroup(group);
     formatter.setPrintWriter(pw);
@@ -69,7 +69,7 @@ public final class CommandLineUtil {
     fmt.printHelp("<command> [Generic Options] [Job-Specific Options]",
         "Generic Options:", ops, "");
 
-    PrintWriter pw = new PrintWriter(System.out);
+    PrintWriter pw = new PrintWriter(System.out, true);
     HelpFormatter formatter = new HelpFormatter();
     formatter.setGroup(group);
     formatter.setPrintWriter(pw);

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/common/MahoutTestCase.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/common/MahoutTestCase.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/common/MahoutTestCase.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/common/MahoutTestCase.java Fri Jul 
8 07:40:25 2011
@@ -18,11 +18,10 @@
 package org.apache.mahout.common;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
 import java.lang.reflect.Field;
 
 import com.google.common.base.Charsets;
@@ -129,11 +128,12 @@ public abstract class MahoutTestCase ext
     return AbstractJob.keyFor(optionName);
   }
 
-  protected static void writeLines(File file, String... lines) throws FileNotFoundException
{
-    PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file),
Charsets.UTF_8));
+  protected static void writeLines(File file, String... lines) throws IOException {
+    Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
     try {
       for (String line : lines) {
-        writer.println(line);
+        writer.write(line);
+        writer.write('\n');
       }
     } finally {
       Closeables.closeQuietly(writer);

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingDataModel.java
Fri Jul  8 07:40:25 2011
@@ -22,7 +22,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
 import java.util.regex.Pattern;
 
 import com.google.common.base.Charsets;
@@ -59,9 +59,9 @@ public final class BookCrossingDataModel
     }
     File resultFile = new File(new File(System.getProperty("java.io.tmpdir")), "taste.bookcrossing.txt");
     resultFile.delete();
-    PrintWriter writer = null;
+    Writer writer = null;
     try {
-      writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(resultFile), Charsets.UTF_8));
+      writer = new OutputStreamWriter(new FileOutputStream(resultFile), Charsets.UTF_8);
       for (String line : new FileLineIterable(originalFile, true)) {
         // 0 ratings are basically "no rating", ignore them (thanks h.9000)
         if (line.endsWith("\"0\"")) {
@@ -78,7 +78,8 @@ public final class BookCrossingDataModel
           // drop rating
           convertedLine = convertedLine.substring(0, convertedLine.lastIndexOf(','));
         }
-        writer.println(convertedLine);
+        writer.write(convertedLine);
+        writer.write('\n');
       }
       writer.flush();
     } catch (IOException ioe) {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/grouplens/GroupLensDataModel.java
Fri Jul  8 07:40:25 2011
@@ -22,7 +22,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
 import java.net.URL;
 import java.util.regex.Pattern;
 
@@ -57,9 +57,9 @@ public final class GroupLensDataModel ex
     if (resultFile.exists()) {
       resultFile.delete();
     }
-    PrintWriter writer = null;
+    Writer writer = null;
     try {
-      writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(resultFile), Charsets.UTF_8));
+      writer = new OutputStreamWriter(new FileOutputStream(resultFile), Charsets.UTF_8);
       for (String line : new FileLineIterable(originalFile, false)) {
         int lastDelimiterStart = line.lastIndexOf(COLON_DELIMTER);
         if (lastDelimiterStart < 0) {
@@ -67,7 +67,8 @@ public final class GroupLensDataModel ex
         }
         String subLine = line.substring(0, lastDelimiterStart);
         String convertedLine = COLON_DELIMITER_PATTERN.matcher(subLine).replaceAll(",");
-        writer.println(convertedLine);
+        writer.write(convertedLine);
+        writer.write('\n');
       }
     } catch (IOException ioe) {
       resultFile.delete();

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/TransposeToByUser.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/TransposeToByUser.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/TransposeToByUser.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/netflix/TransposeToByUser.java
Fri Jul  8 07:40:25 2011
@@ -21,7 +21,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -101,14 +101,14 @@ public final class TransposeToByUser {
   }
   
   private static void appendStringsToFile(Iterable<String> strings, File file) throws
IOException {
-    PrintWriter outputStreamWriter =
-      new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), Charsets.UTF_8));
+    Writer out = new OutputStreamWriter(new FileOutputStream(file, true), Charsets.UTF_8);
     try {
       for (String s : strings) {
-        outputStreamWriter.println(s);
+        out.write(s);
+        out.write('\n');
       }
     } finally {
-      Closeables.closeQuietly(outputStreamWriter);
+      Closeables.closeQuietly(out);
     }
   }
   

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunAdaptiveLogistic.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunAdaptiveLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunAdaptiveLogistic.java
Fri Jul  8 07:40:25 2011
@@ -51,7 +51,7 @@ public final class RunAdaptiveLogistic {
   }
 
   public static void main(String[] args) throws IOException {
-    mainToOutput(args, new PrintWriter(System.out));
+    mainToOutput(args, new PrintWriter(System.out, true));
   }
 
   static void mainToOutput(String[] args, PrintWriter output) throws IOException {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
Fri Jul  8 07:40:25 2011
@@ -48,7 +48,7 @@ public final class RunLogistic {
   }
 
   public static void main(String[] args) throws IOException {
-    mainToOutput(args, new PrintWriter(System.out));
+    mainToOutput(args, new PrintWriter(System.out, true));
   }
 
   static void mainToOutput(String[] args, PrintWriter output) throws IOException {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
Fri Jul  8 07:40:25 2011
@@ -60,7 +60,7 @@ public final class TrainAdaptiveLogistic
   }
 
   public static void main(String[] args) throws IOException {
-    mainToOutput(args, new PrintWriter(System.out));
+    mainToOutput(args, new PrintWriter(System.out, true));
   }
 
   static void mainToOutput(String[] args, PrintWriter output) throws IOException {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
Fri Jul  8 07:40:25 2011
@@ -61,7 +61,7 @@ public final class TrainLogistic {
   }
 
   public static void main(String[] args) throws IOException {
-    mainToOutput(args, new PrintWriter(System.out));
+    mainToOutput(args, new PrintWriter(System.out, true));
   }
 
   static void mainToOutput(String[] args, PrintWriter output) throws IOException {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
(original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
Fri Jul  8 07:40:25 2011
@@ -57,7 +57,7 @@ public final class ValidateAdaptiveLogis
   }
 
   public static void main(String[] args) throws IOException {
-    mainToOutput(args, new PrintWriter(System.out));
+    mainToOutput(args, new PrintWriter(System.out, true));
   }
 
   static void mainToOutput(String[] args, PrintWriter output) throws IOException {

Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
(original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
Fri Jul  8 07:40:25 2011
@@ -44,7 +44,7 @@ public class TrainLogisticTest extends M
     String outputFile = getTestTempFile("model").getAbsolutePath();
 
     StringWriter sw = new StringWriter();
-    PrintWriter pw = new PrintWriter(sw);
+    PrintWriter pw = new PrintWriter(sw, true);
     TrainLogistic.mainToOutput(new String[]{
         "--input", "donut.csv",
         "--output", outputFile,
@@ -87,7 +87,7 @@ public class TrainLogisticTest extends M
     }
 
     sw = new StringWriter();
-    pw = new PrintWriter(sw);
+    pw = new PrintWriter(sw, true);
     RunLogistic.mainToOutput(new String[]{
         "--input", "donut.csv",
         "--model", outputFile,
@@ -104,7 +104,7 @@ public class TrainLogisticTest extends M
     String outputFile = getTestTempFile("model").getAbsolutePath();
 
     StringWriter sw = new StringWriter();
-    PrintWriter pw = new PrintWriter(sw);
+    PrintWriter pw = new PrintWriter(sw, true);
     TrainLogistic.mainToOutput(new String[]{
         "--input", "donut.csv",
         "--output", outputFile,
@@ -123,7 +123,7 @@ public class TrainLogisticTest extends M
     assertTrue(trainOut.contains("c -25."));
 
     sw = new StringWriter();
-    pw = new PrintWriter(sw);
+    pw = new PrintWriter(sw, true);
     RunLogistic.mainToOutput(new String[]{
         "--input", "donut.csv",
         "--model", outputFile,
@@ -134,7 +134,7 @@ public class TrainLogisticTest extends M
     assertTrue(trainOut.contains("AUC = 1.00"));
 
     sw = new StringWriter();
-    pw = new PrintWriter(sw);
+    pw = new PrintWriter(sw, true);
     RunLogistic.mainToOutput(new String[]{
         "--input", "donut-test.csv",
         "--model", outputFile,

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java?rev=1144184&r1=1144183&r2=1144184&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
(original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/clustering/lda/LDAPrintTopics.java
Fri Jul  8 07:40:25 2011
@@ -43,7 +43,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
+import java.io.Writer;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -158,17 +158,18 @@ public final class LDAPrintTopics {
     throws IOException {
     for (int i = 0; i < topWords.size(); ++i) {
       Collection<Pair<String,Double>> topK = topWords.get(i);
-      PrintWriter out = null;
+      Writer out = null;
       boolean printingToSystemOut = false;
       try {
         if (outputDir != null) {
-          out = new PrintWriter(new OutputStreamWriter(
-              new FileOutputStream(new File(outputDir, "topic_" + i)), Charsets.UTF_8));
+          out = new OutputStreamWriter(new FileOutputStream(new File(outputDir, "topic_"
+ i)), Charsets.UTF_8);
         } else {
-          out = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8));
+          out = new OutputStreamWriter(System.out, Charsets.UTF_8);
           printingToSystemOut = true;
-          out.println("Topic " + i);
-          out.println("===========");
+          out.write("Topic " + i);
+          out.write('\n');
+          out.write("===========");
+          out.write('\n');
         }
         List<Pair<String,Double>> topKasList = Lists.newArrayListWithCapacity(topK.size());
         for(Pair<String,Double> wordWithScore : topK) {
@@ -181,8 +182,9 @@ public final class LDAPrintTopics {
           }
         });
         for(Pair<String,Double> wordWithScore : topKasList) {
-          out.println(wordWithScore.getFirst() + " [p(" + wordWithScore.getFirst() + "|topic_"
+ i +") = "
+          out.write(wordWithScore.getFirst() + " [p(" + wordWithScore.getFirst() + "|topic_"
+ i +") = "
            + wordWithScore.getSecond());
+          out.write('\n');
         }
       } finally {
         if (!printingToSystemOut) {



Mime
View raw message