• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NoSuchUserException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: doGet

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

  CharSequence pathInfo = request.getPathInfo();
  if (pathInfo == null) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
    return;
  }
  Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
  long userID;
  long itemID;
  try {
    userID = Long.parseLong(pathComponents.next());
    itemID = Long.parseLong(pathComponents.next());
  } catch (NoSuchElementException nsee) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
    return;
  } catch (NumberFormatException nfe) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
    return;
  }
  if (pathComponents.hasNext()) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Path too long");
    return;
  }

  MyrrixRecommender recommender = getRecommender();
  try {
    Iterable<RecommendedItem> similar = recommender.recommendedBecause(userID, itemID, getHowMany(request));
    output(request, response, similar);
  } catch (NoSuchUserException nsue) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsue.toString());
  } catch (NoSuchItemException nsie) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (TasteException te) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
    getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
  } catch (IllegalArgumentException iae) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
  } catch (UnsupportedOperationException uoe) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, uoe.toString());
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:46,代码来源:BecauseServlet.java


示例17: doGet

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

  CharSequence pathInfo = request.getPathInfo();
  if (pathInfo == null) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
    return;
  }
  Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
  FastIDSet userIDSet = new FastIDSet();
  try {
    while (pathComponents.hasNext()) {
      userIDSet.add(Long.parseLong(pathComponents.next()));
    }
  } catch (NoSuchElementException nsee) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
    return;
  } catch (NumberFormatException nfe) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
    return;
  }

  long[] userIDs = userIDSet.toArray();

  MyrrixRecommender recommender = getRecommender();
  RescorerProvider rescorerProvider = getRescorerProvider();
  try {
    IDRescorer rescorer = rescorerProvider == null ? null :
        rescorerProvider.getRecommendRescorer(userIDs, recommender, getRescorerParams(request));
    Iterable<RecommendedItem> recommended =
        recommender.recommendToMany(userIDs, getHowMany(request), getConsiderKnownItems(request), rescorer);
    output(request, response, recommended);
  } catch (NoSuchUserException nsue) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsue.toString());
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (TasteException te) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
    getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
  } catch (IllegalArgumentException iae) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:44,代码来源:RecommendToManyServlet.java


示例18: doGet

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

  CharSequence pathInfo = request.getPathInfo();
  if (pathInfo == null) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
    return;
  }
  Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
  long userID;
  try {
    userID = Long.parseLong(pathComponents.next());
  } catch (NoSuchElementException nsee) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
    return;
  } catch (NumberFormatException nfe) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
    return;
  }
  if (pathComponents.hasNext()) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Path too long");
    return;
  }

  MyrrixRecommender recommender = getRecommender();
  RescorerProvider rescorerProvider = getRescorerProvider();
  try {
    IDRescorer rescorer = rescorerProvider == null ? null :
        rescorerProvider.getRecommendRescorer(new long[] {userID}, recommender, getRescorerParams(request));
    Iterable<RecommendedItem> recommended =
        recommender.recommend(userID, getHowMany(request), getConsiderKnownItems(request), rescorer);
    output(request, response, recommended);
  } catch (NoSuchUserException nsue) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsue.toString());
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (TasteException te) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
    getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
  } catch (IllegalArgumentException iae) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
  } catch (UnsupportedOperationException uoe) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, uoe.toString());
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:46,代码来源:RecommendServlet.java


示例19: recommendToMany

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
/**
 * @param userIDs users 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 <em>none</em> of {@code userIDs} are known in the model. Otherwise unknown
 *  user IDs are ignored.
 * @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> recommendToMany(long[] userIDs,
                                             int howMany,
                                             boolean considerKnownItems,
                                             String[] rescorerParams) throws TasteException {

  StringBuilder urlPath = new StringBuilder(32);
  urlPath.append("/recommendToMany");
  for (long userID : userIDs) {
    urlPath.append('/').append(userID);
  }
  appendCommonQueryParams(howMany, considerKnownItems, rescorerParams, urlPath);

  // Note that this assumes that all user IDs are on the same partition. It will fail at request
  // time if not since the partition of the first user doesn't contain the others.
  TasteException savedException = null;
  for (HostAndPort replica : choosePartitionAndReplicas(userIDs[0])) {
    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(Arrays.toString(userIDs));
        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,代码行数:57,代码来源:ClientRecommender.java


示例20: testRecommendToManyNonexistent1

import org.apache.mahout.cf.taste.common.NoSuchUserException; //导入依赖的package包/类
@Test(expected = NoSuchUserException.class)
public void testRecommendToManyNonexistent1() throws Exception {
  getClient().recommendToMany(new long[] {Integer.MAX_VALUE}, 3, false, (String[]) null);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:5,代码来源:SimpleTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WxMpMessageHandler类代码示例发布时间:2022-05-23
下一篇:
Java FeatureInfo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap