key = new Text(split[0]);
value = new VectorWritable();
double[] values = new double[2];
values[0] = Double.valueOf(split[1]);
values[1] = Double.valueOf(split[2]);
DenseDoubleVector dd = new DenseDoubleVector(values);
value.set(dd);
}
});
final HashMap<String, Integer> genreIndexes = new HashMap<String, Integer>();
genreIndexes.put("action", 0);
genreIndexes.put("animation", 1);
genreIndexes.put("children", 2);
genreIndexes.put("comedy", 3);
genreIndexes.put("crime", 4);
genreIndexes.put("documentary", 5);
genreIndexes.put("drama", 6);
genreIndexes.put("fantasy", 7);
genreIndexes.put("film-noir", 8);
genreIndexes.put("horror", 9);
genreIndexes.put("musical", 10);
genreIndexes.put("mystery", 11);
genreIndexes.put("romance", 12);
genreIndexes.put("sci-fi", 13);
genreIndexes.put("thriller", 14);
genreIndexes.put("war", 15);
genreIndexes.put("western", 16);
genreIndexes.put("imax", 17);
genreIndexes.put("adventure", 18);
conv.setInputItemFeatures(itemFeaturesPath,
new KeyValueParser<Text, VectorWritable>() {
public void parseLine(String ln) {
String[] split = ln.split("::");
key = new Text(split[0]);
String[] genres = split[2].toLowerCase().split("[|]");
value = new VectorWritable();
DenseDoubleVector values = new DenseDoubleVector(genreIndexes.size());
for (int i=0; i<genres.length; i++) {
Integer id = genreIndexes.get(genres[i]);
if (id == null) {
continue;
}
values.set(id, 1);
}
value.set(values);
}
});
return conv.convert(outputPath);