org.lenskit.data.dao.Query.withAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(68)

本文整理了Java中org.lenskit.data.dao.Query.withAttribute方法的一些代码示例,展示了Query.withAttribute的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.withAttribute方法的具体详情如下:
包路径:org.lenskit.data.dao.Query
类名称:Query
方法名:withAttribute

Query.withAttribute介绍

[英]Add an attribute value condition to the query.
[中]向查询中添加属性值条件。

代码示例

代码示例来源:origin: lenskit/lenskit

/**
 * Get the default exclude set for a user.  The base implementation gets
 * all the items they have interacted with.
 *
 * @param user The user ID.
 * @return The set of items to exclude.
 */
protected LongSet getDefaultExcludes(long user) {
  // FIXME Support things other than ratings
  return dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.USER_ID, user)
       .valueSet(CommonAttributes.ITEM_ID);
}

代码示例来源:origin: lenskit/lenskit

@Override
protected LongList recommend(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude) {
  if (exclude == null) {
    exclude = data.query(statistics.getEntityType())
           .withAttribute(CommonAttributes.USER_ID, user)
           .valueSet(CommonAttributes.ITEM_ID);
  }
  return recommendWithSets(n, candidates, exclude);
}

代码示例来源:origin: lenskit/lenskit

/**
 * Extract a user vector from a data source.
 *
 * @param uid The user ID.
 * @param dao The DAO.
 * @return The user rating vector.
 */
private Long2DoubleMap makeUserVector(long uid, DataAccessObject dao) {
  List<Rating> history = dao.query(Rating.class)
               .withAttribute(CommonAttributes.USER_ID, uid)
               .get();
  Long2DoubleMap vector = null;
  if (!history.isEmpty()) {
    vector = Ratings.userRatingVector(history);
  }
  return vector;
}

代码示例来源:origin: lenskit/lenskit

@Nonnull
@Override
public Long2DoubleMap userRatingVector(long user) {
  IdBox<Long2DoubleMap> cached = cachedValue;
  if (cached != null && cached.getId() == user) {
    return cached.getValue();
  }
  Long2DoubleMap map;
  try (ObjectStream<Rating> stream = dao.query(Rating.class)
                     .withAttribute(CommonAttributes.USER_ID, user)
                     .stream()) {
    map = Ratings.userRatingVector(stream);
  }
  return map;
}

代码示例来源:origin: lenskit/lenskit

@Nonnull
  @Override
  public ResultMap predictWithDetails(long user, @Nonnull Collection<Long> items) {
    List<Rating> ratings = dao.query(Rating.class)
                 .withAttribute(CommonAttributes.USER_ID, user)
                 .get();
    LongSortedSet wantedItems = LongUtils.packedSet(items);
    List<Result> results = new ArrayList<>();
    for (Rating r: ratings) {
      long item = r.getItemId();
      if (wantedItems.contains(r.getItemId())) {
        results.add(Results.create(item, r.getValue()));
      }
    }
    return Results.newResultMap(results);
  }
}

代码示例来源:origin: lenskit/lenskit

@Nonnull
@Override
public Long2DoubleMap userRatingVector(long user) {
  IdBox<Long2DoubleMap> cached = cachedValue;
  if (cached != null && cached.getId() == user) {
    return cached.getValue();
  }
  Long2DoubleMap map;
  List<Entity> entities = dao.query(getEntityType())
      .withAttribute(CommonAttributes.USER_ID, user)
      .get();
  map = makeVector(entities);
  cachedValue = IdBox.create(user, map);
  return map;
}

代码示例来源:origin: lenskit/lenskit

.withAttribute(CommonAttributes.USER_ID, uid)
 .get();
.withAttribute(CommonAttributes.USER_ID, uid)
.get();

代码示例来源:origin: lenskit/lenskit

.collect(Collectors.toList());
 List<Rating> fromDAO = dao.query(Rating.class)
              .withAttribute(CommonAttributes.USER_ID, user)
              .orderBy(CommonAttributes.TIMESTAMP)
              .get();
                .collect(Collectors.toList());
List<Rating> fromDAO = dao.query(Rating.class)
             .withAttribute(CommonAttributes.ITEM_ID, item)
             .orderBy(CommonAttributes.TIMESTAMP)
             .get();

代码示例来源:origin: lenskit/lenskit

.withAttribute(CommonAttributes.USER_ID, rating.getUserId())
.valueSet(CommonAttributes.ITEM_ID));

代码示例来源:origin: lenskit/lenskit

.collect(Collectors.toList());
List<Rating> fromDAO = dao.query(Rating.class)
             .withAttribute(CommonAttributes.USER_ID, user)
             .orderBy(CommonAttributes.TIMESTAMP)
             .get();
                .collect(Collectors.toList());
List<Rating> fromDAO = dao.query(Rating.class)
             .withAttribute(CommonAttributes.ITEM_ID, item)
             .orderBy(CommonAttributes.TIMESTAMP)
             .get();

代码示例来源:origin: lenskit/lenskit

@Test
public void testQueryRejectOneEntityFluent() {
  Entity e = Entities.newBuilder(LIKE, 1)
            .setAttribute(CommonAttributes.USER_ID, 42L)
            .setAttribute(CommonAttributes.ITEM_ID, 39L)
            .build();
  EntityCollectionDAO dao = EntityCollectionDAO.create(e);
  List<Entity> results = dao.query(LIKE)
               .withAttribute(CommonAttributes.USER_ID, 39L)
               .get();
  assertThat(results, hasSize(0));
}

代码示例来源:origin: lenskit/lenskit

equalTo(ratings.get(0)));
assertThat(dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.ITEM_ID, 20L)
       .get(),
      contains(ratings.get(0)));
       .withAttribute(CommonAttributes.USER_ID, 1L)
       .get(),
      contains(ratings.toArray()));

代码示例来源:origin: lenskit/lenskit

equalTo(ratings.get(0)));
assertThat(dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.ITEM_ID, 20L)
       .get(),
      contains(ratings.get(0)));
       .withAttribute(CommonAttributes.USER_ID, 1L)
       .get(),
      contains(ratings.toArray()));

代码示例来源:origin: lenskit/lenskit

/**
 * Get the IDs of the candidate neighbors for a user.
 * @param user The user.
 * @param userItems The user's rated items.
 * @param targetItems The set of target items.
 * @return The set of IDs of candidate neighbors.
 */
private LongSet findCandidateNeighbors(long user, LongSet userItems, LongCollection targetItems) {
  LongSet users = new LongOpenHashSet(100);
  LongIterator items;
  if (userItems.size() < targetItems.size()) {
    items = userItems.iterator();
  } else {
    items = targetItems.iterator();
  }
  while (items.hasNext()) {
    LongSet iusers = dao.query(CommonTypes.RATING)
        .withAttribute(CommonAttributes.ITEM_ID, items.nextLong())
        .valueSet(CommonAttributes.USER_ID);
    if (iusers != null) {
      users.addAll(iusers);
    }
  }
  users.remove(user);
  return users;
}

代码示例来源:origin: org.lenskit/lenskit-core

/**
 * Get the default exclude set for a user.  The base implementation gets
 * all the items they have interacted with.
 *
 * @param user The user ID.
 * @return The set of items to exclude.
 */
protected LongSet getDefaultExcludes(long user) {
  // FIXME Support things other than ratings
  return dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.USER_ID, user)
       .valueSet(CommonAttributes.ITEM_ID);
}

代码示例来源:origin: org.lenskit/lenskit-core

@Override
protected LongList recommend(long user, int n, @Nullable LongSet candidates, @Nullable LongSet exclude) {
  if (exclude == null) {
    exclude = data.query(statistics.getEntityType())
           .withAttribute(CommonAttributes.USER_ID, user)
           .valueSet(CommonAttributes.ITEM_ID);
  }
  return recommendWithSets(n, candidates, exclude);
}

代码示例来源:origin: org.lenskit/lenskit-core

@Nonnull
@Override
public Long2DoubleMap userRatingVector(long user) {
  IdBox<Long2DoubleMap> cached = cachedValue;
  if (cached != null && cached.getId() == user) {
    return cached.getValue();
  }
  Long2DoubleMap map;
  try (ObjectStream<Rating> stream = dao.query(Rating.class)
                     .withAttribute(CommonAttributes.USER_ID, user)
                     .stream()) {
    map = Ratings.userRatingVector(stream);
  }
  return map;
}

代码示例来源:origin: org.lenskit/lenskit-core

@Nonnull
@Override
public Long2DoubleMap userRatingVector(long user) {
  IdBox<Long2DoubleMap> cached = cachedValue;
  if (cached != null && cached.getId() == user) {
    return cached.getValue();
  }
  Long2DoubleMap map;
  List<Entity> entities = dao.query(getEntityType())
      .withAttribute(CommonAttributes.USER_ID, user)
      .get();
  map = makeVector(entities);
  cachedValue = IdBox.create(user, map);
  return map;
}

代码示例来源:origin: org.lenskit/lenskit-knn

/**
 * Get the IDs of the candidate neighbors for a user.
 * @param user The user.
 * @param userItems The user's rated items.
 * @param targetItems The set of target items.
 * @return The set of IDs of candidate neighbors.
 */
private LongSet findCandidateNeighbors(long user, LongSet userItems, LongCollection targetItems) {
  LongSet users = new LongOpenHashSet(100);
  LongIterator items;
  if (userItems.size() < targetItems.size()) {
    items = userItems.iterator();
  } else {
    items = targetItems.iterator();
  }
  while (items.hasNext()) {
    LongSet iusers = dao.query(CommonTypes.RATING)
        .withAttribute(CommonAttributes.ITEM_ID, items.nextLong())
        .valueSet(CommonAttributes.USER_ID);
    if (iusers != null) {
      users.addAll(iusers);
    }
  }
  users.remove(user);
  return users;
}

相关文章