Search in sources :

Example 1 with MediaSegmentQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult in project cineast by vitrivr.

the class FindSegmentsByIdGetHandler method doGet.

@Override
public MediaSegmentQueryResult doGet(Context ctx) {
    final Map<String, String> parameters = ctx.pathParamMap();
    final String segmentId = parameters.get(ID_NAME);
    final MediaSegmentReader sl = new MediaSegmentReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get());
    final List<MediaSegmentDescriptor> list = sl.lookUpSegment(segmentId).map(s -> {
        final List<MediaSegmentDescriptor> segments = new ArrayList<>(1);
        segments.add(s);
        return segments;
    }).orElse(new ArrayList<>(0));
    sl.close();
    return new MediaSegmentQueryResult("", list);
}
Also used : List(java.util.List) GetRestHandler(org.vitrivr.cineast.api.rest.handlers.interfaces.GetRestHandler) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) Context(io.javalin.http.Context) Map(java.util.Map) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) OpenApiDocumentation(io.javalin.plugin.openapi.dsl.OpenApiDocumentation) OpenApiBuilder(io.javalin.plugin.openapi.dsl.OpenApiBuilder) ArrayList(java.util.ArrayList) Config(org.vitrivr.cineast.standalone.config.Config) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with MediaSegmentQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult in project cineast by vitrivr.

the class FindSegmentByIdPostHandler method performPost.

@Override
public MediaSegmentQueryResult performPost(IdList ids, Context ctx) {
    if (ids == null || ids.getIds().length == 0) {
        return new MediaSegmentQueryResult("", new ArrayList<>(0));
    }
    final MediaSegmentReader sl = new MediaSegmentReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get());
    final Map<String, MediaSegmentDescriptor> segments = sl.lookUpSegments(Arrays.asList(ids.getIds()));
    sl.close();
    return new MediaSegmentQueryResult("", new ArrayList<>(segments.values()));
}
Also used : MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)

Example 3 with MediaSegmentQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult in project cineast by vitrivr.

the class FindSegmentsByObjectIdGetHandler method doGet.

@Override
public MediaSegmentQueryResult doGet(Context ctx) {
    final Map<String, String> parameters = ctx.pathParamMap();
    final String objectId = parameters.get(ID_NAME);
    final MediaSegmentReader sl = new MediaSegmentReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get());
    final List<MediaSegmentDescriptor> list = sl.lookUpSegmentsOfObject(objectId);
    sl.close();
    return new MediaSegmentQueryResult("", list);
}
Also used : MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)

Example 4 with MediaSegmentQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult in project cineast by vitrivr.

the class AbstractQueryMessageHandler method submitPrefetchedSegmentandObjectInformationfromIDs.

List<String> submitPrefetchedSegmentandObjectInformationfromIDs(Session session, String queryId, List<MediaSegmentDescriptor> segments, List<String> objectIds) {
    LOGGER.trace("Loading object information");
    final List<MediaObjectDescriptor> objects = this.loadObjects(objectIds, queryId.substring(0, 3));
    if (segments.isEmpty() || objects.isEmpty()) {
        LOGGER.traceEntry("Segment / Objectlist is Empty, ignoring this iteration");
    }
    LOGGER.trace("Writing results to the websocket");
    /* Write segments, objects and similarity search data to stream. */
    this.write(session, new MediaObjectQueryResult(queryId, objects));
    this.write(session, new MediaSegmentQueryResult(queryId, segments));
    return objectIds;
}
Also used : MediaObjectDescriptor(org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor) MediaObjectQueryResult(org.vitrivr.cineast.api.messages.result.MediaObjectQueryResult) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)

Example 5 with MediaSegmentQueryResult

use of org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult in project cineast by vitrivr.

the class NeighbouringQueryMessageHandler method execute.

/**
 * Executes a {@link NeighboringSegmentQuery} message. Performs a lookup for the {@link MediaSegmentDescriptor}s that are temporal neigbours of the provided segment ID.
 *
 * @param session                             WebSocket session the invocation is associated with.
 * @param qconf                               The {@link QueryConfig} that contains additional specifications.
 * @param message                             Instance of {@link NeighboringSegmentQuery}
 * @param segmentIdsForWhichMetadataIsFetched Segment IDs for which metadata is fetched
 * @param objectIdsForWhichMetadataIsFetched  Object IDs for which metadata is fetched
 */
@Override
public void execute(Session session, QueryConfig qconf, NeighboringSegmentQuery message, Set<String> segmentIdsForWhichMetadataIsFetched, Set<String> objectIdsForWhichMetadataIsFetched) throws Exception {
    /* Prepare QueryConfig (so as to obtain a QueryId). */
    final String uuid = qconf.getQueryId().toString();
    /* Retrieve segments. If empty, abort query. */
    final String segmentId = message.getSegmentId();
    if (segmentId == null || segmentId.isEmpty()) {
        return;
    }
    Optional<MediaSegmentDescriptor> segmentOption = this.mediaSegmentReader.lookUpSegment(segmentId);
    if (!segmentOption.isPresent()) {
        return;
    }
    MediaSegmentDescriptor segment = segmentOption.get();
    final List<MediaSegmentDescriptor> segments = this.mediaSegmentReader.lookUpSegmentsByNumberRange(segment.getObjectId(), segment.getSequenceNumber() - message.getCount(), segment.getSequenceNumber() + message.getCount());
    /* Write segments to stream. */
    CompletableFuture<Void> future = this.write(session, new MediaSegmentQueryResult(uuid, segments));
    /* Load and transmit segment metadata. */
    List<Thread> threads = this.loadAndWriteSegmentMetadata(session, uuid, segments.stream().map(MediaSegmentDescriptor::getSegmentId).collect(Collectors.toList()), segmentIdsForWhichMetadataIsFetched, message.getMetadataAccessSpec());
    for (Thread thread : threads) {
        thread.join();
    }
    future.join();
}
Also used : MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)

Aggregations

MediaSegmentQueryResult (org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)5 MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)4 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)3 Context (io.javalin.http.Context)1 OpenApiBuilder (io.javalin.plugin.openapi.dsl.OpenApiBuilder)1 OpenApiDocumentation (io.javalin.plugin.openapi.dsl.OpenApiDocumentation)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 MediaObjectQueryResult (org.vitrivr.cineast.api.messages.result.MediaObjectQueryResult)1 GetRestHandler (org.vitrivr.cineast.api.rest.handlers.interfaces.GetRestHandler)1 MediaObjectDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor)1 Config (org.vitrivr.cineast.standalone.config.Config)1