mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jeast...@apache.org
Subject svn commit: r1348491 - /mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java
Date Sat, 09 Jun 2012 19:54:34 GMT
Author: jeastman
Date: Sat Jun  9 19:54:34 2012
New Revision: 1348491

URL: http://svn.apache.org/viewvc?rev=1348491&view=rev
Log:
MAHOUT-1030: adding null check when empty properties are written

Modified:
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java?rev=1348491&r1=1348490&r2=1348491&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java
(original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumperWriter.java
Sat Jun  9 19:54:34 2012
@@ -35,23 +35,19 @@ import java.util.Map;
  * Implements a {@link ClusterWriter} that outputs in the format used by ClusterDumper in
Mahout 0.5
  */
 public class ClusterDumperWriter extends AbstractClusterWriter {
-
+  
   private final int subString;
   private final String[] dictionary;
   private final int numTopFeatures;
-
-  public ClusterDumperWriter(Writer writer,
-                             Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints,
-                             DistanceMeasure measure,
-                             int numTopFeatures,
-                             String[] dictionary,
-                             int subString) {
+  
+  public ClusterDumperWriter(Writer writer, Map<Integer,List<WeightedVectorWritable>>
clusterIdToPoints,
+      DistanceMeasure measure, int numTopFeatures, String[] dictionary, int subString) {
     super(writer, clusterIdToPoints, measure);
     this.numTopFeatures = numTopFeatures;
     this.dictionary = dictionary;
     this.subString = subString;
   }
-
+  
   @Override
   public void write(ClusterWritable clusterWritable) throws IOException {
     Cluster cluster = clusterWritable.getValue();
@@ -63,37 +59,39 @@ public class ClusterDumperWriter extends
     } else {
       writer.write(fmtStr);
     }
-
+    
     writer.write('\n');
-
+    
     if (dictionary != null) {
       String topTerms = getTopFeatures(clusterWritable.getValue().getCenter(), dictionary,
numTopFeatures);
       writer.write("\tTop Terms: ");
       writer.write(topTerms);
       writer.write('\n');
     }
-
-    Map<Integer, List<WeightedVectorWritable>> clusterIdToPoints = getClusterIdToPoints();
+    
+    Map<Integer,List<WeightedVectorWritable>> clusterIdToPoints = getClusterIdToPoints();
     List<WeightedVectorWritable> points = clusterIdToPoints.get(clusterWritable.getValue().getId());
     if (points != null) {
       writer.write("\tWeight : [props - optional]:  Point:\n\t");
-      for (Iterator<WeightedVectorWritable> iterator = points.iterator(); iterator.hasNext();
) {
+      for (Iterator<WeightedVectorWritable> iterator = points.iterator(); iterator.hasNext();)
{
         WeightedVectorWritable point = iterator.next();
         writer.write(String.valueOf(point.getWeight()));
         if (point instanceof WeightedPropertyVectorWritable) {
           WeightedPropertyVectorWritable tmp = (WeightedPropertyVectorWritable) point;
-          Map<Text, Text> map = tmp.getProperties();
+          Map<Text,Text> map = tmp.getProperties();
+          // map can be null since empty maps when written are returned as null
+          if (map == null) break;
           writer.write(" : [");
-          for (Map.Entry<Text, Text> entry : map.entrySet()) {
+          for (Map.Entry<Text,Text> entry : map.entrySet()) {
             writer.write(entry.getKey().toString());
             writer.write("=");
             writer.write(entry.getValue().toString());
           }
           writer.write("]");
         }
-
+        
         writer.write(": ");
-
+        
         writer.write(AbstractCluster.formatVector(point.getVector(), dictionary));
         if (iterator.hasNext()) {
           writer.write("\n\t");



Mime
View raw message