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


Java RecommendedItem.getItemID方法代码示例

本文整理汇总了Java中org.apache.mahout.cf.taste.recommender.RecommendedItem.getItemID方法的典型用法代码示例。如果您正苦于以下问题:Java RecommendedItem.getItemID方法的具体用法?Java RecommendedItem.getItemID怎么用?Java RecommendedItem.getItemID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mahout.cf.taste.recommender.RecommendedItem的用法示例。


在下文中一共展示了RecommendedItem.getItemID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectTopNIntoQueue

import org.apache.mahout.cf.taste.recommender.RecommendedItem; //导入方法依赖的package包/类
/**
 * Computes top N values for a stream and puts them into a {@link Queue}.
 *
 * @param topN {@link Queue} to add to
 * @param values stream of values from which to choose
 * @param n how many top values to choose
 */
public static void selectTopNIntoQueue(Queue<MutableRecommendedItem> topN,
                                       Iterator<RecommendedItem> values,
                                       int n) {
  while (values.hasNext()) {
    RecommendedItem value = values.next();
    if (value != null) {
      long itemID = value.getItemID();
      float valueScore = value.getValue();
      if (topN.size() > n) {
        if (valueScore > topN.peek().getValue()) {
          MutableRecommendedItem recycled = topN.poll();
          recycled.set(itemID, valueScore);
          topN.add(recycled);
        }
      } else {
        topN.add(new MutableRecommendedItem(itemID, valueScore));
      }
    }
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:28,代码来源:TopN.java

示例2: compare

import org.apache.mahout.cf.taste.recommender.RecommendedItem; //导入方法依赖的package包/类
@Override
public int compare(RecommendedItem a, RecommendedItem b) {
  float aValue = a.getValue();
  float bValue = b.getValue();
  if (aValue < bValue) {
    return -1;
  }
  if (aValue > bValue) {
    return 1;
  }
  // Break ties by item ID, *de*scending. It's rare but at least gives predictable ordering.
  long aItem = a.getItemID();
  long bItem = b.getItemID();
  if (aItem > bItem) {
    return -1;
  }
  if (aItem < bItem) {
    return 1;
  }
  return 0;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:22,代码来源:ByValueAscComparator.java

示例3: translate

import org.apache.mahout.cf.taste.recommender.RecommendedItem; //导入方法依赖的package包/类
private List<TranslatedRecommendedItem> translate(Collection<RecommendedItem> originals) {
  List<TranslatedRecommendedItem> translated = Lists.newArrayListWithCapacity(originals.size());
  for (RecommendedItem original : originals) {
    long id = original.getItemID();
    String untranslation = untranslateItem(id);
    String translatedItemID = untranslation == null ? Long.toString(id) : untranslation;
    translated.add(new GenericTranslatedRecommendedItem(translatedItemID, original.getValue()));
  }
  return translated;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:11,代码来源:TranslatingClientRecommender.java

示例4: selectTopNIntoQueueMultithreaded

import org.apache.mahout.cf.taste.recommender.RecommendedItem; //导入方法依赖的package包/类
/**
 * Computes top N values for a stream and puts them into a {@link Queue}.
 * Used in the context of multiple threads.
 *
 * @param topN {@link Queue} to add to
 * @param queueLeastValue in/out parameter caching the queue's least value
 * @param values stream of values from which to choose
 * @param n how many top values to choose
 */
public static void selectTopNIntoQueueMultithreaded(Queue<MutableRecommendedItem> topN,
                                                    float[] queueLeastValue,
                                                    Iterator<RecommendedItem> values,
                                                    int n) {
  // Cache to avoid most synchronization
  float localQueueLeastValue = queueLeastValue[0];

  while (values.hasNext()) {
    RecommendedItem value = values.next();
    if (value != null) {
      long itemID = value.getItemID();
      float valueScore = value.getValue();
      if (valueScore >= localQueueLeastValue) {

        synchronized (topN) {
          if (topN.size() > n) {
            float currentQueueLeastValue = topN.peek().getValue();
            localQueueLeastValue = currentQueueLeastValue;
            if (valueScore > currentQueueLeastValue) {
              MutableRecommendedItem recycled = topN.poll();
              recycled.set(itemID, valueScore);
              topN.add(recycled);
            }
          } else {
            topN.add(new MutableRecommendedItem(itemID, valueScore));
          }
        }
      }
    }
  }

  queueLeastValue[0] = localQueueLeastValue;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:43,代码来源:TopN.java

示例5: doExecute

import org.apache.mahout.cf.taste.recommender.RecommendedItem; //导入方法依赖的package包/类
@Override
protected void doExecute(ExecutionControl executionControl, MahoutSlopeoneGeneratorStats stats) throws Exception {
    // when doExecute() is called, the generator has been initialized with the configuration we should use

    Date execution = new Date();

    MahoutSlopeoneGeneratorConfig config = getConfiguration();

    TypeMappingService typeMappingService = (TypeMappingService) super.getTypeMappingService();
    ItemAssocService itemAssocService = getItemAssocService();

    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(config.getTenantId(), typeMappingService.getIdOfActionType(config.getTenantId(), config.getActionType()), true, mahoutDataModelMappingDAO);

    Recommender recommender = new SlopeOneRecommender(easyrecDataModel);

    itemTypeDAO.insertOrUpdate(config.getTenantId(), "USER", false);

    Integer assocType = typeMappingService.getIdOfAssocType(config.getTenantId(), config.getAssociationType());
    Integer userType = typeMappingService.getIdOfItemType(config.getTenantId(), "USER");
    Integer sourceType = typeMappingService.getIdOfSourceType(config.getTenantId(), getSourceType());
    Integer viewType = typeMappingService.getIdOfViewType(config.getTenantId(), config.getViewType());

    stats.setNumberOfItems(easyrecDataModel.getNumItems());

    for (LongPrimitiveIterator it = easyrecDataModel.getUserIDs(); it.hasNext(); ) {
        long userId = it.nextLong();
        List<RecommendedItem> recommendations = recommender.recommend(userId, config.getNumberOfRecs());

        if (recommendations.isEmpty()) {
            logger.debug("User " + userId + " : no recommendations");
        }

        // print the list of recommendations for each
        for (RecommendedItem recommendedItem : recommendations) {
            logger.debug("User " + userId + " : " + recommendedItem);

            Integer itemToId = (int) recommendedItem.getItemID();
            Integer itemToType = itemDAO.getItemTypeIdOfItem(config.getTenantId(), itemToId);

            ItemVO<Integer, Integer> fromItem = new ItemVO<Integer, Integer>(config.getTenantId(), (int) userId, userType);
            Double recommendationStrength = (double) recommendedItem.getValue();
            ItemVO<Integer, Integer> toItem = new ItemVO<Integer, Integer>(config.getTenantId(), itemToId, itemToType);

            ItemAssocVO<Integer,Integer> itemAssoc = new ItemAssocVO<Integer,Integer>(
                    config.getTenantId(), fromItem, assocType, recommendationStrength, toItem, sourceType,
                    "Mahout Slopeone Generator", viewType, null, execution);

            itemAssocService.insertOrUpdateItemAssoc(itemAssoc);
            stats.incNumberOfRulesCreated();
        }
    }

}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:54,代码来源:MahoutSlopeoneGenerator.java


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