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;
}
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();
}
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]));
}
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;
}
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;
}
Aggregations