Package org.apache.mahout.cf.taste.model

Examples of org.apache.mahout.cf.taste.model.Item


    recommended = new ArrayList<RecommendedItem>();
    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


    itemIDPadded.append(itemID);
    while (itemIDPadded.length() < 5) {
      itemIDPadded.insert(0, '0');
    }
    List<Preference> prefs = new ArrayList<Preference>();
    Item movie = getItem(itemID);
    File movieFile = new File(new File(dataDirectory, "training_set"), "mv_00" + itemIDPadded + ".txt");
    for (String line : new FileLineIterable(movieFile, true)) {
      int firstComma = line.indexOf((int) ',');
      Integer userID = Integer.valueOf(line.substring(0, firstComma));
      int secondComma = line.indexOf((int) ',', firstComma + 1);
View Full Code Here

    this.moviesFile = moviesFile;
  }

  @Override
  protected Item buildItem(String id) {
    Item item = movieMap.get(id);
    if (item == null) {
      throw new NoSuchElementException();
    }
    return item;
  }
View Full Code Here

    Preference actualPref = theUser.getPreferenceFor(itemID);
    if (actualPref != null) {
      return actualPref.getValue();
    }
    Collection<User> theNeighborhood = neighborhood.getUserNeighborhood(userID);
    Item item = model.getItem(itemID);
    return doEstimatePreference(theUser, theNeighborhood, item);
  }
View Full Code Here

  private static Set<Item> getAllOtherItems(Iterable<User> theNeighborhood, User theUser) {
    Set<Item> allItems = new FastSet<Item>();
    for (User user : theNeighborhood) {
      Preference[] prefs = user.getPreferencesAsArray();
      for (Preference pref : prefs) {
        Item item = pref.getItem();
        // If not already preferred by the user, add it
        if (theUser.getPreferenceFor(item.getID()) == null) {
          allItems.add(item);
        }
      }
    }
    return allItems;
View Full Code Here

    return list.toArray(new Preference[list.size()]);
  }

  private List<? extends Preference> doGetPreferencesForItem(Object itemID) throws TasteException {
    log.debug("Retrieving preferences for item ID '{}'", itemID);
    Item item = getItem(itemID, true);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      conn = dataSource.getConnection();
View Full Code Here

  }


  private void addPreference(ResultSet rs, Collection<Preference> prefs)
          throws SQLException {
    Item item = buildItem(rs.getString(1));
    double preferenceValue = rs.getDouble(2);
    prefs.add(buildPreference(null, item, preferenceValue));
  }
View Full Code Here

    User theUser = getDataModel().getUser(userID);
    List<RecommendedItem> rescored = new ArrayList<RecommendedItem>(recommended.size());
    // Only add items the user doesn't already have a preference for.
    // And that the rescorer doesn't "reject".
    for (RecommendedItem recommendedItem : recommended) {
      Item item = recommendedItem.getItem();
      if (rescorer != null && rescorer.isFiltered(item)) {
        continue;
      }
      if (theUser.getPreferenceFor(item.getID()) == null &&
          (rescorer == null || !Double.isNaN(rescorer.rescore(item, recommendedItem.getValue())))) {
        rescored.add(recommendedItem);
      }
    }
    Collections.sort(rescored, new ByRescoreComparator(rescorer));
View Full Code Here

          break;
        }
      }
    } else {
      // add pref -- assume it does not already exist
      Item item = itemCache.get(itemID);
      if (item == null) {
        item = buildItem(itemID);
        itemCache.put(itemID, item);
      }
      log.debug("Read item '{}' for user ID '{}'", item, userID);
View Full Code Here

public final class NullRescorerTest extends TasteTestCase {

  public void testItemRescorer() throws Exception {
    Rescorer<Item> rescorer = NullRescorer.getItemInstance();
    assertNotNull(rescorer);
    Item item = new GenericItem<String>("test");
    assertEquals(1.0, rescorer.rescore(item, 1.0));
    assertEquals(1.0, rescorer.rescore(null, 1.0));
    assertEquals(0.0, rescorer.rescore(item, 0.0));
    assertTrue(Double.isNaN(rescorer.rescore(item, Double.NaN)));
  }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.model.Item

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.