use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class ParallelBatchImporterTest method assertDegrees.
private void assertDegrees(Node node) {
for (RelationshipType type : node.getRelationshipTypes()) {
for (Direction direction : Direction.values()) {
long degree = node.getDegree(type, direction);
long actualDegree = count(node.getRelationships(type, direction));
assertEquals(actualDegree, degree);
}
}
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class CompiledExpandUtils method connectingRelationships.
public static RelationshipIterator connectingRelationships(ReadOperations readOperations, long fromNode, Direction direction, long toNode, int[] relTypes) throws EntityNotFoundException {
int fromDegree = calculateTotalDegree(readOperations, fromNode, direction, relTypes);
if (fromDegree == 0) {
return RelationshipIterator.EMPTY;
}
int toDegree = calculateTotalDegree(readOperations, toNode, direction.reverse(), relTypes);
if (toDegree == 0) {
return RelationshipIterator.EMPTY;
}
long startNode;
long endNode;
Direction relDirection;
if (fromDegree < toDegree) {
startNode = fromNode;
endNode = toNode;
relDirection = direction;
} else {
startNode = toNode;
endNode = fromNode;
relDirection = direction.reverse();
}
RelationshipIterator allRelationships = readOperations.nodeGetRelationships(startNode, relDirection, relTypes);
return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphan.
@Test
public void shouldHandleFirstNodeBeingOrphan() {
/*
* Layout
*
* (o)
* ___________ _____
* v \v \
* (a) -> (b) -> (c) -> (d)
*/
// Degree 0
Node orphan = graph.makeNode("o");
Node a = graph.makeNode("a");
Node b = graph.makeNode("b");
Node c = graph.makeNode("c");
Node d = graph.makeNode("d");
Set<Node> nodeSet = new HashSet<>();
nodeSet.add(orphan);
nodeSet.add(a);
nodeSet.add(b);
nodeSet.add(c);
nodeSet.add(d);
Set<Relationship> relSet = new HashSet<>();
relSet.add(graph.makeEdge("a", "b"));
relSet.add(graph.makeEdge("b", "c"));
relSet.add(graph.makeEdge("c", "d"));
relSet.add(graph.makeEdge("d", "c"));
relSet.add(graph.makeEdge("c", "a"));
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {
@Override
public Double getCost(Relationship relationship, Direction direction) {
return 1d;
}
}, nodeSet, relSet, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class EigenvectorCentralityTest method shouldHandleFirstNodeBeingOrphanInRelationshipSet.
@Test
public void shouldHandleFirstNodeBeingOrphanInRelationshipSet() {
/*
* Layout
*
* (o)
* ^
* |
* x
* | ___________ _____
* |v \v \
* (a) -> (b) -> (c) -> (d)
*/
Node orphan = graph.makeNode("o");
Node a = graph.makeNode("a");
Node b = graph.makeNode("b");
Node c = graph.makeNode("c");
Node d = graph.makeNode("d");
Set<Node> nodeSet = new HashSet<>();
nodeSet.add(orphan);
nodeSet.add(a);
nodeSet.add(b);
nodeSet.add(c);
nodeSet.add(d);
Set<Relationship> relSet = new HashSet<>();
relSet.add(graph.makeEdge("a", "b"));
relSet.add(graph.makeEdge("b", "c"));
relSet.add(graph.makeEdge("c", "d"));
relSet.add(graph.makeEdge("d", "c"));
relSet.add(graph.makeEdge("c", "a"));
// Edge not included in rel set
graph.makeEdge("a", "o");
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {
@Override
public Double getCost(Relationship relationship, Direction direction) {
return 1d;
}
}, nodeSet, relSet, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "o", 0d, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "a", 0.481, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.363, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.637, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.481, 0.02);
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class EigenvectorCentralityTest method shouldHandleIsolatedCommunities.
@Test
public void shouldHandleIsolatedCommunities() {
/*
* Layout
*
* (a) -> (b)
*
* ___________ _____
* v \v \
* (c) -> (d) -> (e) -> (f)
*
*/
Set<Node> nodeSet = new HashSet<>();
nodeSet.add(graph.makeNode("a"));
nodeSet.add(graph.makeNode("b"));
nodeSet.add(graph.makeNode("c"));
nodeSet.add(graph.makeNode("d"));
nodeSet.add(graph.makeNode("e"));
nodeSet.add(graph.makeNode("f"));
Set<Relationship> relSet = new HashSet<>();
relSet.add(graph.makeEdge("a", "b"));
relSet.add(graph.makeEdge("c", "d"));
relSet.add(graph.makeEdge("d", "e"));
relSet.add(graph.makeEdge("e", "f"));
relSet.add(graph.makeEdge("e", "c"));
relSet.add(graph.makeEdge("f", "e"));
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {
@Override
public Double getCost(Relationship relationship, Direction direction) {
return 1d;
}
}, nodeSet, relSet, 0.001);
assertApproximateCentrality(eigenvectorCentrality, "a", 0d, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0d, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.48, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.36, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "e", 0.64, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "f", 0.48, 0.02);
}
Aggregations