use of org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider in project cineast by vitrivr.
the class QueryUtil method retrieveFeaturesForIDByCategory.
/**
* Retrieves all features for a given id (i.e. segment, object id) and a given category.
*/
public static List<Object> retrieveFeaturesForIDByCategory(String id, String category) {
final RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
final DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
List<Object> _return = new ArrayList<>();
retrievalRuntimeConfig.getRetrieversByCategory(category).forEachKey(retriever -> {
retriever.getTableNames().forEach(tableName -> {
selector.open(tableName);
List<Map<String, PrimitiveTypeProvider>> rows = selector.getRows(GENERIC_ID_COLUMN_QUALIFIER, new StringTypeProvider(id));
rows.stream().map(row -> row.get(FEATURE_COLUMN_QUALIFIER).toObject()).forEach(_return::add);
});
// Return value false would break the foreEachKey
return true;
});
return _return;
}
use of org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider in project cineast by vitrivr.
the class Copier method copyBatchedFrom.
public void copyBatchedFrom(int batchSize, Importer<?> importer) {
if (batchSize <= 0) {
copy();
return;
}
Map<String, PrimitiveTypeProvider> map = importer.readNextAsMap();
if (map == null) {
return;
}
Set<String> keyset = map.keySet();
String[] names = new String[keyset.size()];
int i = 0;
for (String name : keyset) {
names[i++] = name;
}
this.writer.open(entityName);
this.writer.setFieldNames(names);
Object[] objects = new Object[names.length];
ArrayList<PersistentTuple> tupleCache = new ArrayList<>(batchSize);
long start = System.currentTimeMillis();
ImportTaskMonitor.reportImportProgress(0, entityName, 0);
do {
for (i = 0; i < names.length; ++i) {
objects[i] = PrimitiveTypeProvider.getObject(map.get(names[i]));
}
PersistentTuple tuple = this.writer.generateTuple(objects);
tupleCache.add(tuple);
if (tupleCache.size() >= batchSize) {
int size = tupleCache.size();
this.writer.persist(tupleCache);
long stop = System.currentTimeMillis();
LOGGER.trace("Inserted {} elements in {} ms", size, stop - start);
ImportTaskMonitor.reportImportProgress(size, entityName, stop - start);
tupleCache.clear();
start = System.currentTimeMillis();
}
} while ((map = importer.readNextAsMap()) != null);
int size = tupleCache.size();
this.writer.persist(tupleCache);
long stop = System.currentTimeMillis();
LOGGER.trace("Inserted {} elements in {} ms", size, stop - start);
ImportTaskMonitor.reportImportProgress(size, entityName, stop - start);
}
use of org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider in project cineast by vitrivr.
the class ProcessingMetaImporter method parseAsMeta.
private Map<String, PrimitiveTypeProvider> parseAsMeta(String segmentId, String path, String[] items) {
final HashMap<String, PrimitiveTypeProvider> map = new HashMap<>(items.length + 9);
map.put("id", PrimitiveTypeProvider.fromObject(segmentId));
for (int i = 0; i < items.length; i++) {
switch(i) {
case LSCUtilities.META_LAT_COL:
case LSCUtilities.META_LON_COL:
if (StringUtils.isNotBlank(items[i]) && !items[i].equalsIgnoreCase("null")) {
// Only add if useful
map.put(LSCUtilities.META_NAMES[i], PrimitiveTypeProvider.fromObject(Double.parseDouble(items[i])));
} else {
LOGGER.trace("Did not include " + segmentId + " :" + LSCUtilities.META_NAMES[i] + ", beacuse its blank or null:" + items[i]);
map.put(LSCUtilities.META_NAMES[i], PrimitiveTypeProvider.fromObject(Double.NaN));
}
break;
default:
map.put(LSCUtilities.META_NAMES[i], PrimitiveTypeProvider.fromObject(items[i]));
break;
}
}
// Purposely no isPresent check, because it should not be possible
final String minuteId = LSCUtilities.filenameToMinuteId(path).get();
final LocalDateTime dt = LSCUtilities.fromMinuteId(minuteId);
map.put(LSCUtilities.PROCESSED_META_DATETIME, PrimitiveTypeProvider.fromObject(dt.toString()));
map.put(LSCUtilities.PROCESSED_META_DAY_OF_WEEK, PrimitiveTypeProvider.fromObject(String.valueOf(dt.getDayOfWeek())));
map.put(LSCUtilities.PROCESSED_META_MONTH, PrimitiveTypeProvider.fromObject(LSCUtilities.extractMonth(dt)));
// Numeric values
map.put(LSCUtilities.PROCESSED_META_DAY, PrimitiveTypeProvider.fromObject(LSCUtilities.extractDay(dt)));
map.put(LSCUtilities.PROCESSED_META_YEAR, PrimitiveTypeProvider.fromObject(LSCUtilities.extractYear(dt)));
map.put(LSCUtilities.PROCESSED_META_HOUR_OF_DAY, PrimitiveTypeProvider.fromObject(LSCUtilities.extractHour(dt)));
if (StringUtils.isNotBlank(items[LSCUtilities.META_UTC_COL]) && !items[LSCUtilities.META_UTC_COL].equalsIgnoreCase("null")) {
map.put(LSCUtilities.PROCESSED_META_UTC, PrimitiveTypeProvider.fromObject(LSCUtilities.convertUtc(items[LSCUtilities.META_UTC_COL]).toString()));
}
// Processed temporal metadata, based on metadata file
if ((StringUtils.isNotBlank(items[LSCUtilities.META_LOCAL_COL]) && !items[LSCUtilities.META_LOCAL_COL].equalsIgnoreCase("null")) && (StringUtils.isNotBlank(items[LSCUtilities.META_TIMEZONE_COL]) && !items[LSCUtilities.META_TIMEZONE_COL].equalsIgnoreCase("null"))) {
final ZonedDateTime zdt = LSCUtilities.convertLocal(items[LSCUtilities.META_LOCAL_COL], items[LSCUtilities.META_TIMEZONE_COL]);
map.put(LSCUtilities.PROCESSED_META_LOCAL, PrimitiveTypeProvider.fromObject(zdt.toString()));
map.put(LSCUtilities.PROCESSED_META_PHASE_OF_DAY, PrimitiveTypeProvider.fromObject(LSCUtilities.extractPhaseOfDay(zdt)));
} else {
map.put(LSCUtilities.PROCESSED_META_LOCAL, PrimitiveTypeProvider.fromObject(null));
map.put(LSCUtilities.PROCESSED_META_PHASE_OF_DAY, PrimitiveTypeProvider.fromObject(null));
}
return map;
}
use of org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider in project cineast by vitrivr.
the class SpatialImporter method parseEntry.
private Optional<Map<String, PrimitiveTypeProvider>> parseEntry(String key, String[] data) {
String lat = data[LSCUtilities.META_LAT_COL];
String lon = data[LSCUtilities.META_LON_COL];
if (LSCUtilities.isAnyMetaBlank(lat, lon)) {
LOGGER.warn("Either lat or long for {} is blank. Ignoring.", key);
return Optional.empty();
}
boolean ignore = false;
float fLat = Float.NaN, fLon = Float.NaN;
try {
fLat = Float.parseFloat(lat);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse latitute for {}, as it was {}", key, lat, e);
ignore = true;
}
try {
fLon = Float.parseFloat(lon);
} catch (NumberFormatException e) {
LOGGER.warn("Could not parse longitutde for {}, as it was {}", key, lon, e);
ignore = true;
}
if (ignore) {
return Optional.empty();
}
Location location = Location.of(fLat, fLon);
FloatArrayTypeProvider vector = new FloatArrayTypeProvider(ReadableFloatVector.toArray(location));
final HashMap<String, PrimitiveTypeProvider> map = new HashMap<>();
// id
map.put("id", PrimitiveTypeProvider.fromObject(LSCUtilities.pathToSegmentId(key)));
// feature
map.put("feature", vector);
return Optional.of(map);
}
use of org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider in project cineast by vitrivr.
the class TemporalImporter method parseEntry.
private Optional<Map<String, PrimitiveTypeProvider>> parseEntry(String key, String[] data) {
final long ms = toEpochMillis(filenameToMinuteIdMap.get(key));
final PrimitiveTypeProvider msProvider = PrimitiveTypeProvider.fromObject(ms);
final HashMap<String, PrimitiveTypeProvider> map = new HashMap<>();
// id
map.put("id", PrimitiveTypeProvider.fromObject(LSCUtilities.pathToSegmentId(key)));
// temporal info
map.put("segmentstart", msProvider);
// Segment ends one millis later
map.put("segmentend", PrimitiveTypeProvider.fromObject(ms + 1));
map.put("startabs", msProvider);
return Optional.of(map);
}
Aggregations