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

Java NoSuchItemException类代码示例

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

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



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

示例1: get

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


示例2: estimateForAnonymous

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的package包/类
@Override
public float estimateForAnonymous(long toItemID, long[] itemIDs, float[] values)
    throws NotReadyException, NoSuchItemException {

  Generation generation = getCurrentGeneration();    
  FastByIDMap<float[]> Y = generation.getY();
  Lock yLock = generation.getYLock().readLock();
  float[] toItemFeatures;    
  yLock.lock();
  try {
    toItemFeatures = Y.get(toItemID);
  } finally {
    yLock.unlock();
  }
  
  if (toItemFeatures == null) {
    throw new NoSuchItemException(toItemID);
  }
  
  float[] anonymousUserFeatures = buildAnonymousUserFeatures(itemIDs, values);    
  
  return (float) SimpleVectorMath.dot(anonymousUserFeatures, toItemFeatures);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:24,代码来源:ServerRecommender.java


示例3: evaluate

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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: testAnonymous

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

  ClientRecommender client = getClient();
  List<RecommendedItem> recs = client.recommendToAnonymous(new long[] {190L}, 3);

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

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

  assertEquals(83L, recs.get(0).getItemID());
  assertEquals(213L, recs.get(1).getItemID());
  assertEquals(86L, recs.get(2).getItemID());

  try {
    client.recommendToAnonymous(new long[]{0L}, 3);
    fail();
  } catch (NoSuchItemException nsie) {
    // good
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:23,代码来源:SimpleTest.java


示例5: testAnonymous2

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

  ClientRecommender client = getClient();
  List<RecommendedItem> recs =
      client.recommendToAnonymous(new long[] {190L}, new float[] {1.0f}, 3);

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

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

  assertEquals(83L, recs.get(0).getItemID());
  assertEquals(213L, recs.get(1).getItemID());
  assertEquals(86L, recs.get(2).getItemID());

  try {
    client.recommendToAnonymous(new long[]{0L}, 3);
    fail();
  } catch (NoSuchItemException nsie) {
    // good
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:24,代码来源:SimpleTest.java


示例6: testAnonymous3

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

  ClientRecommender client = getClient();
  List<RecommendedItem> recs =
      client.recommendToAnonymous(new long[] {190L, 200L}, new float[] {2.0f, 3.0f}, 3);

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

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

  assertEquals(234L, recs.get(0).getItemID());
  assertEquals(185L, recs.get(1).getItemID());
  assertEquals(176L, recs.get(2).getItemID());

  try {
    client.recommendToAnonymous(new long[]{0L}, 3);
    fail();
  } catch (NoSuchItemException nsie) {
    // good
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:24,代码来源:SimpleTest.java


示例7: getPreferencesForItem

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

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


示例8: getPreferencesForItem

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

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


示例9: getBooleanPreferencesForItem

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

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


示例10: recommendToAnonymous

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的package包/类
@Override
public List<RecommendedItem> recommendToAnonymous(long[] itemIDs,
                                                  float[] values,
                                                  int howMany,
                                                  IDRescorer rescorer)
    throws NotReadyException, NoSuchItemException {

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

  float[] anonymousUserFeatures = buildAnonymousUserFeatures(itemIDs, values);

  FastIDSet userKnownItemIDs = new FastIDSet(itemIDs.length);
  for (long itemID : itemIDs) {
    userKnownItemIDs.add(itemID);
  }

  float[][] anonymousFeaturesAsArray = { anonymousUserFeatures };

  Generation generation = getCurrentGeneration();    
  Lock yLock = generation.getYLock().readLock();    
  yLock.lock();
  try {
    return multithreadedTopN(anonymousFeaturesAsArray,
                             userKnownItemIDs,
                             generation.getUserTagIDs(),
                             rescorer,
                             howMany,
                             generation.getCandidateFilter());
  } finally {
    yLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:33,代码来源:ServerRecommender.java


示例11: mostSimilarItems

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的package包/类
/**
 * One-argument version of {@link #mostSimilarItems(long[], int, Rescorer)}.
 */
@Override
public List<RecommendedItem> mostSimilarItems(long itemID, int howMany, Rescorer<LongPair> rescorer)
    throws NoSuchItemException, NotReadyException {

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

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

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

    float[] itemFeatures = Y.get(itemID);
    if (itemFeatures == null) {
      throw new NoSuchItemException(itemID);
    }

    return TopN.selectTopN(new MostSimilarItemIterator(Y.entrySet().iterator(),
                                                       generation.getUserTagIDs(),
                                                       new long[] { itemID },
                                                       new float[][] { itemFeatures },
                                                       rescorer),
                           howMany);
  } finally {
    yLock.unlock();
  }

}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:33,代码来源:ServerRecommender.java


示例12: similarityToItem

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的package包/类
@Override
public float[] similarityToItem(long toItemID, long... itemIDs) throws TasteException {

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

  float[] similarities = new float[itemIDs.length];
  Lock yLock = generation.getYLock().readLock();
  yLock.lock();
  try {

    float[] toFeatures = Y.get(toItemID);
    if (toFeatures == null) {
      throw new NoSuchItemException(toItemID);
    }
    double toFeaturesNorm = SimpleVectorMath.norm(toFeatures);

    boolean anyFound = false;
    for (int i = 0; i < similarities.length; i++) {
      float[] features = Y.get(itemIDs[i]);
      if (features == null) {
        similarities[i] = Float.NaN;
      } else {
        anyFound = true;
        double featuresNorm = SimpleVectorMath.norm(features);
        similarities[i] = (float) (SimpleVectorMath.dot(features, toFeatures) / (featuresNorm * toFeaturesNorm));
      }
    }
    if (!anyFound) {
      throw new NoSuchItemException(Arrays.toString(itemIDs));
    }

  } finally {
    yLock.unlock();
  }

  return similarities;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:39,代码来源:ServerRecommender.java


示例13: recommendedBecause

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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


示例14: buildAnonymousUserFeatures

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的package包/类
private float[] buildAnonymousUserFeatures(long[] itemIDs, float[] values) 
    throws NotReadyException, NoSuchItemException {

  Preconditions.checkArgument(values == null || values.length == itemIDs.length,
                              "Number of values doesn't match number of items");
  
  Generation generation = getCurrentGeneration();

  FastByIDMap<float[]> Y = generation.getY();
  Solver ytySolver = generation.getYTYSolver();
  if (ytySolver == null) {
    throw new NotReadyException();
  }

  float[] anonymousUserFeatures = null;
  Lock yLock = generation.getYLock().readLock();

  boolean anyItemIDFound = false;
  for (int j = 0; j < itemIDs.length; j++) {
    long itemID = itemIDs[j];
    float[] itemFeatures;
    yLock.lock();
    try {
      itemFeatures = Y.get(itemID);
    } finally {
      yLock.unlock();
    }
    if (itemFeatures == null) {
      continue;
    }
    anyItemIDFound = true;
    double[] userFoldIn = ytySolver.solveFToD(itemFeatures);
    if (anonymousUserFeatures == null) {
      anonymousUserFeatures = new float[userFoldIn.length];
    }
    double signedFoldInWeight = foldInWeight(0.0, values == null ? 1.0f : values[j]);
    if (signedFoldInWeight != 0.0) {
      for (int i = 0; i < anonymousUserFeatures.length; i++) {
        anonymousUserFeatures[i] += (float) (signedFoldInWeight * userFoldIn[i]);
      }
    }
  }
  if (!anyItemIDFound) {
    throw new NoSuchItemException(Arrays.toString(itemIDs));
  }

  return anonymousUserFeatures;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:49,代码来源:ServerRecommender.java


示例15: recommendedBecause

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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.NoSuchItemException; //导入依赖的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 itemIDSet = new FastIDSet();
  try {
    while (pathComponents.hasNext()) {
      itemIDSet.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;
  }

  if (itemIDSet.isEmpty()) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
    return;
  }

  MyrrixRecommender recommender = getRecommender();
  RescorerProvider rescorerProvider = getRescorerProvider();
  try {
    int howMany = getHowMany(request);
    Iterable<RecommendedItem> similar;
    if (rescorerProvider == null) {
      similar = recommender.mostSimilarItems(itemIDSet.toArray(), howMany);
    } else {
      Rescorer<LongPair> rescorer =
          rescorerProvider.getMostSimilarItemsRescorer(recommender, getRescorerParams(request));
      similar = recommender.mostSimilarItems(itemIDSet.toArray(),
                                             howMany,
                                             rescorer);
    }
    output(request, response, similar);
  } 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());
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:54,代码来源:SimilarityServlet.java


示例17: doGet

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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 toItemID;
  List<Long> itemIDsList = Lists.newArrayList();
  try {
    toItemID = Long.parseLong(pathComponents.next());
    while (pathComponents.hasNext()) {
      itemIDsList.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;
  }
  if (itemIDsList.isEmpty()) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
    return;
  }
  long[] itemIDs = new long[itemIDsList.size()];
  for (int i = 0; i < itemIDs.length; i++) {
    itemIDs[i] = itemIDsList.get(i);
  }

  MyrrixRecommender recommender = getRecommender();
  try {
    float[] similarities = recommender.similarityToItem(toItemID, itemIDs);
    Writer out = response.getWriter();
    for (float similarity : similarities) {
      out.write(Float.toString(similarity));
      out.write('\n');        
    }
  } 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);
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:50,代码来源:SimilarityToItemServlet.java


示例18: doGet

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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


示例19: doGet

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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();
  Pair<long[],float[]> itemIDsAndValue;
  try {
    itemIDsAndValue = parseItemValuePairs(pathComponents);
  } 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 (itemIDsAndValue.getFirst().length == 0) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
    return;
  }

  long[] itemIDs = itemIDsAndValue.getFirst();
  float[] values = itemIDsAndValue.getSecond();
  
  MyrrixRecommender recommender = getRecommender();
  RescorerProvider rescorerProvider = getRescorerProvider();
  try {
    IDRescorer rescorer = rescorerProvider == null ? null :
        rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request));
    Iterable<RecommendedItem> recommended =
        recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer);
    output(request, response, recommended);
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (NoSuchItemException nsie) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.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,代码行数:48,代码来源:RecommendToAnonymousServlet.java


示例20: doGet

import org.apache.mahout.cf.taste.common.NoSuchItemException; //导入依赖的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 toItemID;
  Pair<long[],float[]> itemIDsAndValue;
  try {
    toItemID = Long.parseLong(pathComponents.next());
    itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
  } 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 (itemIDsAndValue.getFirst().length == 0) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
    return;
  }

  long[] itemIDs = itemIDsAndValue.getFirst();
  float[] values = itemIDsAndValue.getSecond();
  
  MyrrixRecommender recommender = getRecommender();
  try {
    float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
    Writer out = response.getWriter();
    out.write(Float.toString(estimate));
    out.write('\n');
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (NoSuchItemException nsie) {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
  } catch (TasteException te) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
    getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:46,代码来源:EstimateForAnonymousServlet.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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