Search in sources :

Example 1 with StringTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider 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 StringTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider in project cineast by vitrivr.

the class SegmentTags method getSimilar.

@Override
public List<ScoreElement> getSimilar(String segmentId, ReadableQueryConfig qc) {
    List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getRows("id", new StringTypeProvider(segmentId));
    if (rows.isEmpty()) {
        return Collections.emptyList();
    }
    ArrayList<WeightedTag> wtags = new ArrayList<>(rows.size());
    for (Map<String, PrimitiveTypeProvider> row : rows) {
        wtags.add(new IncompleteTag(row.get("tagid").getString(), "", "", row.get("score").getFloat()));
    }
    return getSimilar(wtags, qc);
}
Also used : StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) IncompleteTag(org.vitrivr.cineast.core.data.tag.IncompleteTag) WeightedTag(org.vitrivr.cineast.core.data.tag.WeightedTag) ArrayList(java.util.ArrayList) TObjectFloatHashMap(gnu.trove.map.hash.TObjectFloatHashMap) HashMap(java.util.HashMap) Map(java.util.Map) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 3 with StringTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider in project cineast by vitrivr.

the class AverageColorRaster method getSimilar.

@Override
public List<ScoreElement> getSimilar(String segmentId, ReadableQueryConfig qc) {
    List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getRows(GENERIC_ID_COLUMN_QUALIFIER, new StringTypeProvider(segmentId));
    if (rows.isEmpty()) {
        return new ArrayList<>(1);
    }
    Map<String, PrimitiveTypeProvider> map = rows.get(0);
    return getSimilar(map.get("raster").getFloatArray(), map.get("hist").getFloatArray(), qc);
}
Also used : StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) ArrayList(java.util.ArrayList) Map(java.util.Map) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 4 with StringTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider in project cineast by vitrivr.

the class TagReader method getTagsByName.

/**
 * Returns all {@link Tag}s that are equal to the specified name.
 *
 * @param name To value with which to compare the {@link Tag}s.
 * @return List of matching {@link Tag}s.
 */
public List<Tag> getTagsByName(String name) {
    List<Map<String, PrimitiveTypeProvider>> rows = this.selector.getRows("name", new StringTypeProvider(name));
    ArrayList<Tag> _return = new ArrayList<>(rows.size());
    for (Map<String, PrimitiveTypeProvider> row : rows) {
        Tag t = fromMap(row);
        if (t != null) {
            _return.add(t);
        }
    }
    return _return;
}
Also used : StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) ArrayList(java.util.ArrayList) Tag(org.vitrivr.cineast.core.data.tag.Tag) CompleteTag(org.vitrivr.cineast.core.data.tag.CompleteTag) HashMap(java.util.HashMap) Map(java.util.Map) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)

Example 5 with StringTypeProvider

use of org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider in project cineast by vitrivr.

the class DBIntegrationTest method getFeatureVectors.

@Test
@DisplayName("get multiple feature vectors")
void getFeatureVectors() {
    this.selector.open(testVectorTableName);
    final List<PrimitiveTypeProvider> vectors = this.selector.getFeatureVectorsGeneric(ID_COL_NAME, new StringTypeProvider("0"), FEATURE_VECTOR_COL_NAME);
    Assertions.assertTrue((Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(0)), new float[] { 0, 0, 0 }) | Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(0)), new float[] { 0, 1, 0 })));
    Assertions.assertTrue((Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(1)), new float[] { 0, 0, 0 }) | Arrays.equals(PrimitiveTypeProvider.getSafeFloatArray(vectors.get(1)), new float[] { 0, 1, 0 })));
}
Also used : StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) PrimitiveTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

StringTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider)11 PrimitiveTypeProvider (org.vitrivr.cineast.core.data.providers.primitive.PrimitiveTypeProvider)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 TObjectFloatHashMap (gnu.trove.map.hash.TObjectFloatHashMap)2 QueryConfig (org.vitrivr.cineast.core.config.QueryConfig)2 ReadableQueryConfig (org.vitrivr.cineast.core.config.ReadableQueryConfig)2 SegmentScoreElement (org.vitrivr.cineast.core.data.score.SegmentScoreElement)2 Tag (org.vitrivr.cineast.core.data.tag.Tag)2 WeightedTag (org.vitrivr.cineast.core.data.tag.WeightedTag)2 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)2 RetrievalRuntimeConfig (org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 TObjectDoubleHashMap (gnu.trove.map.hash.TObjectDoubleHashMap)1 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