Package org.apache.mahout.cf.taste.impl.recommender

Examples of org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem


      List<RecommendedItem> items = new LinkedList<RecommendedItem>();
      for (String token : tokens) {
        String[] itemTokens = token.split(":");
        long itemID = Long.parseLong(itemTokens[0]);
        float value = Float.parseFloat(itemTokens[1]);
        items.add(new GenericRecommendedItem(itemID, value));
      }
      recommendations.put(userID, items);
    }
    return recommendations;
  }
View Full Code Here


    try {
      do {
        String itemID = in.readUTF();
        double value = in.readDouble();
        Item item = new GenericItem<String>(itemID);
        RecommendedItem recommendedItem = new GenericRecommendedItem(item, value);
        recommended.add(recommendedItem);
      } while (true);
    } catch (EOFException eofe) {
      // continue; done
    }
View Full Code Here

    int size = in.readInt();
    recommended = Lists.newArrayListWithCapacity(size);
    for (int i = 0; i < size; i++) {
      long itemID = Varint.readSignedVarLong(in);
      float value = in.readFloat();
      RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
      recommended.add(recommendedItem);
    }
  }
View Full Code Here

      List<RecommendedItem> items = Lists.newLinkedList();
      for (String token : tokens) {
        String[] itemTokens = token.split(":");
        long itemID = Long.parseLong(itemTokens[0]);
        float value = Float.parseFloat(itemTokens[1]);
        items.add(new GenericRecommendedItem(itemID, value));
      }
      recommendations.put(userID, items);
    }
    return recommendations;
  }
View Full Code Here

    recommended = new ArrayList<RecommendedItem>();
    try {
      do {
        long itemID = in.readLong();
        float value = in.readFloat();
        RecommendedItem recommendedItem = new GenericRecommendedItem(itemID, value);
        recommended.add(recommendedItem);
      } while (true);
    } catch (EOFException eofe) {
      // continue; done
    }
View Full Code Here

  }

  private static List<RecommendedItem> makeNCandidates(int n) {
    List<RecommendedItem> candidates = Lists.newArrayListWithCapacity(n);
    for (int i = 1; i <= n; i++) {
      candidates.add(new GenericRecommendedItem(i, i));
    }
    return candidates;
  }
View Full Code Here

        long userID = Long.parseLong(parts.next());
        long itemID = Long.parseLong(parts.next());
        if (parts.hasNext()) {
          String token = parts.next().trim();
          if (!token.isEmpty()) {
            data.put(userID, new GenericRecommendedItem(itemID, LangUtils.parseFloat(token)));
          }
          // Ignore remove lines
        } else {
          data.put(userID, new GenericRecommendedItem(itemID, 1.0f));
        }
        if (++count % 1000000 == 0) {
          log.info("Finished {} lines", count);
        }
      }
View Full Code Here

      CharSequence line;
      while ((line = reader.readLine()) != null) {
        Iterator<String> tokens = COMMA.split(line).iterator();
        long itemID = Long.parseLong(tokens.next());
        float value = LangUtils.parseFloat(tokens.next());
        result.add(new GenericRecommendedItem(itemID, value));
      }
    } finally {
      reader.close();
    }
    return result;
View Full Code Here

            if (parts.hasNext()) {
              String token = parts.next().trim();
              if (!token.isEmpty()) {
                float value = LangUtils.parseFloat(token);
                if (userIsTag) {
                  itemTags.put(userIDString, new GenericRecommendedItem(itemID, value));
                } else if (itemIsTag) {
                  userTags.put(itemIDString, new GenericRecommendedItem(userID, value));
                } else {
                  if (provider != null) {
                    IDRescorer rescorer = provider.getRecommendRescorer(new long[] {userID}, null);
                    if (rescorer != null) {
                      value = (float) rescorer.rescore(itemID, value);
                    }
                  }
                  data.put(userID, new GenericRecommendedItem(itemID, value));
                }
              }
              // Ignore remove lines
            } else {
              if (userIsTag) {
                itemTags.put(userIDString, new GenericRecommendedItem(itemID, 1.0f));
              } else if (itemIsTag) {
                userTags.put(itemIDString, new GenericRecommendedItem(userID, 1.0f));
              } else {
                float value = 1.0f;               
                if (provider != null) {
                  IDRescorer rescorer = provider.getRecommendRescorer(new long[] {userID}, null);
                  if (rescorer != null) {
                    value = (float) rescorer.rescore(itemID, value);
                  }
                }
                data.put(userID, new GenericRecommendedItem(itemID, value));
              }
            }
          }
        }
        if (++count % 1000000 == 0) {
View Full Code Here

      long itemID = indexItemIDMap.get(index);
      if (itemsToRecommendFor == null || itemsToRecommendFor.contains(itemID)) {
        float value = (float) element.get();
        if (!Float.isNaN(value)) {
          if (topItems.size() < recommendationsPerUser) {
            topItems.add(new GenericRecommendedItem(itemID, value));
          } else if (value > topItems.peek().getValue()) {
            topItems.add(new GenericRecommendedItem(itemID, value));
            topItems.poll();
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.