use of org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor in project cineast by vitrivr.
the class TreeWalkContainerIteratorProvider method next.
@Override
public synchronized Optional<ExtractionItemContainer> next() {
if (pathIterator.hasNext() && open) {
Path next = pathIterator.next();
Path path = basePath.toFile().isDirectory() ? basePath.toAbsolutePath().relativize(next.toAbsolutePath()) : next.getFileName();
LOGGER.debug("Next path: {}, base {}, res {}", next, basePath, path);
return Optional.of(new ExtractionItemContainer(new MediaObjectDescriptor(path), null, next));
}
return Optional.empty();
}
use of org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor in project cineast by vitrivr.
the class RetrievalResultCSVExporter method notify.
@Override
public void notify(List<ScoreElement> resultList, RetrievalTask task) {
ReadableQueryConfig qc = task.getConfig();
String queryIdString;
if (qc == null || qc.getQueryId() == null) {
LOGGER.error("could not determine query id, using 'null'");
queryIdString = "null";
} else {
queryIdString = qc.getQueryId().toString();
}
String filename = task.getRetriever().getClass().getSimpleName() + ".csv";
File outFolder = new File(baseFolder, queryIdString);
outFolder.mkdirs();
File out = new File(outFolder, filename);
ArrayList<String> ids = new ArrayList<>(resultList.size());
for (ScoreElement e : resultList) {
ids.add(e.getId());
}
Map<String, MediaSegmentDescriptor> segments = mediaSegmentReader.lookUpSegments(ids);
Set<String> objectIds = new HashSet<>();
for (MediaSegmentDescriptor sd : segments.values()) {
objectIds.add(sd.getObjectId());
}
Map<String, MediaObjectDescriptor> objects = mediaObjectReader.lookUpObjects(objectIds);
try (PrintWriter writer = new PrintWriter(out)) {
// header
writer.println("\"rank\", \"id\", \"score\", \"path\"");
int rank = 1;
for (ScoreElement e : resultList) {
writer.print(rank++);
writer.print(',');
writer.print(e.getId());
writer.print(',');
writer.print(e.getScore());
writer.print(',');
writer.print('"');
writer.print(objects.get(segments.get(e.getId()).getObjectId()).getPath().replace('\\', '/'));
writer.println('"');
}
writer.flush();
} catch (FileNotFoundException e) {
LOGGER.error("could not write file '{}': {}", out.getAbsolutePath(), LogHelper.getStackTrace(e));
}
}
use of org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor in project cineast by vitrivr.
the class MediaObjectReader method mapToDescriptor.
private MediaObjectDescriptor mapToDescriptor(Map<String, PrimitiveTypeProvider> map) {
PrimitiveTypeProvider idProvider = map.get(MediaObjectDescriptor.FIELDNAMES[0]);
PrimitiveTypeProvider typeProvider = map.get(MediaObjectDescriptor.FIELDNAMES[1]);
PrimitiveTypeProvider nameProvider = map.get(MediaObjectDescriptor.FIELDNAMES[2]);
PrimitiveTypeProvider pathProvider = map.get(MediaObjectDescriptor.FIELDNAMES[3]);
if (!checkProvider(MediaObjectDescriptor.FIELDNAMES[0], idProvider, ProviderDataType.STRING)) {
return new MediaObjectDescriptor();
}
if (!checkProvider(MediaObjectDescriptor.FIELDNAMES[1], typeProvider, ProviderDataType.INT)) {
return new MediaObjectDescriptor();
}
if (!checkProvider(MediaObjectDescriptor.FIELDNAMES[2], nameProvider, ProviderDataType.STRING)) {
return new MediaObjectDescriptor();
}
if (!checkProvider(MediaObjectDescriptor.FIELDNAMES[3], pathProvider, ProviderDataType.STRING)) {
return new MediaObjectDescriptor();
}
return new MediaObjectDescriptor(idProvider.getString(), nameProvider.getString(), pathProvider.getString(), MediaType.fromId(typeProvider.getInt()), true);
}
use of org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor in project cineast by vitrivr.
the class MediaObjectReader method lookUpObjects.
public Map<String, MediaObjectDescriptor> lookUpObjects(Iterable<String> videoIds) {
if (videoIds == null) {
return new HashMap<>();
}
HashMap<String, MediaObjectDescriptor> _return = new HashMap<>();
List<Map<String, PrimitiveTypeProvider>> results = selector.getRows(MediaObjectDescriptor.FIELDNAMES[0], Lists.newArrayList(videoIds));
results.forEach(el -> {
MediaObjectDescriptor d = mapToDescriptor(el);
_return.put(d.getObjectId(), d);
});
return _return;
}
use of org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor 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;
}
Aggregations