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

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

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

Query.get介绍

[英]Get the results of this query as a list.
[中]以列表的形式获取此查询的结果。

代码示例

代码示例来源: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 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

List<Entity> trainHistory = trainData.query(entityType)
                   .withAttribute(CommonAttributes.USER_ID, uid)
                   .get();
                  .get();

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

.get();

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

List<Rating> built = dao.query(Rating.class)
            .orderBy(CommonAttributes.ENTITY_ID)
            .get();
assertThat(built, hasSize(ratings.size()));
assertThat(built, equalTo(sorted));
               .withAttribute(CommonAttributes.USER_ID, user)
               .orderBy(CommonAttributes.TIMESTAMP)
               .get();
  assertThat(fromDAO, equalTo(fromData));
               .withAttribute(CommonAttributes.ITEM_ID, item)
               .orderBy(CommonAttributes.TIMESTAMP)
               .get();
  assertThat(fromDAO, equalTo(fromData));

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

List<Rating> built = dao.query(Rating.class)
            .orderBy(CommonAttributes.ENTITY_ID)
            .get();
assertThat(built, hasSize(ratings.size()));
assertThat(built, equalTo(sorted));
                .withAttribute(CommonAttributes.USER_ID, user)
                .orderBy(CommonAttributes.TIMESTAMP)
                .get();
   assertThat(fromDAO, equalTo(fromData));
               .withAttribute(CommonAttributes.ITEM_ID, item)
               .orderBy(CommonAttributes.TIMESTAMP)
               .get();
  assertThat(fromDAO, equalTo(fromData));

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

List<Entity> users = testData.query(CommonTypes.USER).get();
Stream<Entity> userStream;
if (inForkJoinPool()) {

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

assertThat(dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.ITEM_ID, 20L)
       .get(),
      contains(ratings.get(0)));
       .get(),
      contains(ratings.toArray()));
assertThat(dao.getEntityIds(CommonTypes.ITEM),
      containsInAnyOrder(20L, 21L));
assertThat(dao.query(CommonTypes.USER).get(),
      contains(Entities.create(CommonTypes.USER, 1)));
assertThat(dao.query(CommonTypes.ITEM).get(),
      containsInAnyOrder(Entities.create(CommonTypes.ITEM, 20),
               Entities.create(CommonTypes.ITEM, 21)));

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

assertThat(dao.query(CommonTypes.RATING)
       .withAttribute(CommonAttributes.ITEM_ID, 20L)
       .get(),
      contains(ratings.get(0)));
       .get(),
      contains(ratings.toArray()));
assertThat(dao.getEntityIds(CommonTypes.ITEM),
      containsInAnyOrder(20L, 21L));
assertThat(dao.query(CommonTypes.USER).get(),
      contains(Entities.create(CommonTypes.USER, 1)));
assertThat(dao.query(CommonTypes.ITEM).get(),
      containsInAnyOrder(Entities.create(CommonTypes.ITEM, 20),
               Entities.create(CommonTypes.ITEM, 21)));

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

assertThat(dao.getEntityTypes(), containsInAnyOrder(ets));
List<Entity> ratings = dao.query(CommonTypes.RATING).get();
assertThat(ratings, hasSize(2));
assertThat(dao.query(CommonTypes.USER).get(),
      containsInAnyOrder(Entities.create(CommonTypes.USER, 10),
               Entities.create(CommonTypes.USER, 11)));
assertThat(dao.query(CommonTypes.ITEM).get(),
      contains(Entities.create(CommonTypes.ITEM, 20)));
            .get();
assertThat(rlist, hasSize(2));
assertThat(rlist, (Matcher) equalTo(ratings));

代码示例来源: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

@Test
public void testAddEntityLayout() {
  EntityCollectionDAOBuilder b = EntityCollectionDAO.newBuilder();
  b.addEntityLayout(Rating.ENTITY_TYPE, Rating.ATTRIBUTES);
  Rating r = Rating.newBuilder()
           .setId(42)
           .setUserId(100)
           .setItemId(50)
           .setRating(3.5)
           .setTimestamp(1034801)
           .build();
  b.addEntity(r);
  EntityCollectionDAO dao = b.build();
  assertThat(dao.getEntityIds(CommonTypes.RATING), contains(42L));
  assertThat(dao.streamEntities(CommonTypes.RATING)
         .collect(Collectors.toList()),
        contains(r));
  assertThat(dao.query(Rating.class)
         .get(),
        contains(r));
}

代码示例来源: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;
}

相关文章