Search in sources :

Example 6 with MediaSegmentReader

use of org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader in project cineast by vitrivr.

the class CliUtils method printInfoForSegment.

public static void printInfoForSegment(String segmentId, DBSelector selector, String _filterCategory, boolean printObjInfo) {
    System.out.println("= Retrieving segment information for " + segmentId + "=");
    MediaSegmentReader segmentReader = new MediaSegmentReader(selector);
    Optional<MediaSegmentDescriptor> segmentDescriptor = segmentReader.lookUpSegment(segmentId);
    segmentDescriptor.ifPresent(System.out::println);
    segmentDescriptor.ifPresent(descriptor -> {
        if (printObjInfo) {
            printInfoForObject(descriptor.getObjectId(), selector);
        }
    });
    System.out.println("= Retrieving segment metadata =");
    MediaSegmentMetadataReader reader = new MediaSegmentMetadataReader(selector);
    reader.lookupMultimediaMetadata(segmentId).forEach(System.out::println);
    System.out.println("Retrieving all columns for segment " + segmentId);
    RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
    retrievalRuntimeConfig.getRetrieverCategories().forEach(cat -> {
        if (_filterCategory != null) {
            if (!cat.equals(_filterCategory)) {
                return;
            }
        }
        retrievalRuntimeConfig.getRetrieversByCategory(cat).forEachEntry((retriever, weight) -> {
            System.out.println("= Retrieving for feature: " + retriever.getClass().getSimpleName() + " =");
            retriever.getTableNames().forEach(tableName -> {
                selector.open(tableName);
                List<Map<String, PrimitiveTypeProvider>> rows = selector.getRows("id", new StringTypeProvider(segmentId));
                if (retriever.getClass() == RangeBooleanRetriever.class) {
                    rows = selector.getRows("segmentid", new StringTypeProvider(segmentId));
                }
                rows.forEach(row -> {
                    System.out.println("== New row == ");
                    row.forEach((key, value) -> System.out.println(tableName + "." + key + " - " + value));
                });
            });
            return true;
        });
    });
    System.out.println("Done");
}
Also used : MediaSegmentMetadataReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentMetadataReader) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) Map(java.util.Map)

Example 7 with MediaSegmentReader

use of org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader in project cineast by vitrivr.

the class CineastQueryService method getNeighboringSegments.

@Override
public void getNeighboringSegments(CineastGrpc.MediaSegmentIdList request, StreamObserver<CineastGrpc.MediaSegmentQueryResult> responseObserver) {
    MediaSegmentReader mediaSegmentReader = new MediaSegmentReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get());
    Set<String> ids = request.getIdsList().stream().map(CineastGrpc.MediaSegmentId::getId).collect(Collectors.toSet());
    Map<String, MediaSegmentDescriptor> descriptors = mediaSegmentReader.lookUpSegments(ids);
    int range = QueryContainerUtil.queryConfig(request.getQueryConfig()).getMaxResults().orElse(DEFAULT_NEIGHBORING_SEGMENTS) / 2;
    if (range > 0) {
        Set<MediaSegmentDescriptor> results = new HashSet<>(2 * range * descriptors.size());
        for (MediaSegmentDescriptor d : descriptors.values()) {
            results.addAll(mediaSegmentReader.lookUpSegmentsByNumberRange(d.getObjectId(), d.getSequenceNumber() - range, d.getSequenceNumber() + range));
        }
        CineastGrpc.MediaSegmentQueryResult result = CineastGrpc.MediaSegmentQueryResult.newBuilder().addAllSegments(results.stream().map(MediaSegmentUtil::fromMediaSegmentDescriptor).collect(Collectors.toList())).build();
        responseObserver.onNext(result);
    }
    responseObserver.onCompleted();
    mediaSegmentReader.close();
}
Also used : MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) HashSet(java.util.HashSet)

Example 8 with MediaSegmentReader

use of org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader in project cineast by vitrivr.

the class MetadataFeatureModule method init.

@Override
public void init(DBSelectorSupplier selectorSupply) {
    this.dbSelector = selectorSupply.get();
    this.dbSelector.open(this.featureEntityName());
    this.mediaSegmentReader = new MediaSegmentReader(selectorSupply.get());
}
Also used : MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)

Aggregations

MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)8 MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)7 Map (java.util.Map)3 MediaSegmentQueryResult (org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 MediaSegmentMetadataReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentMetadataReader)2 Config (org.vitrivr.cineast.standalone.config.Config)2 StreamObserver (io.grpc.stub.StreamObserver)1 Context (io.javalin.http.Context)1 OpenApiBuilder (io.javalin.plugin.openapi.dsl.OpenApiBuilder)1 OpenApiDocumentation (io.javalin.plugin.openapi.dsl.OpenApiDocumentation)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1