Exemplo n.º 1
0
 /**
  * CSV output contains one recommendation per line, and each line is of the form {@code
  * itemID,strength}, like {@code "ABC",0.53}. Strength is an opaque indicator of the relative
  * quality of the recommendation.
  */
 final void output(ServletResponse response, Iterable<IDValue> items) throws IOException {
   Writer writer = response.getWriter();
   for (IDValue item : items) {
     writer.write(DelimitedDataUtils.encode(item.getID(), Float.toString(item.getValue())));
     writer.write('\n');
   }
 }
Exemplo n.º 2
0
 private static String setToString(LongFloatMap map) {
   LongPrimitiveIterator it = map.keySetIterator();
   Collection<String> keyStrings = Lists.newArrayListWithCapacity(map.size());
   while (it.hasNext()) {
     keyStrings.add(Long.toString(it.nextLong()));
   }
   return DelimitedDataUtils.encode(',', keyStrings);
 }
Exemplo n.º 3
0
 @Override
 public void process(Pair<Long, Iterable<NumericIDValue>> input, Emitter<String> emitter) {
   StringLongMapping mapping = idMapping.getIDMapping();
   Iterable<NumericIDValue> recs = TopN.selectTopN(input.second().iterator(), numRecs);
   String userID = mapping.toString(input.first());
   for (NumericIDValue rec : recs) {
     emitter.emit(
         DelimitedDataUtils.encode(
             ',', userID, mapping.toString(rec.getID()), Float.toString(rec.getValue())));
   }
 }