Example usage for org.apache.mahout.cf.taste.hadoop.item VectorOrPrefWritable getUserID

List of usage examples for org.apache.mahout.cf.taste.hadoop.item VectorOrPrefWritable getUserID

Introduction

In this page you can find the example usage for org.apache.mahout.cf.taste.hadoop.item VectorOrPrefWritable getUserID.

Prototype

public long getUserID() 

Source Link

Usage

From source file:com.skp.experiment.common.mapreduce.ToVectorAndPrefReducer.java

License:Apache License

@Override
protected void reduce(IntWritable key, Iterable<VectorOrPrefWritable> values, Context context)
        throws IOException, InterruptedException {

    List<Long> userIDs = Lists.newArrayList();
    List<Float> prefValues = Lists.newArrayList();
    Vector similarityMatrixColumn = null;
    for (VectorOrPrefWritable value : values) {
        if (value.getVector() == null) {
            // Then this is going into list
            userIDs.add(value.getUserID());
            prefValues.add(value.getValue());
        } else {//from w  w w  .  j  a  v a2s. c  o m
            // Then this is going into vector
            if (similarityMatrixColumn != null) {
                throw new IllegalStateException(" " + key.get());
            }
            similarityMatrixColumn = value.getVector();
        }
    }

    if (similarityMatrixColumn == null) {
        return;
    }

    VectorAndPrefsWritable vectorAndPrefs = new VectorAndPrefsWritable(similarityMatrixColumn, userIDs,
            prefValues);
    context.write(key, vectorAndPrefs);
}