Skip to content

Commit 0e6d448

Browse files
Improve checking of invalid config keys for hashgnn
Co-Authored-By: Florentin Dörre <florentin.dorre@neotechnology.com>
1 parent 7f6a290 commit 0e6d448

File tree

6 files changed

+41
-90
lines changed

6 files changed

+41
-90
lines changed

algo/src/main/java/org/neo4j/gds/embeddings/hashgnn/HashGNNConfig.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ static Optional<BinarizeFeaturesConfig> parseBinarizationConfig(Object o) {
7777
if (o instanceof Optional) {
7878
return (Optional<BinarizeFeaturesConfig>) o;
7979
}
80-
return Optional.of(new BinarizeFeaturesConfigImpl(CypherMapWrapper.create((Map<String, Object>) o)));
80+
var cypherMapWrapper = CypherMapWrapper.create((Map<String, Object>) o);
81+
var binarizeFeaturesConfig = new BinarizeFeaturesConfigImpl(cypherMapWrapper);
82+
cypherMapWrapper.requireOnlyKeysFrom(binarizeFeaturesConfig.configKeys());
83+
return Optional.of(binarizeFeaturesConfig);
8184
}
8285

8386
static Map<String, Object> toMapBinarizationConfig(BinarizeFeaturesConfig config) {
@@ -88,25 +91,14 @@ static Optional<GenerateFeaturesConfig> parseGenerateFeaturesConfig(Object o) {
8891
if (o instanceof Optional) {
8992
return (Optional<GenerateFeaturesConfig>) o;
9093
}
91-
return Optional.of(new GenerateFeaturesConfigImpl(CypherMapWrapper.create((Map<String, Object>) o)));
94+
var cypherMapWrapper = CypherMapWrapper.create((Map<String, Object>) o);
95+
var generateFeaturesConfig = new GenerateFeaturesConfigImpl(cypherMapWrapper);
96+
cypherMapWrapper.requireOnlyKeysFrom(generateFeaturesConfig.configKeys());
97+
return Optional.of(generateFeaturesConfig);
9298
}
9399

94100
static Map<String, Object> toMapGenerateFeaturesConfig(GenerateFeaturesConfig config) {
95101
return config.toMap();
96102
}
97103

98-
static void checkConfigKeys(CypherMapWrapper config) {
99-
if (config.containsKey("binarizeFeatures")) {
100-
var binarizeFeaturesMap = config.getMap("binarizeFeatures");
101-
var cypherMapWrapper = CypherMapWrapper.create(binarizeFeaturesMap);
102-
var binarizeFeaturesConfig = new BinarizeFeaturesConfigImpl(cypherMapWrapper);
103-
cypherMapWrapper.requireOnlyKeysFrom(binarizeFeaturesConfig.configKeys());
104-
}
105-
if (config.containsKey("generateFeatures")) {
106-
var generateFeaturesMap = config.getMap("generateFeatures");
107-
var cypherMapWrapper = CypherMapWrapper.create(generateFeaturesMap);
108-
var generateFeaturesConfig = new GenerateFeaturesConfigImpl(cypherMapWrapper);
109-
cypherMapWrapper.requireOnlyKeysFrom(generateFeaturesConfig.configKeys());
110-
}
111-
}
112104
}

algo/src/main/java/org/neo4j/gds/embeddings/hashgnn/HashGNNMutateConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
public interface HashGNNMutateConfig extends HashGNNConfig, MutatePropertyConfig {
2828

2929
static HashGNNMutateConfig of(CypherMapWrapper config) {
30-
HashGNNConfig.checkConfigKeys(config);
3130
return new HashGNNMutateConfigImpl(config);
3231
}
3332

algo/src/main/java/org/neo4j/gds/embeddings/hashgnn/HashGNNStreamConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
public interface HashGNNStreamConfig extends HashGNNConfig {
2727

2828
static HashGNNStreamConfig of(CypherMapWrapper config) {
29-
HashGNNConfig.checkConfigKeys(config);
3029
return new HashGNNStreamConfigImpl(config);
3130
}
3231
}

algo/src/test/java/org/neo4j/gds/embeddings/hashgnn/HashGNNConfigTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.neo4j.gds.embeddings.hashgnn;
2121

2222
import org.junit.jupiter.api.Test;
23+
import org.neo4j.gds.core.CypherMapWrapper;
2324

2425
import java.util.List;
2526
import java.util.Map;
@@ -75,4 +76,36 @@ void requiresDensityLevelAtMostDensity() {
7576
.build();
7677
}).hasMessage("Generate features requires `densityLevel` to be at most `dimension` but was 5 > 4.");
7778
}
79+
80+
@Test
81+
void failsOnInvalidBinarizationKeys() {
82+
assertThatThrownBy(() -> {
83+
new HashGNNConfigImpl(CypherMapWrapper.create(
84+
Map.of(
85+
"mutateProperty", "foo",
86+
"featureProperties", List.of("x"),
87+
"binarizeFeatures", Map.of("dimension", 100, "treshold", 2.0),
88+
"embeddingDensity", 4,
89+
"iterations", 100
90+
)
91+
));
92+
93+
}).isInstanceOf(IllegalArgumentException.class)
94+
.hasMessage("Unexpected configuration key: treshold (Did you mean [threshold]?)");
95+
}
96+
97+
@Test
98+
void failsOnInvalidGenerateFeaturesKeys() {
99+
assertThatThrownBy(() -> {
100+
new HashGNNConfigImpl(CypherMapWrapper.create(
101+
Map.of(
102+
"generateFeatures", Map.of("dimension", 100, "densityElfen", 2),
103+
"embeddingDensity", 4,
104+
"iterations", 100
105+
)
106+
));
107+
108+
}).isInstanceOf(IllegalArgumentException.class)
109+
.hasMessage("No value specified for the mandatory configuration parameter `densityLevel` (a similar parameter exists: [densityElfen])");
110+
}
78111
}

proc/embeddings/src/test/java/org/neo4j/gds/embeddings/hashgnn/HashGNNMutateProcTest.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@
1919
*/
2020
package org.neo4j.gds.embeddings.hashgnn;
2121

22-
import org.junit.jupiter.api.Test;
2322
import org.neo4j.gds.AlgoBaseProc;
2423
import org.neo4j.gds.MutateNodePropertyTest;
2524
import org.neo4j.gds.api.nodeproperties.ValueType;
2625
import org.neo4j.gds.core.CypherMapWrapper;
2726

28-
import java.util.List;
29-
import java.util.Map;
30-
31-
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
32-
3327
class HashGNNMutateProcTest extends HashGNNProcTest<HashGNNMutateConfig> implements
3428
MutateNodePropertyTest<HashGNN, HashGNNMutateConfig, HashGNN.HashGNNResult> {
3529

@@ -72,36 +66,4 @@ public String expectedMutatedGraph() {
7266
", (b)-[:R1]->(a)" +
7367
", (b)-[:R2]->(c)";
7468
}
75-
76-
@Test
77-
void failsOnInvalidBinarizationKeys() {
78-
assertThatThrownBy(() -> {
79-
HashGNNMutateConfig.of(CypherMapWrapper.create(
80-
Map.of(
81-
"mutateProperty", "foo",
82-
"featureProperties", List.of("x"),
83-
"binarizeFeatures", Map.of("dimension", 100, "treshold", 2.0),
84-
"embeddingDensity", 4,
85-
"iterations", 100
86-
)
87-
));
88-
89-
}).isInstanceOf(IllegalArgumentException.class)
90-
.hasMessage("Unexpected configuration key: treshold (Did you mean [threshold]?)");
91-
}
92-
93-
@Test
94-
void failsOnInvalidGenerateFeaturesKeys() {
95-
assertThatThrownBy(() -> {
96-
HashGNNMutateConfig.of(CypherMapWrapper.create(
97-
Map.of(
98-
"generateFeatures", Map.of("dimension", 100, "densityElfen", 2),
99-
"embeddingDensity", 4,
100-
"iterations", 100
101-
)
102-
));
103-
104-
}).isInstanceOf(IllegalArgumentException.class)
105-
.hasMessage("No value specified for the mandatory configuration parameter `densityLevel` (a similar parameter exists: [densityElfen])");
106-
}
10769
}

proc/embeddings/src/test/java/org/neo4j/gds/embeddings/hashgnn/HashGNNStreamProcTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
import org.neo4j.gds.core.CypherMapWrapper;
2626

2727
import java.util.List;
28-
import java.util.Map;
2928

3029
import static org.assertj.core.api.Assertions.assertThat;
31-
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
3230

3331
@SuppressWarnings("unchecked")
3432
class HashGNNStreamProcTest extends HashGNNProcTest<HashGNNStreamConfig> {
@@ -70,37 +68,5 @@ void shouldComputeNonZeroEmbeddings() {
7068
.hasSize(3)
7169
.anyMatch(value -> value != 0.0);
7270
});
73-
74-
}
75-
76-
@Test
77-
void failsOnInvalidBinarizationKeys() {
78-
assertThatThrownBy(() -> {
79-
HashGNNStreamConfig.of(CypherMapWrapper.create(
80-
Map.of(
81-
"featureProperties", List.of("x"),
82-
"binarizeFeatures", Map.of("dimension", 100, "treshold", 2.0),
83-
"embeddingDensity", 4,
84-
"iterations", 100
85-
)
86-
));
87-
88-
}).isInstanceOf(IllegalArgumentException.class)
89-
.hasMessage("Unexpected configuration key: treshold (Did you mean [threshold]?)");
90-
}
91-
92-
@Test
93-
void failsOnInvalidGenerateFeaturesKeys() {
94-
assertThatThrownBy(() -> {
95-
HashGNNStreamConfig.of(CypherMapWrapper.create(
96-
Map.of(
97-
"generateFeatures", Map.of("dimension", 100, "densityElfen", 2),
98-
"embeddingDensity", 4,
99-
"iterations", 100
100-
)
101-
));
102-
103-
}).isInstanceOf(IllegalArgumentException.class)
104-
.hasMessage("No value specified for the mandatory configuration parameter `densityLevel` (a similar parameter exists: [densityElfen])");
10571
}
10672
}

0 commit comments

Comments
 (0)