-
Notifications
You must be signed in to change notification settings - Fork 116
add Neo4j heuristics calculator #1647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andyfelder16
wants to merge
6
commits into
master
Choose a base branch
from
neo4j-heuristics-core
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
588b240
score cypher match queries against a graph with a truthness-based heu…
andyfelder16 af9a624
cleaned test file
andyfelder16 2d0e890
dispatch cypher conditions through a visitor and fix review comments
andyfelder16 f1551bc
guard neo4j mapping lookups so a null variable name can't pass as unb…
andyfelder16 659b89b
align the neo4j heuristics with evomaster review conventions
andyfelder16 85e728e
score unvaluatable cypher conditions instead of skipping them
andyfelder16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...in/java/org/evomaster/client/java/controller/neo4j/conditions/CypherConditionVisitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package org.evomaster.client.java.controller.neo4j.conditions; | ||
|
|
||
| /** | ||
| * Visitor over the typed {@link CypherCondition} boolean tree the parser produces. Each concrete | ||
| * condition dispatches to its own {@code visit} method through {@link CypherCondition#accept}, so a | ||
| * consumer handles every case explicitly and the compiler flags any implementation that forgets one | ||
| * (no {@code instanceof} chain, no silent fall-through for an unhandled condition type). | ||
| * | ||
| * @param <T> the result type each visit produces (e.g. a {@code Truthness} for the heuristics). | ||
| */ | ||
| public interface CypherConditionVisitor<T> { | ||
|
|
||
| T visitLabel(LabelCondition condition); | ||
|
|
||
| T visitAnyLabel(AnyLabelCondition condition); | ||
|
|
||
| T visitType(TypeCondition condition); | ||
|
|
||
| T visitProperty(PropertyCondition condition); | ||
|
|
||
| T visitComparison(ComparisonCondition condition); | ||
|
|
||
| T visitAnd(AndCondition condition); | ||
|
|
||
| T visitOr(OrCondition condition); | ||
|
|
||
| T visitXor(XorCondition condition); | ||
|
|
||
| T visitNot(NotCondition condition); | ||
|
|
||
| T visitRaw(RawCondition condition); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...a/controller/src/main/java/org/evomaster/client/java/controller/neo4j/data/Neo4jEdge.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package org.evomaster.client.java.controller.neo4j.data; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * An edge (relationship) of a captured Neo4j graph: a stable id, a single type, the ids of its two | ||
| * endpoint nodes (source and target), and its property map. A relationship in Neo4j is always stored | ||
| * with a direction (source → target). | ||
| */ | ||
| public class Neo4jEdge { | ||
|
|
||
| /** | ||
| * Stable identifier of this relationship, as reported by the driver ({@code elementId}). Unique | ||
| * within the captured graph, and used to tell two relationships apart when enumerating mappings. | ||
| */ | ||
| private final String id; | ||
|
|
||
| /** | ||
| * The relationship type, e.g. {@code KNOWS}. Neo4j gives a relationship exactly one type (unlike a | ||
| * node, which can carry several labels), so this is a single value and never {@code null}. | ||
| */ | ||
| private final String type; | ||
|
|
||
| /** Id of the node this relationship starts from, matching some {@link Neo4jNode#getId()}. */ | ||
| private final String sourceId; | ||
|
|
||
| /** Id of the node this relationship points to, matching some {@link Neo4jNode#getId()}. */ | ||
| private final String targetId; | ||
|
|
||
| /** | ||
| * The relationship's properties. Keys are property names as stored in Neo4j (e.g. {@code since}); | ||
| * values are the corresponding property values, already converted to plain Java types by the graph | ||
| * reader ({@code String}, {@code Long}, {@code Double}, {@code Boolean}, ...). A key that is absent | ||
| * means the property is not set, which is distinct from a key present with a {@code null} value. | ||
| */ | ||
| private final Map<String, Object> properties; | ||
|
|
||
| public Neo4jEdge(String id, String type, String sourceId, String targetId, | ||
| Map<String, Object> properties) { | ||
| this.id = Objects.requireNonNull(id, "id must not be null"); | ||
| this.type = Objects.requireNonNull(type, "type must not be null"); | ||
| this.sourceId = Objects.requireNonNull(sourceId, "sourceId must not be null"); | ||
| this.targetId = Objects.requireNonNull(targetId, "targetId must not be null"); | ||
| this.properties = properties != null ? new LinkedHashMap<>(properties) : new LinkedHashMap<>(); | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public String getSourceId() { | ||
| return sourceId; | ||
| } | ||
|
|
||
| public String getTargetId() { | ||
| return targetId; | ||
| } | ||
|
|
||
| public Map<String, Object> getProperties() { | ||
| return Collections.unmodifiableMap(properties); | ||
| } | ||
|
|
||
| /** | ||
| * Returns true when the property is present on this relationship. Distinguishes an absent property | ||
| * (the operand cannot be valuated) from a present property whose value is {@code null}. | ||
| */ | ||
| public boolean hasProperty(String key) { | ||
| return properties.containsKey(key); | ||
| } | ||
|
|
||
| /** | ||
| * The value of the given property, or {@code null} if it is absent <em>or</em> present with a | ||
| * {@code null} value. Use {@link #hasProperty(String)} to tell those two apart. | ||
| */ | ||
| public Object getProperty(String key) { | ||
| return properties.get(key); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Neo4jEdge{" + id + ", type=" + type + ", " + sourceId + "->" + targetId | ||
| + ", props=" + properties + "}"; | ||
| } | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
.../controller/src/main/java/org/evomaster/client/java/controller/neo4j/data/Neo4jGraph.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.evomaster.client.java.controller.neo4j.data; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * An in-memory snapshot of a Neo4j graph ({@code G}): the set of nodes and relationships against | ||
| * which a parsed query is scored. Built either by hand in tests or by reading the live database | ||
| * through the driver. Nodes are indexed by id so a relationship's endpoints can be resolved quickly. | ||
| */ | ||
| public class Neo4jGraph { | ||
|
|
||
| /** All nodes of the snapshot, in the order they were read. */ | ||
| private final List<Neo4jNode> nodes; | ||
|
|
||
| /** All relationships of the snapshot, in the order they were read. */ | ||
| private final List<Neo4jEdge> edges; | ||
|
|
||
| /** | ||
| * Index over {@link #nodes} for endpoint resolution. Keys are node ids ({@link Neo4jNode#getId()}); | ||
| * values are the node carrying that id. Lets a relationship's {@code sourceId}/{@code targetId} be | ||
| * resolved in constant time while enumerating mappings, instead of scanning the node list. | ||
| */ | ||
| private final Map<String, Neo4jNode> nodesById; | ||
|
|
||
| public Neo4jGraph(List<Neo4jNode> nodes, List<Neo4jEdge> edges) { | ||
| this.nodes = nodes != null ? new ArrayList<>(nodes) : new ArrayList<>(); | ||
| this.edges = edges != null ? new ArrayList<>(edges) : new ArrayList<>(); | ||
| this.nodesById = new LinkedHashMap<>(); | ||
| for (Neo4jNode n : this.nodes) { | ||
| nodesById.put(n.getId(), n); | ||
| } | ||
| } | ||
|
|
||
| public List<Neo4jNode> getNodes() { | ||
| return Collections.unmodifiableList(nodes); | ||
| } | ||
|
|
||
| public List<Neo4jEdge> getEdges() { | ||
| return Collections.unmodifiableList(edges); | ||
| } | ||
|
|
||
| public int nodeCount() { | ||
| return nodes.size(); | ||
| } | ||
|
|
||
| public Neo4jNode getNodeById(String id) { | ||
| return nodesById.get(id); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Neo4jGraph{nodes=" + nodes.size() + ", edges=" + edges.size() + "}"; | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
...a/controller/src/main/java/org/evomaster/client/java/controller/neo4j/data/Neo4jNode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package org.evomaster.client.java.controller.neo4j.data; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * A node of a captured Neo4j graph, used as the {@code G} side when computing the heuristic | ||
| * {@code H(Q, G)}. It is the in-memory counterpart of a stored node: a stable id (the driver's | ||
| * {@code elementId}), the set of labels, and the property map. | ||
| * <p> | ||
| * This is a plain data holder built either by hand (tests) or by reading the live database; it has | ||
| * no relation to {@link org.evomaster.client.java.controller.neo4j.operations.PatternNode}, which is | ||
| * the structural node of a parsed query pattern. | ||
| */ | ||
| public class Neo4jNode { | ||
|
|
||
| /** | ||
| * Stable identifier of this node, as reported by the driver ({@code elementId}). Unique within the | ||
| * captured graph, and used to tell two nodes apart when enumerating mappings. | ||
| */ | ||
| private final String id; | ||
|
|
||
| /** | ||
| * The labels attached to this node, e.g. {@code {Person, Employee}}. A node may carry zero, one or | ||
| * many labels, which is why this is a set rather than a single value. Iteration order follows the | ||
| * order the labels were read, so scoring is deterministic. | ||
| */ | ||
| private final Set<String> labels; | ||
|
|
||
| /** | ||
| * The node's properties. Keys are property names as stored in Neo4j (e.g. {@code age}); values are | ||
| * the corresponding property values, already converted to plain Java types by the graph reader | ||
| * ({@code String}, {@code Long}, {@code Double}, {@code Boolean}, ...). A key that is absent means | ||
| * the property is not set, which is distinct from a key present with a {@code null} value. | ||
| */ | ||
| private final Map<String, Object> properties; | ||
|
andyfelder16 marked this conversation as resolved.
|
||
|
|
||
| public Neo4jNode(String id, Set<String> labels, Map<String, Object> properties) { | ||
| this.id = Objects.requireNonNull(id, "id must not be null"); | ||
| this.labels = labels != null ? new LinkedHashSet<>(labels) : new LinkedHashSet<>(); | ||
| this.properties = properties != null ? new LinkedHashMap<>(properties) : new LinkedHashMap<>(); | ||
| } | ||
|
|
||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Set<String> getLabels() { | ||
| return Collections.unmodifiableSet(labels); | ||
| } | ||
|
|
||
| public Map<String, Object> getProperties() { | ||
| return Collections.unmodifiableMap(properties); | ||
| } | ||
|
|
||
| /** | ||
| * Returns true when the property is present on this node. Distinguishes an absent property | ||
| * (the operand cannot be valuated) from a present property whose value is {@code null}. | ||
| */ | ||
| public boolean hasProperty(String key) { | ||
| return properties.containsKey(key); | ||
| } | ||
|
|
||
| /** | ||
| * The value of the given property, or {@code null} if it is absent <em>or</em> present with a | ||
| * {@code null} value. Use {@link #hasProperty(String)} to tell those two apart. | ||
| */ | ||
| public Object getProperty(String key) { | ||
| return properties.get(key); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Neo4jNode{" + id + ", labels=" + labels + ", props=" + properties + "}"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.