Search in sources :

Example 1 with RetrievalRuntimeConfig

use of org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig 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 RetrievalRuntimeConfig

use of org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig in project cineast by vitrivr.

the class QueryUtil method getFeaturesForCategory.

private static Map<String, ArrayList<HashMap<String, Object>>> getFeaturesForCategory(String category, List<String> ids) {
    final RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
    Map<String, ArrayList<HashMap<String, Object>>> _return = new HashMap<>();
    retrievalRuntimeConfig.getRetrieversByCategory(category).forEach(retriever -> {
        retriever.getTableNames().forEach(tableName -> _return.put(tableName, getFeaturesFromEntity(tableName, ids)));
        return true;
    });
    return _return;
}
Also used : HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) ArrayList(java.util.ArrayList) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject)

Example 3 with RetrievalRuntimeConfig

use of org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig in project cineast by vitrivr.

the class CliUtils method printInfoForSegment.

public static void printInfoForSegment(String segmentId, DBSelector selector, String _filterCategory, boolean printObjInfo) {
    System.out.println("= Retrieving segment information for " + segmentId + "=");
    MediaSegmentReader segmentReader = new MediaSegmentReader(selector);
    Optional<MediaSegmentDescriptor> segmentDescriptor = segmentReader.lookUpSegment(segmentId);
    segmentDescriptor.ifPresent(System.out::println);
    segmentDescriptor.ifPresent(descriptor -> {
        if (printObjInfo) {
            printInfoForObject(descriptor.getObjectId(), selector);
        }
    });
    System.out.println("= Retrieving segment metadata =");
    MediaSegmentMetadataReader reader = new MediaSegmentMetadataReader(selector);
    reader.lookupMultimediaMetadata(segmentId).forEach(System.out::println);
    System.out.println("Retrieving all columns for segment " + segmentId);
    RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
    retrievalRuntimeConfig.getRetrieverCategories().forEach(cat -> {
        if (_filterCategory != null) {
            if (!cat.equals(_filterCategory)) {
                return;
            }
        }
        retrievalRuntimeConfig.getRetrieversByCategory(cat).forEachEntry((retriever, weight) -> {
            System.out.println("= Retrieving for feature: " + retriever.getClass().getSimpleName() + " =");
            retriever.getTableNames().forEach(tableName -> {
                selector.open(tableName);
                List<Map<String, PrimitiveTypeProvider>> rows = selector.getRows("id", new StringTypeProvider(segmentId));
                if (retriever.getClass() == RangeBooleanRetriever.class) {
                    rows = selector.getRows("segmentid", new StringTypeProvider(segmentId));
                }
                rows.forEach(row -> {
                    System.out.println("== New row == ");
                    row.forEach((key, value) -> System.out.println(tableName + "." + key + " - " + value));
                });
            });
            return true;
        });
    });
    System.out.println("Done");
}
Also used : MediaSegmentMetadataReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentMetadataReader) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) Map(java.util.Map)

Example 4 with RetrievalRuntimeConfig

use of org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig in project cineast by vitrivr.

the class QueryUtil method retrieveFeaturesForAllCategories.

public static FeaturesAllCategoriesQueryResult retrieveFeaturesForAllCategories(String id) {
    Map<String, Object[]> features = new HashMap<>();
    final RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
    retrievalRuntimeConfig.getRetrieverCategories().forEach(cat -> {
        List<Object> _features = retrieveFeaturesForIDByCategory(id, cat);
        if (_features.size() == 0) {
            return;
        }
        if (_features.get(0) != null) {
            features.put(cat, _features.toArray());
        }
    });
    return new FeaturesAllCategoriesQueryResult("", features, id);
}
Also used : HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) FeaturesAllCategoriesQueryResult(org.vitrivr.cineast.api.messages.result.FeaturesAllCategoriesQueryResult) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) TemporalObject(org.vitrivr.cineast.core.data.TemporalObject)

Aggregations

RetrievalRuntimeConfig (org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig)4 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)3 HashMap (java.util.HashMap)3 TemporalObject (org.vitrivr.cineast.core.data.TemporalObject)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 FeaturesAllCategoriesQueryResult (org.vitrivr.cineast.api.messages.result.FeaturesAllCategoriesQueryResult)2 StringTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider)2 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 QueryStage (org.vitrivr.cineast.api.messages.query.QueryStage)1 QueryTerm (org.vitrivr.cineast.api.messages.query.QueryTerm)1 TemporalQuery (org.vitrivr.cineast.api.messages.query.TemporalQuery)1 FeaturesByCategoryQueryResult (org.vitrivr.cineast.api.messages.result.FeaturesByCategoryQueryResult)1 FeaturesByEntityQueryResult (org.vitrivr.cineast.api.messages.result.FeaturesByEntityQueryResult)1