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

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

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

Query.groupBy介绍

[英]Group the results of this query by an attribute.
[中]按属性将此查询的结果分组。

代码示例

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

@Override
  public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() {
    ObjectStream<IdBox<List<Rating>>> stream = dao.query(Rating.class)
                           .groupBy(CommonAttributes.USER_ID)
                           .stream();
    return ObjectStreams.wrap(stream.map(u -> u.mapValue(Ratings::userRatingVector)),
                 stream);
  }
}

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

@Override
  public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() {
    ObjectStream<IdBox<List<Entity>>> stream = dao.query(getEntityType())
                           .groupBy(CommonAttributes.USER_ID)
                           .stream();
    return ObjectStreams.transform(stream, new Function<IdBox<List<Entity>>, IdBox<Long2DoubleMap>>() {
      @Nullable
      @Override
      public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) {
        if (input == null) {
          return null;
        }

        return IdBox.create(input.getId(),
                  makeVector(input.getValue()));
      }
    });
  }
}

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

@Test
public void testEmptyDAOHasEmptyGroupedResults() {
  EntityCollectionDAO dao = EntityCollectionDAO.create();
  assertThat(dao.query(RATING).groupBy(CommonAttributes.ITEM_ID).get(),
        hasSize(0));
}

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

try (ObjectStream<IdBox<List<Rating>>> userStream = input.query(type)
                             .asType(Rating.class)
                             .groupBy(groupAttribute)
                             .stream()) {
  for (IdBox<List<Rating>> history : userStream) {

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

@Test
public void testGroupEntitiesFluently() {
  List<Entity> entities = new ArrayList<>();
  entities.add(Entities.newBuilder(LIKE, 1)
             .setAttribute(CommonAttributes.USER_ID, 42L)
             .setAttribute(CommonAttributes.ITEM_ID, 39L)
             .build());
  entities.add(Entities.newBuilder(LIKE, 2)
             .setAttribute(CommonAttributes.USER_ID, 67L)
             .setAttribute(CommonAttributes.ITEM_ID, 28L)
             .build());
  entities.add(Entities.newBuilder(LIKE, 3)
             .setAttribute(CommonAttributes.USER_ID, 42L)
             .setAttribute(CommonAttributes.ITEM_ID, 28L)
             .build());
  EntityCollectionDAO dao = EntityCollectionDAO.create(entities);
  EntityQuery<Entity> query = EntityQuery.newBuilder(LIKE)
                      .addSortKey(CommonAttributes.ITEM_ID)
                      .build();
  List<IdBox<List<Entity>>> results = dao.query(LIKE)
                      .orderBy(CommonAttributes.ITEM_ID)
                      .groupBy(CommonAttributes.USER_ID).get();
  assertThat(results, hasSize(2));
  assertThat(results,
        containsInAnyOrder(IdBox.create(42L, (List) ImmutableList.of(entities.get(2), entities.get(0))),
                 IdBox.create(67L, ImmutableList.of(entities.get(1)))));
}

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

DataAccessObject testDao = sds.get();
try (ObjectStream<IdBox<List<Entity>>> ps = testDao.query(EntityType.forName("request"))
                       .groupBy(CommonAttributes.USER_ID)
                       .stream()) {
  for (IdBox<List<Entity>> upairs: ps) {

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

@Override
  public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() {
    ObjectStream<IdBox<List<Entity>>> stream = dao.query(getEntityType())
                           .groupBy(CommonAttributes.USER_ID)
                           .stream();
    return ObjectStreams.transform(stream, new Function<IdBox<List<Entity>>, IdBox<Long2DoubleMap>>() {
      @Nullable
      @Override
      public IdBox<Long2DoubleMap> apply(@Nullable IdBox<List<Entity>> input) {
        if (input == null) {
          return null;
        }

        return IdBox.create(input.getId(),
                  makeVector(input.getValue()));
      }
    });
  }
}

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

@Override
  public ObjectStream<IdBox<Long2DoubleMap>> streamUsers() {
    ObjectStream<IdBox<List<Rating>>> stream = dao.query(Rating.class)
                           .groupBy(CommonAttributes.USER_ID)
                           .stream();
    return ObjectStreams.wrap(stream.map(u -> u.mapValue(Ratings::userRatingVector)),
                 stream);
  }
}

相关文章