Search in sources :

Example 1 with PrimitiveTypeProvider

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;
}
Also used : TagReader(org.vitrivr.cineast.core.db.dao.reader.TagReader) QueryStage(org.vitrivr.cineast.api.messages.query.QueryStage) TemporalQuery(org.vitrivr.cineast.api.messages.query.TemporalQuery) GENERIC_ID_COLUMN_QUALIFIER(org.vitrivr.cineast.core.util.CineastConstants.GENERIC_ID_COLUMN_QUALIFIER) DBSelector(org.vitrivr.cineast.core.db.DBSelector) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) AbstractQueryTermContainer(org.vitrivr.cineast.core.data.query.containers.AbstractQueryTermContainer) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject) HashMap(java.util.HashMap) FeaturesByEntityQueryResult(org.vitrivr.cineast.api.messages.result.FeaturesByEntityQueryResult) ArrayList(java.util.ArrayList) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) HashSet(java.util.HashSet) TemporalScoring(org.vitrivr.cineast.core.temporal.TemporalScoring) QueryTerm(org.vitrivr.cineast.api.messages.query.QueryTerm) Map(java.util.Map) Pair(org.vitrivr.cineast.core.data.Pair) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) ContinuousRetrievalLogic(org.vitrivr.cineast.standalone.util.ContinuousRetrievalLogic) FeaturesByCategoryQueryResult(org.vitrivr.cineast.api.messages.result.FeaturesByCategoryQueryResult) MathHelper(org.vitrivr.cineast.core.util.math.MathHelper) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) FeaturesAllCategoriesQueryResult(org.vitrivr.cineast.api.messages.result.FeaturesAllCategoriesQueryResult) Collection(java.util.Collection) QueryConfig(org.vitrivr.cineast.core.config.QueryConfig) Tag(org.vitrivr.cineast.core.data.tag.Tag) ReadableQueryConfig(org.vitrivr.cineast.core.config.ReadableQueryConfig) StringDoublePair(org.vitrivr.cineast.core.data.StringDoublePair) Collectors(java.util.stream.Collectors) List(java.util.List) Logger(org.apache.logging.log4j.Logger) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider) FEATURE_COLUMN_QUALIFIER(org.vitrivr.cineast.core.util.CineastConstants.FEATURE_COLUMN_QUALIFIER) LogManager(org.apache.logging.log4j.LogManager) SegmentTags(org.vitrivr.cineast.core.features.SegmentTags) Config(org.vitrivr.cineast.standalone.config.Config) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) ArrayList(java.util.ArrayList) DBSelector(org.vitrivr.cineast.core.db.DBSelector) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) Map(java.util.Map)

Example 2 with PrimitiveTypeProvider

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);
}
Also used : PersistentTuple(org.vitrivr.cineast.core.db.PersistentTuple) ArrayList(java.util.ArrayList) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 3 with PrimitiveTypeProvider

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) ZonedDateTime(java.time.ZonedDateTime) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 4 with PrimitiveTypeProvider

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);
}
Also used : HashMap(java.util.HashMap) FloatArrayTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.FloatArrayTypeProvider) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider) Location(org.vitrivr.cineast.core.data.Location)

Example 5 with PrimitiveTypeProvider

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

Aggregations

PrimitiveTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)33 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)16 Map (java.util.Map)15 StringTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider)8 LinkedList (java.util.LinkedList)5 StopWatch (org.apache.commons.lang3.time.StopWatch)5 List (java.util.List)4 Tag (org.vitrivr.cineast.core.data.tag.Tag)4 Collectors (java.util.stream.Collectors)3 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)3 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)3 DBSelector (org.vitrivr.cineast.core.db.DBSelector)3 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)2 TObjectFloatHashMap (gnu.trove.map.hash.TObjectFloatHashMap)2 Collection (java.util.Collection)2 TimeUnit (java.util.concurrent.TimeUnit)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 BooleanQueryMessage (org.vitrivr.adampro.grpc.AdamGrpc.BooleanQueryMessage)2