return file;
}
private Long2ObjectMap<SparseVector> readPredictions(File predFile) throws FileNotFoundException, RecommenderBuildException {
Long2ObjectMap<Long2DoubleMap> data = new Long2ObjectOpenHashMap<Long2DoubleMap>();
Cursor<String[]> cursor = new DelimitedTextCursor(predFile, algorithm.getOutputDelimiter());
try {
int n = 0;
for (String[] row: cursor) {
n++;
if (row.length == 0 || row.length == 1 && row[0].equals("")) {
continue;
}
if (row.length < 3) {
logger.error("predictions line {}: invalid row {}", n,
StringUtils.join(row, ","));
throw new RecommenderBuildException("invalid prediction row");
}
long uid = Long.parseLong(row[0]);
long iid = Long.parseLong(row[1]);
double pred = Double.parseDouble(row[2]);
Long2DoubleMap user = data.get(uid);
if (user == null) {
user = new Long2DoubleOpenHashMap();
data.put(uid, user);
}
user.put(iid, pred);
}
} finally {
cursor.close();
}
Long2ObjectMap<SparseVector> vectors = new Long2ObjectOpenHashMap<SparseVector>(data.size());
for (Long2ObjectMap.Entry<Long2DoubleMap> entry: data.long2ObjectEntrySet()) {
vectors.put(entry.getLongKey(), ImmutableSparseVector.create(entry.getValue()));
}