BSPPeer<Text, VectorWritable, Text, VectorWritable, MapWritable> peer,
HashSet<Text> requiredUserFeatures,
HashSet<Text> requiredItemFeatures)
throws IOException {
Text key = new Text();
VectorWritable value = new VectorWritable();
int counter = 0;
requiredUserFeatures = new HashSet<Text>();
requiredItemFeatures = new HashSet<Text>();
while(peer.readNext(key, value)) {
// key format: (0, 1..n)
// 0 - delimiter, for type of key
// 1..n - actaul key value
String firstSymbol = key.toString().substring(0, 1);
String actualId = key.toString().substring(1);
if (firstSymbol.equals(inputPreferenceDelim)) {
// parse as <k:userId, v:(itemId, score)>
String itemId = Long.toString((long)value.getVector().get(0));
String score = Double.toString(value.getVector().get(1));
if (usersMatrix.containsKey(actualId) == false) {
DenseDoubleVector vals = new DenseDoubleVector(MATRIX_RANK);
for (int i=0; i<MATRIX_RANK; i++) {
vals.set(i, rnd.nextDouble());
}
VectorWritable rndValues = new VectorWritable(vals);
usersMatrix.put(actualId, rndValues);
}
if (itemsMatrix.containsKey(itemId) == false) {
DenseDoubleVector vals = new DenseDoubleVector(MATRIX_RANK);
for (int i=0; i<MATRIX_RANK; i++) {
vals.set(i, rnd.nextDouble());
}
VectorWritable rndValues = new VectorWritable(vals);
itemsMatrix.put(itemId, rndValues);
}
preferences.add(new Preference<String, String>(actualId, itemId, Double.parseDouble(score)));
indexes.add(counter);