Search in sources :

Example 1 with DBSelector

use of org.vitrivr.cineast.core.db.DBSelector 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 DBSelector

use of org.vitrivr.cineast.core.db.DBSelector in project cineast by vitrivr.

the class CliUtils method retrieveAndLog.

public static void retrieveAndLog(List<Retriever> retrievers, ContinuousRetrievalLogic retrieval, int limit, boolean printDetail, AbstractQueryTermContainer qc) {
    System.out.println("Only printing the first " + limit + " results, change with --limit parameter");
    DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
    retrievers.forEach(retriever -> {
        AtomicBoolean entityExists = new AtomicBoolean(true);
        retriever.getTableNames().forEach(table -> {
            if (!selector.existsEntity(table)) {
                System.out.println("Entity " + table + " does not exist");
                entityExists.set(false);
            }
        });
        if (!entityExists.get()) {
            System.out.println("Not retrieving for " + retriever.getClass().getSimpleName() + " because entity does not exist");
            return;
        }
        System.out.println("Retrieving for " + retriever.getClass().getSimpleName());
        long start = System.currentTimeMillis();
        List<SegmentScoreElement> results = retrieval.retrieveByRetriever(qc, retriever, new ConstrainedQueryConfig().setMaxResults(limit));
        long stop = System.currentTimeMillis();
        System.out.println("Results for " + retriever.getClass().getSimpleName() + ":, retrieved in " + (stop - start) + "ms");
        for (SegmentScoreElement e : results) {
            System.out.print(e.getSegmentId());
            System.out.print(": ");
            System.out.println(e.getScore());
            if (printDetail) {
                CliUtils.printInfoForSegment(e.getSegmentId(), selector, null, true);
            }
        }
        System.out.println();
    });
    retrieval.shutdown();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConstrainedQueryConfig(org.vitrivr.cineast.standalone.config.ConstrainedQueryConfig) SegmentScoreElement(org.vitrivr.cineast.core.data.score.SegmentScoreElement) DBSelector(org.vitrivr.cineast.core.db.DBSelector)

Example 3 with DBSelector

use of org.vitrivr.cineast.core.db.DBSelector in project cineast by vitrivr.

the class QueryUtil method resolveTagsById.

/**
 * Returns all tags for a given list of tagsids
 */
public static List<Tag> resolveTagsById(List<String> tagIds) {
    DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
    TagReader tagReader = new TagReader(selector);
    return tagReader.getTagsById(tagIds.toArray(new String[0]));
}
Also used : DBSelector(org.vitrivr.cineast.core.db.DBSelector) TagReader(org.vitrivr.cineast.core.db.dao.reader.TagReader)

Example 4 with DBSelector

use of org.vitrivr.cineast.core.db.DBSelector in project cineast by vitrivr.

the class QueryUtil method retrieveTagIDs.

/**
 * Retrieves all tag ids belong to certain elements. duplicates are a feature
 *
 * @param ids element ids for which the tags table is to be searched.
 * @return a list of {@link Tag#getId()} ids
 */
public static List<String> retrieveTagIDs(List<String> ids) {
    List<String> _return = new ArrayList<>();
    DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
    selector.open(SegmentTags.SEGMENT_TAGS_TABLE_NAME);
    List<Map<String, PrimitiveTypeProvider>> rows = selector.getRows(GENERIC_ID_COLUMN_QUALIFIER, ids);
    rows.forEach(row -> _return.add(row.get(SegmentTags.TAG_ID_QUALIFIER).getString()));
    return _return;
}
Also used : ArrayList(java.util.ArrayList) DBSelector(org.vitrivr.cineast.core.db.DBSelector) HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) Map(java.util.Map)

Example 5 with DBSelector

use of org.vitrivr.cineast.core.db.DBSelector in project cineast by vitrivr.

the class QueryUtil method getFeaturesFromEntity.

private static ArrayList<HashMap<String, Object>> getFeaturesFromEntity(String entityName, List<String> ids) {
    final DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
    ArrayList<HashMap<String, Object>> currList = new ArrayList<>();
    selector.open(entityName);
    List<Map<String, PrimitiveTypeProvider>> rows;
    if (ids == null || ids.isEmpty()) {
        rows = selector.getAll();
    } else {
        rows = selector.getRows(GENERIC_ID_COLUMN_QUALIFIER, ids);
    }
    for (Map<String, PrimitiveTypeProvider> row : rows) {
        HashMap<String, Object> tempMap = new HashMap<>();
        tempMap.put(FEATURE_COLUMN_QUALIFIER, row.get(FEATURE_COLUMN_QUALIFIER).toObject());
        tempMap.put(GENERIC_ID_COLUMN_QUALIFIER, row.get(GENERIC_ID_COLUMN_QUALIFIER).toObject());
        currList.add(tempMap);
    }
    return currList;
}
Also used : HashMap(java.util.HashMap) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) 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) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Aggregations

DBSelector (org.vitrivr.cineast.core.db.DBSelector)7 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TemporalObject (org.vitrivr.cineast.core.data.TemporalObject)2 PrimitiveTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)2 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)2 TagReader (org.vitrivr.cineast.core.db.dao.reader.TagReader)2 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ToIntFunction (java.util.function.ToIntFunction)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