Skip to content

Commit

Permalink
Replaced potentially problematic libraries (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro authored Aug 9, 2022
1 parent 6e5ac66 commit c24a49e
Show file tree
Hide file tree
Showing 28 changed files with 167 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static org.vitrivr.cineast.core.util.CineastConstants.FEATURE_COLUMN_QUALIFIER;
import static org.vitrivr.cineast.core.util.CineastConstants.GENERIC_ID_COLUMN_QUALIFIER;

import gnu.trove.map.hash.TObjectDoubleHashMap;
import com.carrotsearch.hppc.ObjectDoubleHashMap;
import com.carrotsearch.hppc.predicates.ObjectDoublePredicate;
import com.carrotsearch.hppc.procedures.ObjectDoubleProcedure;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -34,6 +36,7 @@
import org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader;
import org.vitrivr.cineast.core.db.dao.reader.TagReader;
import org.vitrivr.cineast.core.features.SegmentTags;
import org.vitrivr.cineast.core.features.retriever.Retriever;
import org.vitrivr.cineast.core.temporal.TemporalScoring;
import org.vitrivr.cineast.core.util.math.MathHelper;
import org.vitrivr.cineast.standalone.config.Config;
Expand Down Expand Up @@ -171,7 +174,7 @@ public static HashMap<String, ArrayList<AbstractQueryTermContainer>> groupQueryT
}

public static List<StringDoublePair> retrieveCategory(ContinuousRetrievalLogic continuousRetrievalLogic, List<Pair<AbstractQueryTermContainer, ReadableQueryConfig>> queryContainers, String category) {
TObjectDoubleHashMap<String> scoreBySegmentId = new TObjectDoubleHashMap<>();
ObjectDoubleHashMap<String> scoreBySegmentId = new ObjectDoubleHashMap<>();
for (Pair<AbstractQueryTermContainer, ReadableQueryConfig> pair : queryContainers) {

if (pair == null) {
Expand All @@ -187,7 +190,7 @@ public static List<StringDoublePair> retrieveCategory(ContinuousRetrievalLogic c

}
final List<StringDoublePair> list = new ArrayList<>(scoreBySegmentId.size());
scoreBySegmentId.forEachEntry((segmentId, score) -> {
scoreBySegmentId.forEach((ObjectDoublePredicate<? super String>) (segmentId, score) -> {
if (score > 0) {
list.add(new StringDoublePair(segmentId, score));
}
Expand All @@ -207,12 +210,12 @@ public static List<StringDoublePair> retrieveCategory(ContinuousRetrievalLogic c

public static List<StringDoublePair> retrieve(ContinuousRetrievalLogic continuousRetrievalLogic, AbstractQueryTermContainer queryTermContainer, ReadableQueryConfig config, String category) {
float weight = MathHelper.limit(queryTermContainer.getWeight(), -1f, 1f);
TObjectDoubleHashMap<String> scoreBySegmentId = new TObjectDoubleHashMap<>();
ObjectDoubleHashMap<String> scoreBySegmentId = new ObjectDoubleHashMap<>();

retrieveAndWeight(continuousRetrievalLogic, category, scoreBySegmentId, queryTermContainer, config, weight);

final List<StringDoublePair> list = new ArrayList<>(scoreBySegmentId.size());
scoreBySegmentId.forEachEntry((segmentId, score) -> {
scoreBySegmentId.forEach((ObjectDoublePredicate<? super String>) (segmentId, score) -> {
if (score > 0) {
list.add(new StringDoublePair(segmentId, score));
}
Expand All @@ -222,7 +225,7 @@ public static List<StringDoublePair> retrieve(ContinuousRetrievalLogic continuou
return list;
}

private static void retrieveAndWeight(ContinuousRetrievalLogic continuousRetrievalLogic, String category, TObjectDoubleHashMap<String> scoreBySegmentId, AbstractQueryTermContainer qc, ReadableQueryConfig qconf, float weight) {
private static void retrieveAndWeight(ContinuousRetrievalLogic continuousRetrievalLogic, String category, ObjectDoubleHashMap<String> scoreBySegmentId, AbstractQueryTermContainer qc, ReadableQueryConfig qconf, float weight) {
List<SegmentScoreElement> scoreResults;
if (qc.hasId()) {
scoreResults = continuousRetrievalLogic.retrieve(qc.getId(), category, qconf);
Expand All @@ -237,7 +240,7 @@ private static void retrieveAndWeight(ContinuousRetrievalLogic continuousRetriev
continue;
}
double weightedScore = score * weight;
scoreBySegmentId.adjustOrPutValue(segmentId, weightedScore, weightedScore);
scoreBySegmentId.putOrAdd(segmentId, weightedScore, weightedScore);
}
}

Expand Down Expand Up @@ -275,13 +278,12 @@ public static List<Object> retrieveFeaturesForIDByCategory(String id, String cat
final RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
final DBSelector selector = Config.sharedConfig().getDatabase().getSelectorSupplier().get();
List<Object> _return = new ArrayList<>();
retrievalRuntimeConfig.getRetrieversByCategory(category).forEachKey(retriever -> {
retrievalRuntimeConfig.getRetrieversByCategory(category).forEach((ObjectDoubleProcedure<? super Retriever>) (retriever, weight) -> {
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 true; // Return value false would break the foreEachKey
});
return _return;
}
Expand Down Expand Up @@ -343,9 +345,8 @@ private static Map<String, ArrayList<HashMap<String, Object>>> getFeaturesForCat
final RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
Map<String, ArrayList<HashMap<String, Object>>> _return = new HashMap<>();

retrievalRuntimeConfig.getRetrieversByCategory(category).forEach(retriever -> {
retrievalRuntimeConfig.getRetrieversByCategory(category).forEach((ObjectDoubleProcedure<? super Retriever>) (retriever, weight) -> {
retriever.getTableNames().forEach(tableName -> _return.put(tableName, getFeaturesFromEntity(tableName, ids)));
return true;
});

return _return;
Expand Down
7 changes: 2 additions & 5 deletions cineast-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ dependencies {
api group: 'com.google.code.gson', name: 'gson', version: version_gson

/** Some basic stuff (collections etc). */
api group: "net.sf.trove4j", name: "trove4j", version: version_trove4j
api group: "com.google.guava", name: "guava", version: version_guava
api group: "com.googlecode.javaewah", name: "JavaEWAH", version: version_javaewah
api group: 'com.carrotsearch', name: 'hppc', version: vershion_hppc

/** Mockito for unit testing */
implementation 'org.mockito:mockito-inline:4.5.1'
implementation 'org.mockito:mockito-inline:4.6.1'

/** Tensorflow (Java). */
if (DefaultNativePlatform.currentOperatingSystem.isMacOsX())
Expand Down Expand Up @@ -144,9 +144,6 @@ dependencies {
/** OpenCV. */
api group: 'org.openpnp', name: 'opencv', version: version_opencv

/** Evaluator of math expressions (e.g. to _evaluate_ config entries in the form of 1000/3 */
implementation 'com.fathzer:javaluator:3.0.3'

/** Java 9+ compatibility. */
api group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
api group: 'javax.activation', name: 'activation', version: '1.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package org.vitrivr.cineast.core.color;

import gnu.trove.TCollections;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;

import com.carrotsearch.hppc.IntObjectHashMap;

/* for equations see http://www.easyrgb.com/ */
public final class ColorConverter {

private static TIntObjectMap<ReadableLabContainer> rgbToLabCache = TCollections
.synchronizedMap(new TIntObjectHashMap<ReadableLabContainer>(100000));
private static TIntObjectMap<ReadableHSVContainer> rgbToHSVCache = TCollections
.synchronizedMap(new TIntObjectHashMap<ReadableHSVContainer>(100000));
private static IntObjectHashMap<ReadableLabContainer> rgbToLabCache = new IntObjectHashMap<>(100000);
private static IntObjectHashMap<ReadableHSVContainer> rgbToHSVCache = new IntObjectHashMap<>(100000);

private ColorConverter() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.vitrivr.cineast.core.data;

import gnu.trove.list.array.TFloatArrayList;
import com.carrotsearch.hppc.FloatArrayList;
import java.util.List;

public class FloatVectorImpl implements FloatVector {

private TFloatArrayList list;
private final FloatArrayList list;

public FloatVectorImpl(TFloatArrayList list) {
public FloatVectorImpl(FloatArrayList list) {
this.list = list;
}

Expand All @@ -26,7 +26,7 @@ public FloatVectorImpl(float[] array) {
}

public FloatVectorImpl() {
this(new TFloatArrayList());
this(new FloatArrayList());
}

public FloatVectorImpl(List<Double> list) {
Expand Down Expand Up @@ -70,7 +70,7 @@ public void add(float element) {
}

public String toFeatureString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('<');
for (int i = 0; i < this.list.size(); ++i) {
buf.append(list.get(i));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.vitrivr.cineast.core.data;

import gnu.trove.map.hash.TObjectIntHashMap;
import com.carrotsearch.hppc.ObjectIntHashMap;
import java.util.NoSuchElementException;

public abstract class Histogram implements ReadableFloatVector {

protected double[] bins;
protected TObjectIntHashMap<String> binNames = new TObjectIntHashMap<>();
protected ObjectIntHashMap<String> binNames = new ObjectIntHashMap<>();

protected Histogram(int numberOfBins) {
this.bins = new double[numberOfBins];
Expand Down Expand Up @@ -54,7 +54,7 @@ public double getDistance(Histogram hist) {


public String toFeatureString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append('<');
for (int i = 0; i < bins.length; ++i) {
buf.append(bins[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vitrivr.cineast.core.data;

import gnu.trove.map.hash.TIntObjectHashMap;

import com.carrotsearch.hppc.IntObjectHashMap;
import java.util.EnumSet;
import java.util.HashMap;
import org.apache.commons.lang3.tuple.ImmutablePair;
Expand All @@ -16,7 +17,7 @@ public enum MediaType {
UNKNOWN(99, "u", "unknown");

public static final char DELIMITER = '_';
private static final TIntObjectHashMap<MediaType> idToType = new TIntObjectHashMap<>();
private static final IntObjectHashMap<MediaType> idToType = new IntObjectHashMap<>();
private static final HashMap<String, MediaType> prefixToType = new HashMap<>();
private static final HashMap<String, MediaType> nameToType = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vitrivr.cineast.core.data;

import gnu.trove.map.hash.TObjectDoubleHashMap;
import com.carrotsearch.hppc.ObjectDoubleHashMap;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
import org.vitrivr.cineast.core.config.CacheableQueryConfig;
Expand All @@ -13,18 +14,18 @@
*/
public record QueryResultCacheKey(int queryTermContainerHash, String querySegmentId, String retrieverSpecification, CacheableQueryConfig queryConfig) {

private QueryResultCacheKey(AbstractQueryTermContainer queryTermContainer, String querySegmentId, TObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
this(queryTermContainer == null ? 0 : queryTermContainer.hashCode(), querySegmentId, retrievers.keySet().stream().map(retriever -> {
private QueryResultCacheKey(AbstractQueryTermContainer queryTermContainer, String querySegmentId, ObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
this(queryTermContainer == null ? 0 : queryTermContainer.hashCode(), querySegmentId, Arrays.stream(retrievers.keys().toArray(Retriever.class)).map(retriever -> {
double weight = retrievers.get(retriever);
return retriever.getClass().getName() + "-" + weight + "|"; //TODO disambiguate between differently configured instances of same retriever
}).sorted().collect(Collectors.joining()), new CacheableQueryConfig(queryConfig));
}

public QueryResultCacheKey(AbstractQueryTermContainer queryTermContainer, TObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
public QueryResultCacheKey(AbstractQueryTermContainer queryTermContainer, ObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
this(queryTermContainer, null, retrievers, queryConfig);
}

public QueryResultCacheKey(String querySegmentId, TObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
public QueryResultCacheKey(String querySegmentId, ObjectDoubleHashMap<Retriever> retrievers, ReadableQueryConfig queryConfig) {
this(null, querySegmentId, retrievers, queryConfig);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.vitrivr.cineast.core.data;

import gnu.trove.map.hash.TIntObjectHashMap;
import com.carrotsearch.hppc.IntObjectHashMap;
import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.Map;
Expand All @@ -15,7 +15,7 @@ public SemanticMap(BufferedImage image, Map<String, String> classes) {
}

private static DeepLabLabel[][] toLabels(BufferedImage image, Map<String, String> classes) {
TIntObjectHashMap<DeepLabLabel> intToLabelMap = new TIntObjectHashMap<>(classes.size());
IntObjectHashMap<DeepLabLabel> intToLabelMap = new IntObjectHashMap<>(classes.size());
for (String className : classes.keySet()) {

DeepLabLabel label;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.vitrivr.cineast.core.data.score;

import com.carrotsearch.hppc.ObjectDoubleMap;
import com.carrotsearch.hppc.predicates.ObjectDoublePredicate;
import com.google.common.collect.ImmutableList;
import gnu.trove.map.TObjectDoubleMap;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
Expand All @@ -27,12 +28,12 @@ static List<ScoreElement> filterMaximumScores(Stream<ScoreElement> elements) {
}

static List<SegmentScoreElement> segmentsFromSegmentsMap(
TObjectDoubleMap<String> scoreBySegmentId) {
ObjectDoubleMap<String> scoreBySegmentId) {
return segmentsFromSegmentsDistanceMap(scoreBySegmentId, CorrespondenceFunction.identity());
}

static List<ScoreElement> scoresFromSegmentsDistanceMap(
TObjectDoubleMap<String> distanceBySegmentId, CorrespondenceFunction correspondence) {
ObjectDoubleMap<String> distanceBySegmentId, CorrespondenceFunction correspondence) {
List<SegmentScoreElement> segments = segmentsFromSegmentsDistanceMap(distanceBySegmentId,
correspondence);

Expand All @@ -41,9 +42,9 @@ static List<ScoreElement> scoresFromSegmentsDistanceMap(
}

static List<SegmentScoreElement> segmentsFromSegmentsDistanceMap(
TObjectDoubleMap<String> distanceBySegmentId, CorrespondenceFunction correspondence) {
ObjectDoubleMap<String> distanceBySegmentId, CorrespondenceFunction correspondence) {
ImmutableList.Builder<SegmentScoreElement> builder = ImmutableList.builder();
distanceBySegmentId.forEachEntry((id, score) -> {
distanceBySegmentId.forEach((ObjectDoublePredicate<? super String>) (id, score) -> {
builder.add(new SegmentScoreElement(id, correspondence.applyAsDouble(score)));
return true;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vitrivr.cineast.core.extraction.decode.m3d;

import gnu.trove.map.hash.TObjectIntHashMap;

import com.carrotsearch.hppc.ObjectIntHashMap;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -120,7 +121,7 @@ private Mesh readAscii(InputStream is) throws IOException {
Mesh mesh = new Mesh(100, 100);

/* Prepare helper structures. */
TObjectIntHashMap<Vector3f> vertexBuffer = new TObjectIntHashMap<>();
ObjectIntHashMap<Vector3f> vertexBuffer = new ObjectIntHashMap<>();
int index = 0;
int[] vertexindices = new int[3];

Expand Down Expand Up @@ -212,7 +213,7 @@ private Mesh readBinary(InputStream is, int skip) throws IOException {
Mesh mesh = new Mesh((int) triangles, (int) triangles);

/* Prepare helper structures. */
TObjectIntHashMap<Vector3f> vertexBuffer = new TObjectIntHashMap<>();
ObjectIntHashMap<Vector3f> vertexBuffer = new ObjectIntHashMap<>();
int index = 0;
int[] vertexindices = new int[3];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import static org.vitrivr.cineast.core.util.CineastConstants.FEATURE_COLUMN_QUALIFIER;

import gnu.trove.list.array.TIntArrayList;

import com.carrotsearch.hppc.IntArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -48,7 +49,7 @@ public AudioFingerprint() {

@Override
public void processSegment(SegmentContainer segment) {
TIntArrayList filteredSpectrum = this.filterSpectrum(segment);
IntArrayList filteredSpectrum = this.filterSpectrum(segment);
int vectors = filteredSpectrum.size() / FINGERPRINT;
List<PersistentTuple> tuples = new ArrayList<>();
for (int i = 0; i < vectors; i++) {
Expand Down Expand Up @@ -76,7 +77,7 @@ protected List<float[]> preprocessQuery(SegmentContainer sc, ReadableQueryConfig
List<float[]> features = new ArrayList<>();

/* Extract filtered spectrum and create query-vectors. */
final TIntArrayList filteredSpectrum = this.filterSpectrum(sc);
final IntArrayList filteredSpectrum = this.filterSpectrum(sc);
final int shift = RANGES.length - 1;
final int lookups = Math.max(1, Math.min(30, filteredSpectrum.size() - FINGERPRINT));

Expand Down Expand Up @@ -166,9 +167,9 @@ protected List<ReadableQueryConfig> generateQueryConfigsForFeatures(ReadableQuer
return configs;
}

private TIntArrayList filterSpectrum(SegmentContainer segment) {
private IntArrayList filterSpectrum(SegmentContainer segment) {
/* Prepare empty list of candidates for filtered spectrum. */
TIntArrayList candidates = new TIntArrayList();
IntArrayList candidates = new IntArrayList();

/* Perform STFT and extract the Spectra. If this fails, return empty list. */
Pair<Integer, Integer> properties = FFTUtil.parametersForDuration(segment.getSamplingrate(), WINDOW_SIZE);
Expand Down
Loading

0 comments on commit c24a49e

Please sign in to comment.