Search in sources :

Example 6 with MediaObjectDescriptor

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();
}
Also used : Path(java.nio.file.Path) MediaObjectDescriptor(org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor) ExtractionItemContainer(org.vitrivr.cineast.standalone.run.ExtractionItemContainer)

Example 7 with MediaObjectDescriptor

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));
    }
}
Also used : MediaObjectDescriptor(org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor) ScoreElement(org.vitrivr.cineast.core.data.score.ScoreElement) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) File(java.io.File) HashSet(java.util.HashSet) PrintWriter(java.io.PrintWriter)

Example 8 with MediaObjectDescriptor

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);
}
Also used : MediaObjectDescriptor(org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 9 with MediaObjectDescriptor

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;
}
Also used : MediaObjectDescriptor(org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with MediaObjectDescriptor

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

Aggregations

MediaObjectDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor)14 MediaObjectReader (org.vitrivr.cineast.core.db.dao.reader.MediaObjectReader)6 MediaObjectQueryResult (org.vitrivr.cineast.api.messages.result.MediaObjectQueryResult)4 MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)4 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 HashSet (java.util.HashSet)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)2 MediaType (org.vitrivr.cineast.core.data.MediaType)2 MediaObjectMetadataDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectMetadataDescriptor)2 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)2 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)2 StreamObserver (io.grpc.stub.StreamObserver)1