Example usage for org.apache.mahout.math VarIntWritable get

List of usage examples for org.apache.mahout.math VarIntWritable get

Introduction

In this page you can find the example usage for org.apache.mahout.math VarIntWritable get.

Prototype

public int get() 

Source Link

Usage

From source file:org.gpfvic.mahout.cf.taste.hadoop.item.ToVectorAndPrefReducer.java

License:Apache License

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

    List<Long> userIDs = new ArrayList<>();
    List<Float> prefValues = new ArrayList<>();
    Vector similarityMatrixColumn = null;
    for (VectorOrPrefWritable value : values) {
        if (value.getVector() == null) {
            // Then this is a user-pref value
            userIDs.add(value.getUserID());
            prefValues.add(value.getValue());
        } else {/*from   ww w  .j a v a 2s  . c  om*/
            // Then this is the column vector
            if (similarityMatrixColumn != null) {
                throw new IllegalStateException(
                        "Found two similarity-matrix columns for item index " + key.get());
            }
            similarityMatrixColumn = value.getVector();
        }
    }

    if (similarityMatrixColumn == null) {
        return;
    }

    vectorAndPrefs.set(similarityMatrixColumn, userIDs, prefValues);
    context.write(key, vectorAndPrefs);
}