当前位置: 首页>>代码示例>>Java>>正文


Java NoSuchUserException类代码示例

本文整理汇总了Java中org.apache.mahout.cf.taste.common.NoSuchUserException的典型用法代码示例。如果您正苦于以下问题:Java NoSuchUserException类的具体用法?Java NoSuchUserException怎么用?Java NoSuchUserException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NoSuchUserException类属于org.apache.mahout.cf.taste.common包,在下文中一共展示了NoSuchUserException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public PreferenceArray get(Long userID) throws TasteException {
    try {
        List<Entity> results = getItemsForUser(userID);
        if(results == null || results.isEmpty()) {
            throw new NoSuchUserException(userID);
        }
        int i = 0;
        PreferenceArray prefs = new GenericUserPreferenceArray(results.size());
        prefs.setUserID(0, userID);
        for (Entity entity : results) {
            prefs.setItemID(
                    i,
                    DatastoreHelper.getLong(
                            DatastoreHelper.getPropertyMap(entity).get(ITEM_ID_COLUMN)
                    )
            );
            prefs.setValue(i, 1f);
            i++;
        }
        return prefs;
    } catch (DatastoreException e) {
        throw new TasteException(e);
    }
}
 
开发者ID:balarj,项目名称:rmend-be,代码行数:26,代码来源:GoogleDatastoreDataModel.java

示例2: getRecommendations

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * Give the recommendations based on the supplied User instance.
 * This will make the calls to Mahout and ask it to give recommendations
 * for the given User instance that this user is likely interested in.
 * Although we speak about Users here, this can be any object type.
 * Note: The recommendations that are returned are the result of the
 * algorithm you use, if the results do not match your expectations, please
 * try using another algorithm. See the documentation for more information.
 * @param x The user object to give recommendations of.
 * @param howMany The number of recommendations you would like to get.
 * @param aType The type of the recommendation, either USER (in case of User
 * to Item recommendations) or ITEM (in case of Item to Item recommendations)
 * @return A list with recommended items that are recommended by Mahout
 * for this user.
 */
public List<?> getRecommendations(Object x, int howMany, RecFieldType aType) {
    if(checkAvailabilityOfRecommendations(aType) == false){
        org.webdsl.logging.Logger.warn("Warning, you request to get recommendations while the recommendations taste table has not yet been filled by Mahout.\nEither wait for it to finish its background task, or call the reconstructRecommendCache function (last option should be used with care, on non-production systems only.)");
        return new ArrayList<Object>();
    }
    long startTime = System.currentTimeMillis();

    try {
        long id = getIDOfObject(x, aType);

        List<RecommendedItem> recommendations = aType == RecFieldType.USER ? this.userRecommenderCache.recommend(id, howMany) : this.itemRecommenderCache.recommend(id, howMany);

        this.lastExecutionTime = System.currentTimeMillis() - startTime;
        //org.webdsl.logging.Logger.info("Obtaining the list of recommendations took: " + this.lastExecutionTime);
        return getObjectsOfIDList(recommendations, RecFieldType.ITEM);
    } catch(NoSuchUserException nse){
        /* Recommendations cannot be given because the user is unknown */
        return new ArrayList<Object>();
    } catch (Exception e){
        org.webdsl.logging.Logger.error("Error, catched an exception while obtaining the recommendations! " + e);
        org.webdsl.logging.Logger.error("EXCEPTION",e);
        return new ArrayList<Object>();
    }
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:40,代码来源:RecommendEntityServlet.java

示例3: evaluate

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public EvaluationResult evaluate(MyrrixRecommender recommender,
                                 RescorerProvider provider, // ignored
                                 Multimap<Long,RecommendedItem> testData) throws TasteException {
  DoubleWeightedMean score = new DoubleWeightedMean();
  int count = 0;
  for (Map.Entry<Long,RecommendedItem> entry : testData.entries()) {
    long userID = entry.getKey();
    RecommendedItem itemPref = entry.getValue();
    try {
      float estimate = recommender.estimatePreference(userID, itemPref.getItemID());
      Preconditions.checkState(LangUtils.isFinite(estimate));
      score.increment(1.0 - estimate, itemPref.getValue());
    } catch (NoSuchItemException nsie) {
      // continue
    } catch (NoSuchUserException nsue) {
      // continue
    }
    if (++count % 100000 == 0) {
      log.info("Score: {}", score);
    }
  }
  log.info("Score: {}", score);
  return new EvaluationResultImpl(score.getResult());
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:26,代码来源:EstimatedStrengthEvaluator.java

示例4: testSetRemove

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Test
public void testSetRemove() throws Exception {
  ClientRecommender client = getClient();

  client.setPreference(0L, 1L);
  List<RecommendedItem> recs = client.recommend(0L, 1);
  assertEquals(50L, recs.get(0).getItemID());

  client.setPreference(0L, 2L, 1.0f);
  recs = client.recommend(0L, 1);
  assertEquals(50L, recs.get(0).getItemID());

  client.removePreference(0L, 2L);
  recs = client.recommend(0L, 1);
  assertEquals(50L, recs.get(0).getItemID());

  client.removePreference(0L, 1L);
  try {
    client.recommend(0L, 1);
    fail();
  } catch (NoSuchUserException nsue) {
    // good
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:25,代码来源:SimpleTest.java

示例5: getPreferencesFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public PreferenceArray getPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
    try {
        return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericPreferenceRowMapper));
    } catch (EmptyResultDataAccessException e) {
        logger.warn("An error occurred!", e);
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:12,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例6: getBooleanPreferencesFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public PreferenceArray getBooleanPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
    try {
        return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericBooleanPreferenceRowMapper));
    } catch (EmptyResultDataAccessException e) {
        logger.warn("An error occurred!", e);
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:12,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例7: getItemIDsFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public FastIDSet getItemIDsFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};

    try {
        return getJdbcTemplate().query(getItemIDsFromUserQuery, args, argTypes, fastIDSetExtractor);
    } catch (EmptyResultDataAccessException e) {
        logger.warn("An error occurred!", e);
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:13,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例8: getPreferencesFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public PreferenceArray getPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
    try {
        return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericPreferenceRowMapper));
    } catch (EmptyResultDataAccessException e) {
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:11,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例9: getBooleanPreferencesFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public PreferenceArray getBooleanPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
    try {
        return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericBooleanPreferenceRowMapper));
    } catch (EmptyResultDataAccessException e) {
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:11,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例10: getItemIDsFromUser

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
public FastIDSet getItemIDsFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
    Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
    int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};

    try {
        return getJdbcTemplate().query(getItemIDsFromUserQuery, args, argTypes, fastIDSetExtractor);
    } catch (EmptyResultDataAccessException e) {
        throw new NoSuchUserException(userID);
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:12,代码来源:MahoutDataModelMappingDAOMysqlImpl.java

示例11: recommend

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * @param userID user for which recommendations are to be computed
 * @param howMany desired number of recommendations
 * @param considerKnownItems if true, items that the user is already associated to are candidates
 *  for recommendation. Normally this is {@code false}.
 * @param rescorerParams optional parameters to send to the server's {@code RescorerProvider}
 * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to least
 * @throws NoSuchUserException if the user is not known in the model
 * @throws NotReadyException if the recommender has no model available yet
 * @throws TasteException if another error occurs
 * @throws UnsupportedOperationException if rescorer is not null
 */
public List<RecommendedItem> recommend(long userID,
                                       int howMany,
                                       boolean considerKnownItems,
                                       String[] rescorerParams) throws TasteException {

  StringBuilder urlPath = new StringBuilder();
  urlPath.append("/recommend/");
  urlPath.append(userID);
  appendCommonQueryParams(howMany, considerKnownItems, rescorerParams, urlPath);

  TasteException savedException = null;
  for (HostAndPort replica : choosePartitionAndReplicas(userID)) {
    HttpURLConnection connection = null;
    try {
      connection = buildConnectionToReplica(replica, urlPath.toString(), "GET");
      switch (connection.getResponseCode()) {
        case HttpURLConnection.HTTP_OK:
          return consumeItems(connection);
        case HttpURLConnection.HTTP_NOT_FOUND:
          throw new NoSuchUserException(userID);
        case HttpURLConnection.HTTP_UNAVAILABLE:
          throw new NotReadyException();
        default:
          throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage());
      }
    } catch (TasteException te) {
      log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString());
      savedException = te;
    } catch (IOException ioe) {
      log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString());
      savedException = new TasteException(ioe);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
  }
  throw savedException;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:52,代码来源:ClientRecommender.java

示例12: recommendedBecause

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * <p>Lists the items that were most influential in recommending a given item to a given user. Exactly how this
 * is determined is left to the implementation, but, generally this will return items that the user prefers
 * and that are similar to the given item.</p>
 *
 * <p>These values by which the results are ordered are opaque values and have no interpretation
 * other than that larger means stronger.</p>
 *
 * @param userID ID of user who was recommended the item
 * @param itemID ID of item that was recommended
 * @param howMany maximum number of items to return
 * @return {@link List} of {@link RecommendedItem}, ordered from most influential in recommended the given
 *  item to least
 * @throws NoSuchUserException if the user is not known in the model
 * @throws NoSuchItemException if the item is not known in the model
 * @throws NotReadyException if the recommender has no model available yet
 * @throws TasteException if another error occurs
 */
@Override
public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany) throws TasteException {
  String urlPath = "/because/" + userID + '/' + itemID + "?howMany=" + howMany;

  TasteException savedException = null;
  for (HostAndPort replica : choosePartitionAndReplicas(userID)) {
    HttpURLConnection connection = null;
    try {
      connection = buildConnectionToReplica(replica, urlPath, "GET");
      switch (connection.getResponseCode()) {
        case HttpURLConnection.HTTP_OK:
          return consumeItems(connection);
        case HttpURLConnection.HTTP_NOT_FOUND:
          String connectionMessage = connection.getResponseMessage();
          if (connectionMessage != null &&
              connectionMessage.contains(NoSuchUserException.class.getSimpleName())) {
            throw new NoSuchUserException(userID);
          } else {
            throw new NoSuchItemException(itemID);
          }
        case HttpURLConnection.HTTP_UNAVAILABLE:
          throw new NotReadyException();
        default:
          throw new TasteException(connection.getResponseCode() + " " + connection.getResponseMessage());
      }
    } catch (TasteException te) {
      log.info("Can't access {} at {}: ({})", urlPath, replica, te.toString());
      savedException = te;
    } catch (IOException ioe) {
      log.info("Can't access {} at {}: ({})", urlPath, replica, ioe.toString());
      savedException = new TasteException(ioe);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
  }
  throw savedException;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:58,代码来源:ClientRecommender.java

示例13: testRecommend

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Test
public void testRecommend() throws Exception {

  ClientRecommender client = getClient();
  List<RecommendedItem> recs = client.recommend(1L, 3);

  assertNotNull(recs);
  assertEquals(3, recs.size());

  log.info("{}", recs);

  assertEquals(475L, recs.get(0).getItemID());
  assertEquals(582L, recs.get(1).getItemID());
  assertEquals(403L, recs.get(2).getItemID());

  try {
    client.recommend(0L, 3);
    fail();
  } catch (NoSuchUserException nsue) {
    // good
  }

  recs = client.recommend(1L, 3, true, (String[]) null);

  assertNotNull(recs);
  assertEquals(3, recs.size());

  log.info("{}", recs);

  assertEquals(179L, recs.get(0).getItemID());
  assertEquals(475L, recs.get(1).getItemID());
  assertEquals(135L, recs.get(2).getItemID());
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:34,代码来源:SimpleTest.java

示例14: recommend

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * Like {@link #recommend(long, int, IDRescorer)} but supplies no rescorer.
 */
@Override
public List<RecommendedItem> recommend(long userID, int howMany) throws NoSuchUserException, NotReadyException {
  return recommend(userID, howMany, null);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:8,代码来源:ServerRecommender.java

示例15: recommendedBecause

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * <p>Lists the items that were most influential in recommending a given item to a given user. Exactly how this
 * is determined is left to the implementation, but, generally this will return items that the user prefers
 * and that are similar to the given item.</p>
 *
 * <p>These values by which the results are ordered are opaque values and have no interpretation
 * other than that larger means stronger.</p>
 *
 * @param userID ID of user who was recommended the item
 * @param itemID ID of item that was recommended
 * @param howMany maximum number of items to return
 * @return {@link List} of {@link RecommendedItem}, ordered from most influential in recommended the given
 *  item to least
 * @throws NoSuchUserException if the user is not known in the model
 * @throws NoSuchItemException if the item is not known in the model
 * @throws NotReadyException if the recommender has no model available yet
 */
@Override
public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany)
    throws NoSuchUserException, NoSuchItemException, NotReadyException {

  Preconditions.checkArgument(howMany > 0, "howMany must be positive");

  Generation generation = getCurrentGeneration();
  FastByIDMap<FastIDSet> knownItemIDs = generation.getKnownItemIDs();
  if (knownItemIDs == null) {
    throw new UnsupportedOperationException("No known item IDs available");
  }

  Lock knownItemLock = generation.getKnownItemLock().readLock();
  FastIDSet userKnownItemIDs;
  knownItemLock.lock();
  try {
    userKnownItemIDs = knownItemIDs.get(userID);
  } finally {
    knownItemLock.unlock();
  }
  if (userKnownItemIDs == null) {
    throw new NoSuchUserException(userID);
  }

  FastByIDMap<float[]> Y = generation.getY();

  Lock yLock = generation.getYLock().readLock();
  yLock.lock();
  try {

    float[] features = Y.get(itemID);
    if (features == null) {
      throw new NoSuchItemException(itemID);
    }
    FastByIDMap<float[]> toFeatures;
    synchronized (userKnownItemIDs) {
      toFeatures = new FastByIDMap<float[]>(userKnownItemIDs.size());
      LongPrimitiveIterator it = userKnownItemIDs.iterator();
      while (it.hasNext()) {
        long fromItemID = it.nextLong();
        float[] fromFeatures = Y.get(fromItemID);
        toFeatures.put(fromItemID, fromFeatures);
      }
    }

    return TopN.selectTopN(new RecommendedBecauseIterator(toFeatures.entrySet().iterator(), 
                                                          generation.getUserTagIDs(), 
                                                          features), 
                           howMany);
  } finally {
    yLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:71,代码来源:ServerRecommender.java


注:本文中的org.apache.mahout.cf.taste.common.NoSuchUserException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。