mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r1146882 - /mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
Date Thu, 14 Jul 2011 20:16:25 GMT
Author: gsingers
Date: Thu Jul 14 20:16:25 2011
New Revision: 1146882

URL: http://svn.apache.org/viewvc?rev=1146882&view=rev
Log:
MAHOUT-761: forgot the add

Added:
    mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
  (with props)

Added: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java?rev=1146882&view=auto
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
(added)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
Thu Jul 14 20:16:25 2011
@@ -0,0 +1,97 @@
+package org.apache.mahout.clustering;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+import org.apache.hadoop.io.Text;
+import org.apache.mahout.math.Vector;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ *
+ **/
+public class WeightedPropertyVectorWritable extends WeightedVectorWritable {
+
+  protected Map<Text, Text> properties;
+
+  public WeightedPropertyVectorWritable() {
+  }
+
+  public WeightedPropertyVectorWritable(Map<Text, Text> properties) {
+    this.properties = properties;
+  }
+
+  public WeightedPropertyVectorWritable(double weight, Vector vector, Map<Text, Text>
properties) {
+    super(weight, vector);
+    this.properties = properties;
+  }
+
+  public Map<Text, Text> getProperties() {
+    return properties;
+  }
+
+  public void setProperties(Map<Text, Text> properties) {
+    this.properties = properties;
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    super.readFields(in);
+    int size = in.readInt();
+    if (size > 0) {
+      properties = new HashMap<Text, Text>();
+      for (int i = 0; i < size; i++) {
+        Text key = new Text(in.readUTF());
+        Text val = new Text(in.readUTF());
+        properties.put(key, val);
+      }
+    }
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    super.write(out);
+    out.writeInt(properties != null ? properties.size() : 0);
+    if (properties != null) {
+      for (Map.Entry<Text, Text> entry : properties.entrySet()) {
+        out.writeUTF(entry.getKey().toString());
+        out.writeUTF(entry.getValue().toString());
+      }
+    }
+  }
+
+  public String toString() {
+    Vector vector = getVector();
+    StringBuilder bldr = new StringBuilder("wt: ").append(weight);
+    if (properties != null && properties.isEmpty() == false) {
+      for (Map.Entry<Text, Text> entry : properties.entrySet()) {
+        bldr.append(entry.getKey().toString()).append(": ").append(entry.getValue().toString()).append('
');
+      }
+    }
+    bldr.append(" vec: ").append((vector == null ? "null" : AbstractCluster.formatVector(vector,
null)));
+    return bldr.toString();
+  }
+
+
+}
+

Propchange: mahout/trunk/core/src/main/java/org/apache/mahout/clustering/WeightedPropertyVectorWritable.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message