use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class TransactionProvidingApp method toSortedExpander.
protected static PathExpander toSortedExpander(GraphDatabaseService db, Direction defaultDirection, Map<String, Object> relationshipTypes, boolean caseInsensitiveFilters, boolean looseFilters) throws ShellException {
defaultDirection = defaultDirection != null ? defaultDirection : Direction.BOTH;
Map<String, Direction> matches = filterMapToTypes(db, defaultDirection, relationshipTypes, caseInsensitiveFilters, looseFilters);
PathExpanderBuilder expander = PathExpanderBuilder.emptyOrderedByType();
for (Map.Entry<String, Direction> entry : matches.entrySet()) {
expander = expander.add(RelationshipType.withName(entry.getKey()), entry.getValue());
}
return expander.build();
}
use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class EigenvectorCentralityTest method testWeightAndDirection.
/**
* Same network as above, but with direction BOTH and weights in different
* directions are given by a map.
*/
@Test
public void testWeightAndDirection() {
graph.makeEdgeChain("a,b");
graph.makeEdgeChain("b,c");
graph.makeEdgeChain("c,d");
graph.makeEdgeChain("c,a");
final Map<String, Double> costs = new HashMap<String, Double>();
costs.put("a,b", 1.0);
costs.put("b,c", 1.0);
costs.put("c,d", 1.0);
costs.put("c,b", 0.1);
costs.put("c,a", 0.1);
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.BOTH, new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
String start = graph.getNodeId(relationship.getStartNode());
String end = graph.getNodeId(relationship.getEndNode());
if (direction == Direction.INCOMING) {
// swap
String tmp = end;
end = start;
start = tmp;
}
Double value = costs.get(start + "," + end);
if (value == null) {
return 0.0;
}
return value;
}
}, graph.getAllNodes(), graph.getAllEdges(), 0.01);
// eigenvectorCentrality.setMaxIterations( 100 );
assertApproximateCentrality(eigenvectorCentrality, "a", 0.0851, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.244, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.456, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.852, 0.01);
}
use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class EigenvectorCentralityTest method testRun.
@Test
public void testRun() {
graph.makeEdgeChain("a,b,c,d");
graph.makeEdges("b,a,c,a");
EigenvectorCentrality eigenvectorCentrality = getEigenvectorCentrality(Direction.OUTGOING, new CostEvaluator<Double>() {
public Double getCost(Relationship relationship, Direction direction) {
return 1.0;
}
}, graph.getAllNodes(), graph.getAllEdges(), 0.01);
// eigenvectorCentrality.setMaxIterations( 100 );
assertApproximateCentrality(eigenvectorCentrality, "a", 0.693, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.523, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.395, 0.01);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.298, 0.01);
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class NodeRelationshipCacheTest method shouldGetAndPutRelationshipAroundChunkEdge.
@Test
public void shouldGetAndPutRelationshipAroundChunkEdge() throws Exception {
// GIVEN
cache = new NodeRelationshipCache(NumberArrayFactory.HEAP, 10);
// WHEN
long nodeId = 1_000_000 - 1;
cache.setHighNodeId(nodeId + 1);
Direction direction = Direction.OUTGOING;
long relId = 10;
cache.getAndPutRelationship(nodeId, direction, relId, false);
// THEN
assertEquals(relId, cache.getFirstRel(nodeId, mock(GroupVisitor.class)));
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class TestRelationshipCount method ensureRightDegree.
private void ensureRightDegree(int initialSize, Collection<RelationshipCreationSpec> cspecs, Collection<RelationshipDeletionSpec> dspecs) {
Map<RelType, int[]> expectedCounts = new EnumMap<>(RelType.class);
for (RelType type : RelType.values()) {
expectedCounts.put(type, new int[3]);
}
Node me = getGraphDb().createNode();
for (int i = 0; i < initialSize; i++) {
me.createRelationshipTo(getGraphDb().createNode(), RelType.INITIAL);
}
newTransaction();
expectedCounts.get(RelType.INITIAL)[0] = initialSize;
assertCounts(me, expectedCounts);
int counter = 0;
for (RelationshipCreationSpec spec : cspecs) {
for (int i = 0; i < spec.count; i++) {
Node otherNode = null;
if (spec.dir == Direction.OUTGOING) {
otherNode = getGraphDb().createNode();
me.createRelationshipTo(otherNode, spec.type);
} else if (spec.dir == Direction.INCOMING) {
otherNode = getGraphDb().createNode();
otherNode.createRelationshipTo(me, spec.type);
} else {
me.createRelationshipTo(me, spec.type);
}
expectedCounts.get(spec.type)[spec.dir.ordinal()]++;
if (otherNode != null) {
assertEquals(1, otherNode.getDegree());
}
assertCounts(me, expectedCounts);
if (counter % 3 == 0 && counter > 0) {
newTransaction();
assertCounts(me, expectedCounts);
}
}
}
assertCounts(me, expectedCounts);
newTransaction();
assertCounts(me, expectedCounts);
// Delete one of each type/direction combination
counter = 0;
if (dspecs == null) {
for (RelType type : RelType.values()) {
if (!type.measure) {
continue;
}
for (Direction direction : Direction.values()) {
int[] counts = expectedCounts.get(type);
if (counts[direction.ordinal()] > 0) {
deleteOneRelationship(me, type, direction, 0);
counts[direction.ordinal()]--;
assertCounts(me, expectedCounts);
if (counter % 3 == 0 && counter > 0) {
newTransaction();
assertCounts(me, expectedCounts);
}
}
}
}
} else {
for (RelationshipDeletionSpec spec : dspecs) {
deleteOneRelationship(me, spec.type, spec.dir, spec.which);
expectedCounts.get(spec.type)[spec.dir.ordinal()]--;
assertCounts(me, expectedCounts);
if (counter % 3 == 0 && counter > 0) {
newTransaction();
assertCounts(me, expectedCounts);
}
}
}
assertCounts(me, expectedCounts);
newTransaction();
assertCounts(me, expectedCounts);
// Clean up
for (Relationship rel : me.getRelationships()) {
Node otherNode = rel.getOtherNode(me);
if (!otherNode.equals(me)) {
otherNode.delete();
}
rel.delete();
}
me.delete();
}
Aggregations