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);
}
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()));
}
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);
}
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;
}
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();
}
Aggregations