Skip to content

Commit

Permalink
Minor rename
Browse files Browse the repository at this point in the history
  • Loading branch information
IoannisPanagiotas committed Mar 8, 2024
1 parent 076d677 commit 0d8d54b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* have convinced ourselves that {@link org.neo4j.gds.similarity.knn.Knn} never presents us with such cases. So this
* data structure suffices.
*/
public final class ProvidedTargetNodeFilter implements TargetNodeFilter {
public final class ExistingTargetNodeFilter implements TargetNodeFilter {
private final TreeSet<Pair<Double, Long>> priorityQueue;
private final LongPredicate predicate;
private final int bound;
Expand All @@ -52,7 +52,7 @@ public final class ProvidedTargetNodeFilter implements TargetNodeFilter {
/**
* @param seeds Optionally seed the priority queue
*/
static ProvidedTargetNodeFilter create(
static ExistingTargetNodeFilter create(
LongPredicate targetNodePredicate,
int bound,
Optional<Set<Pair<Double, Long>>> seeds,
Expand All @@ -62,10 +62,16 @@ static ProvidedTargetNodeFilter create(

seeds.ifPresent(priorityQueue::addAll);

return new ProvidedTargetNodeFilter(priorityQueue, seeds.isPresent(), similarityCutoff, targetNodePredicate, bound);
return new ExistingTargetNodeFilter(
priorityQueue,
seeds.isPresent(),
similarityCutoff,
targetNodePredicate,
bound
);
}

ProvidedTargetNodeFilter(
ExistingTargetNodeFilter(
TreeSet<Pair<Double, Long>> priorityQueue,
boolean seeded,
double similarityCutoff,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

import static org.neo4j.gds.similarity.filteredknn.EmptyTargetNodeFilter.EMPTY_CONSUMER;

public final class ProvidedTargetNodeFiltering implements TargetNodeFiltering {
public final class ExistingTargetNodeFiltering implements TargetNodeFiltering {

private final HugeObjectArray<TargetNodeFilter> targetNodeFilters;
private final SeedingSummary seedingSummary;
Expand All @@ -50,7 +50,7 @@ public final class ProvidedTargetNodeFiltering implements TargetNodeFiltering {
* @param optionalSimilarityFunction An actual similarity function if you want seeding, empty otherwise
*/

static ProvidedTargetNodeFiltering create(
static ExistingTargetNodeFiltering create(
NodeFilter sourceNodeFilter,
long nodeCount,
int k,
Expand Down Expand Up @@ -80,7 +80,7 @@ static ProvidedTargetNodeFiltering create(
nodepairAdder.add(optionalPersonalizedSeeds.get().size());
}

TargetNodeFilter targetNodeFilter = ProvidedTargetNodeFilter.create(
TargetNodeFilter targetNodeFilter = ExistingTargetNodeFilter.create(
targetNodePredicate,
k,
optionalPersonalizedSeeds,
Expand All @@ -91,7 +91,7 @@ static ProvidedTargetNodeFiltering create(
});

var seededOptimally = (startingSeeds[k] == -1) && (optionalSimilarityFunction.isPresent()); //if there less than `k+1` targets, we optimally find solution just by seeding.
return new ProvidedTargetNodeFiltering(
return new ExistingTargetNodeFiltering(
neighbourConsumers,
new SeedingSummary(nodeCountAdder.longValue(), nodepairAdder.longValue(), seededOptimally)
);
Expand Down Expand Up @@ -162,7 +162,7 @@ private static Optional<Set<Pair<Double, Long>>> prepareNode(
}


private ProvidedTargetNodeFiltering(
private ExistingTargetNodeFiltering(
HugeObjectArray<TargetNodeFilter> targetNodeFilters,
SeedingSummary seedingSummary
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static TargetNodeFiltering create(
if (targetNodePredicate == NodeFilter.ALLOW_EVERYTHING) {
return EmptyTargetNodeFiltering.EMPTY_TARGET_FILTERING;
} else {
return ProvidedTargetNodeFiltering.create(
return ExistingTargetNodeFiltering.create(
sourceNodeFilter,
nodeCount,
k,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class TargetNodeFilterTest {
@Test
void shouldPrioritiseTargetNodes() {
var consumer = ProvidedTargetNodeFilter.create(l -> true, 3, Optional.empty(), Double.MIN_VALUE);
var consumer = ExistingTargetNodeFilter.create(l -> true, 3, Optional.empty(), Double.MIN_VALUE);

consumer.offer(23, 3.14);
consumer.offer(42, 1.61);
Expand All @@ -46,7 +46,7 @@ void shouldPrioritiseTargetNodes() {

@Test
void shouldOnlyKeepTopK() {
var consumer = ProvidedTargetNodeFilter.create(l -> true, 2, Optional.empty(), Double.MIN_VALUE);
var consumer = ExistingTargetNodeFilter.create(l -> true, 2, Optional.empty(), Double.MIN_VALUE);

consumer.offer(23, 3.14);
consumer.offer(42, 1.61);
Expand All @@ -60,7 +60,7 @@ void shouldOnlyKeepTopK() {

@Test
void shouldOnlyIncludeTargetNodes() {
var consumer = ProvidedTargetNodeFilter.create(l -> false, 3, Optional.empty(), Double.MIN_VALUE);
var consumer = ExistingTargetNodeFilter.create(l -> false, 3, Optional.empty(), Double.MIN_VALUE);

consumer.offer(23, 3.14);
consumer.offer(42, 1.61);
Expand All @@ -71,7 +71,7 @@ void shouldOnlyIncludeTargetNodes() {

@Test
void shouldIgnoreExactDuplicates() {
var consumer = ProvidedTargetNodeFilter.create(l -> true, 4, Optional.empty(), Double.MIN_VALUE);
var consumer = ExistingTargetNodeFilter.create(l -> true, 4, Optional.empty(), Double.MIN_VALUE);

consumer.offer(23, 3.14);
consumer.offer(42, 1.61);
Expand All @@ -90,7 +90,7 @@ void shouldIgnoreExactDuplicates() {
*/
@Test
void shouldAllowDuplicateElementsWithNewPriorities() {
var consumer = ProvidedTargetNodeFilter.create(l -> true, 4, Optional.empty(), Double.MIN_VALUE);
var consumer = ExistingTargetNodeFilter.create(l -> true, 4, Optional.empty(), Double.MIN_VALUE);

consumer.offer(23, 3.14);
consumer.offer(42, 1.61);
Expand All @@ -107,7 +107,7 @@ void shouldAllowDuplicateElementsWithNewPriorities() {

@Test
void shouldIgnoreLowScoringNodes() {
var targetNodeFilter = ProvidedTargetNodeFilter.create(l -> true, 3, Optional.empty(), 2);
var targetNodeFilter = ExistingTargetNodeFilter.create(l -> true, 3, Optional.empty(), 2);

targetNodeFilter.offer(23, 3.14);
targetNodeFilter.offer(42, 1.61);
Expand All @@ -128,7 +128,7 @@ void shouldNotIgnoreLowScoringNodesWhenSeeded() {
Pair.of(0.003, 384L)
);

var targetNodeFilter = ProvidedTargetNodeFilter.create(l -> true, 3, Optional.of(seeds), 2);
var targetNodeFilter = ExistingTargetNodeFilter.create(l -> true, 3, Optional.of(seeds), 2);

targetNodeFilter.offer(23, 3.14);
targetNodeFilter.offer(42, 1.61);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void shouldFilterTargetNodes() {
int kIsTwo = 2;
LongPredicate evenNodesAreTargetNodes = l -> l % 2 == 0;
double noSimilarityCutoff = Double.MIN_VALUE;
ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
NodeFilter.ALLOW_EVERYTHING,
thereIsSixNodeInThisFilter,
kIsTwo,
Expand Down Expand Up @@ -74,7 +74,7 @@ public double computeSimilarity(long n, long m) {
}
});
double noSimilarityCutoff = Double.MIN_VALUE;
ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
NodeFilter.ALLOW_EVERYTHING,
thereIsSixNodeInThisFilter,
kIsFive,
Expand Down Expand Up @@ -113,7 +113,7 @@ public double computeSimilarity(long n, long m) {
}
});
double noSimilarityCutoff = Double.MIN_VALUE;
ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
NodeFilter.ALLOW_EVERYTHING,
thereIsSixNodeInThisFilter,
kIsFive,
Expand All @@ -135,7 +135,7 @@ void shouldRestrictToSourceFilteredNodes() {
int kIsTwo = 2;
LongPredicate evenNodesAreTargetNodes = l -> l % 2 == 0;
double noSimilarityCutoff = Double.MIN_VALUE;
ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
l -> l > 0,
thereIsSixNodeInThisFilter,
kIsTwo,
Expand All @@ -148,7 +148,7 @@ void shouldRestrictToSourceFilteredNodes() {
var targetNodeFilterZero = targetNodeFiltering.get(0);
var targetNodeFilterOne = targetNodeFiltering.get(1);
assertThat(targetNodeFilterZero).isInstanceOf(EmptyTargetNodeFilter.class);
assertThat(targetNodeFilterOne).isInstanceOf(ProvidedTargetNodeFilter.class);
assertThat(targetNodeFilterOne).isInstanceOf(ExistingTargetNodeFilter.class);

}

Expand All @@ -166,7 +166,7 @@ public double computeSimilarity(long n, long m) {
}
});

ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
NodeFilter.ALLOW_EVERYTHING,
gazillionNodes,
gazillionK,
Expand Down Expand Up @@ -194,7 +194,7 @@ public double computeSimilarity(long n, long m) {
}
});

ProvidedTargetNodeFiltering targetNodeFiltering = ProvidedTargetNodeFiltering.create(
ExistingTargetNodeFiltering targetNodeFiltering = ExistingTargetNodeFiltering.create(
NodeFilter.ALLOW_EVERYTHING,
gazillionNodes,
gazillionK,
Expand Down

0 comments on commit 0d8d54b

Please sign in to comment.