Search in sources :

Example 6 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor 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 7 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class TemporalTestCases method buildTestCase4.

public void buildTestCase4() {
    Map<String, MediaSegmentDescriptor> segmentMap = new HashMap<>();
    List<List<StringDoublePair>> containerResults = new ArrayList<>();
    segmentMap.put(descriptor1_1.getSegmentId(), descriptor1_1);
    segmentMap.put(descriptor1_2.getSegmentId(), descriptor1_2);
    segmentMap.put(descriptor1_4.getSegmentId(), descriptor1_4);
    segmentMap.put(descriptor1_5.getSegmentId(), descriptor1_5);
    segmentMap.put(descriptor2_3.getSegmentId(), descriptor2_3);
    segmentMap.put(descriptor2_4.getSegmentId(), descriptor2_4);
    segmentMap.put(descriptor2_5.getSegmentId(), descriptor2_5);
    segmentMap.put(descriptor2_6.getSegmentId(), descriptor2_6);
    segmentMap.put(descriptor2_7.getSegmentId(), descriptor2_7);
    segmentMap.put(descriptor3_5.getSegmentId(), descriptor3_5);
    segmentMap.put(descriptor3_6.getSegmentId(), descriptor3_6);
    segmentMap.put(descriptor3_7.getSegmentId(), descriptor3_7);
    List<StringDoublePair> containerList0 = new ArrayList<>();
    containerList0.add(new StringDoublePair(descriptor1_1.getSegmentId(), 1d));
    containerList0.add(new StringDoublePair(descriptor2_3.getSegmentId(), 1d));
    containerList0.add(new StringDoublePair(descriptor2_5.getSegmentId(), 1d));
    containerList0.add(new StringDoublePair(descriptor3_5.getSegmentId(), 1d));
    List<StringDoublePair> containerList1 = new ArrayList<>();
    containerList1.add(new StringDoublePair(descriptor1_2.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor2_3.getSegmentId(), 0.5d));
    containerList1.add(new StringDoublePair(descriptor2_6.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor3_5.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor3_6.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor3_6.getSegmentId(), 1d));
    List<StringDoublePair> containerList2 = new ArrayList<>();
    containerList2.add(new StringDoublePair(descriptor1_4.getSegmentId(), 1d));
    containerList2.add(new StringDoublePair(descriptor1_5.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor2_3.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor2_3.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor2_7.getSegmentId(), 1d));
    containerList2.add(new StringDoublePair(descriptor3_7.getSegmentId(), 1d));
    containerResults.add(0, containerList0);
    containerResults.add(1, containerList1);
    containerResults.add(2, containerList2);
    List<TemporalObject> expectedResults = new ArrayList<>();
    List<String> segments3 = new ArrayList<>();
    segments3.add(descriptor3_5.getSegmentId());
    segments3.add(descriptor3_6.getSegmentId());
    segments3.add(descriptor3_7.getSegmentId());
    TemporalObject t1 = new TemporalObject(segments3, descriptor3_5.getObjectId(), 1f);
    expectedResults.add(t1);
    List<String> segments2 = new ArrayList<>();
    segments2.add(descriptor2_3.getSegmentId());
    segments2.add(descriptor2_5.getSegmentId());
    segments2.add(descriptor2_6.getSegmentId());
    segments2.add(descriptor2_7.getSegmentId());
    TemporalObject t2 = new TemporalObject(segments2, descriptor2_3.getObjectId(), 1f);
    expectedResults.add(t2);
    List<String> segments1 = new ArrayList<>();
    segments1.add(descriptor1_1.getSegmentId());
    segments1.add(descriptor1_2.getSegmentId());
    segments1.add(descriptor1_4.getSegmentId());
    segments1.add(descriptor1_5.getSegmentId());
    TemporalObject t3 = new TemporalObject(segments1, descriptor1_1.getObjectId(), 2f / 3f);
    expectedResults.add(t3);
    this.segmentMap = segmentMap;
    this.containerResults = containerResults;
    this.maxLength = 30f;
    this.expectedResults = expectedResults;
    List<Float> timeDistances = new ArrayList<>();
    timeDistances.add(0f);
    timeDistances.add(0f);
    this.timeDistances = timeDistances;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringDoublePair(org.vitrivr.cineast.core.data.StringDoublePair) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class TemporalTestCases method buildTestCase2.

public void buildTestCase2() {
    Map<String, MediaSegmentDescriptor> segmentMap = new HashMap<>();
    List<List<StringDoublePair>> containerResults = new ArrayList<>();
    segmentMap.put(descriptor1_1.getSegmentId(), descriptor1_1);
    segmentMap.put(descriptor1_2.getSegmentId(), descriptor1_2);
    segmentMap.put(descriptor1_3.getSegmentId(), descriptor1_3);
    List<StringDoublePair> containerList0 = new ArrayList<>();
    containerList0.add(new StringDoublePair(descriptor1_1.getSegmentId(), 1d));
    List<StringDoublePair> containerList1 = new ArrayList<>();
    containerList1.add(new StringDoublePair(descriptor1_2.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor1_3.getSegmentId(), 0.5d));
    containerResults.add(0, containerList0);
    containerResults.add(1, containerList1);
    List<TemporalObject> expectedResults = new ArrayList<>();
    List<String> segments1 = new ArrayList<>();
    segments1.add(descriptor1_1.getSegmentId());
    segments1.add(descriptor1_2.getSegmentId());
    segments1.add(descriptor1_3.getSegmentId());
    TemporalObject t1 = new TemporalObject(segments1, descriptor1_1.getObjectId(), 1f);
    expectedResults.add(t1);
    this.segmentMap = segmentMap;
    this.containerResults = containerResults;
    this.maxLength = 20f;
    this.expectedResults = expectedResults;
    List<Float> timeDistances = new ArrayList<>();
    timeDistances.add(0f);
    this.timeDistances = timeDistances;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringDoublePair(org.vitrivr.cineast.core.data.StringDoublePair) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class TemporalTestCases method buildTestCase3.

public void buildTestCase3() {
    Map<String, MediaSegmentDescriptor> segmentMap = new HashMap<>();
    List<List<StringDoublePair>> containerResults = new ArrayList<>();
    segmentMap.put(descriptor1_1.getSegmentId(), descriptor1_1);
    segmentMap.put(descriptor1_2.getSegmentId(), descriptor1_2);
    segmentMap.put(descriptor1_3.getSegmentId(), descriptor1_3);
    segmentMap.put(descriptor1_4.getSegmentId(), descriptor1_4);
    segmentMap.put(descriptor1_5.getSegmentId(), descriptor1_5);
    segmentMap.put(descriptor1_6.getSegmentId(), descriptor1_6);
    segmentMap.put(descriptor1_7.getSegmentId(), descriptor1_7);
    List<StringDoublePair> containerList0 = new ArrayList<>();
    containerList0.add(new StringDoublePair(descriptor1_1.getSegmentId(), 1d));
    List<StringDoublePair> containerList1 = new ArrayList<>();
    containerList1.add(new StringDoublePair(descriptor1_2.getSegmentId(), 1d));
    containerList1.add(new StringDoublePair(descriptor1_3.getSegmentId(), 0.5d));
    containerList1.add(new StringDoublePair(descriptor1_7.getSegmentId(), 2d));
    List<StringDoublePair> containerList2 = new ArrayList<>();
    containerList2.add(new StringDoublePair(descriptor1_3.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor1_3.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor1_4.getSegmentId(), 1d));
    containerList2.add(new StringDoublePair(descriptor1_5.getSegmentId(), 0.5d));
    containerList2.add(new StringDoublePair(descriptor1_5.getSegmentId(), 1d));
    containerResults.add(0, containerList0);
    containerResults.add(1, containerList1);
    containerResults.add(2, containerList2);
    List<TemporalObject> expectedResults = new ArrayList<>();
    List<String> segments1 = new ArrayList<>();
    segments1.add(descriptor1_1.getSegmentId());
    segments1.add(descriptor1_2.getSegmentId());
    segments1.add(descriptor1_3.getSegmentId());
    segments1.add(descriptor1_4.getSegmentId());
    segments1.add(descriptor1_5.getSegmentId());
    segments1.add(descriptor1_7.getSegmentId());
    /* optimal result is 1: (1,1), 2: (2,1) 3: (3, 0.5) , because 4 is not a valid result */
    TemporalObject t1 = new TemporalObject(segments1, descriptor1_1.getObjectId(), 2.5 / 3f);
    expectedResults.add(t1);
    this.segmentMap = segmentMap;
    this.containerResults = containerResults;
    this.maxLength = 30f;
    this.expectedResults = expectedResults;
    List<Float> timeDistances = new ArrayList<>();
    timeDistances.add(0f);
    timeDistances.add(0f);
    this.timeDistances = timeDistances;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringDoublePair(org.vitrivr.cineast.core.data.StringDoublePair) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 10 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor 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)

Aggregations

MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)23 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 StringDoublePair (org.vitrivr.cineast.core.data.StringDoublePair)8 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)8 Map (java.util.Map)7 TemporalObject (org.vitrivr.cineast.core.data.TemporalObject)7 Collectors (java.util.stream.Collectors)5 HashSet (java.util.HashSet)4 MediaSegmentQueryResult (org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)4 Config (org.vitrivr.cineast.standalone.config.Config)4 Set (java.util.Set)3 IntStream (java.util.stream.IntStream)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 MediaObjectDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor)3 FileNotFoundException (java.io.FileNotFoundException)2 Comparator (java.util.Comparator)2 TreeMap (java.util.TreeMap)2