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