use of org.vitrivr.cineast.core.data.TemporalObject in project cineast by vitrivr.
the class TimeDistanceTemporalScoringAlgorithm method score.
/**
* Score the information given to the class upon the creation of the class according to the sequential scoring algorithm.
*
* @return List of {@link TemporalObject}
*/
@Override
public List<TemporalObject> score() {
/* Calculate the best temporal object linearly for all segments given and assigned in the constructor. */
Map<String, ResultStorage> resultMap = new HashMap<>();
if (this.scoredSegmentSets.size() == 0) {
return new ArrayList<>();
}
this.scoredSegmentSets.values().forEach(set -> {
set.forEach(segment -> {
boolean lsc = segment.getEndAbs() == 0;
TemporalObject best = getBestTemporalObject(segment, lsc);
resultMap.putIfAbsent(best.getObjectId(), new ResultStorage(best.getObjectId()));
List<String> bestSegmentIds = best.getSegments();
List<Integer> bestSequenceNumber = this.getSequenceNumbers(bestSegmentIds);
resultMap.get(best.getObjectId()).addSegmentsAndScore(IntStream.range(0, bestSegmentIds.size()).boxed().collect(Collectors.toMap(bestSequenceNumber::get, bestSegmentIds::get)), best.getScore());
});
});
Stream<TemporalObject> resultStream;
resultStream = resultMap.values().stream().map(ResultStorage::toTemporalObject);
/* Return the sorted temporal objects. */
return resultStream.sorted(Comparator.comparingDouble(TemporalObject::getScore).reversed()).collect(Collectors.toList());
}
use of org.vitrivr.cineast.core.data.TemporalObject 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;
}
use of org.vitrivr.cineast.core.data.TemporalObject 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;
}
use of org.vitrivr.cineast.core.data.TemporalObject 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;
}
use of org.vitrivr.cineast.core.data.TemporalObject in project cineast by vitrivr.
the class TimeDistanceTemporalScoringAlgorithmTest method testTemporalTestCase1.
@Test
@DisplayName("First temporal test case")
public void testTemporalTestCase1() {
TemporalTestCases temporalTestCases = new TemporalTestCases();
temporalTestCases.buildTestCase1();
TimeDistanceTemporalScoringAlgorithm testAlgorithm = new TimeDistanceTemporalScoringAlgorithm(temporalTestCases.getSegmentMap(), temporalTestCases.getContainerResults(), temporalTestCases.getMaxLength(), temporalTestCases.getTimeDistances());
List<TemporalObject> result = testAlgorithm.score();
assert temporalTestCases.assertListSame(temporalTestCases.getExpectedResults(), result);
assert result.size() == 2;
}
Aggregations