use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class EigenvectorCentralityTest method simpleTest.
@Test
public void simpleTest() {
/*
* Layout
* ___________
* v \
* (a) -> (b) -> (c) -> (d)
* ^ /
* ----
*/
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.02);
assertApproximateCentrality(eigenvectorCentrality, "a", 0.693, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "b", 0.523, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "c", 0.395, 0.02);
assertApproximateCentrality(eigenvectorCentrality, "d", 0.298, 0.02);
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class Paths method descriptorForIdAndProperties.
/**
* Create a new {@link Paths.PathDescriptor} that prints values of listed property keys
* and id of nodes and relationships if configured so.
* @param nodeId true if node id should be included.
* @param relId true if relationship id should be included.
* @param propertyKeys all property keys that should be included.
* @param <T> the type of the {@link Path}
* @return a new {@link Paths.PathDescriptor}
*/
public static <T extends Path> PathDescriptor<T> descriptorForIdAndProperties(final boolean nodeId, final boolean relId, final String... propertyKeys) {
return new Paths.PathDescriptor<T>() {
@Override
public String nodeRepresentation(T path, Node node) {
String representation = representation(node);
return "(" + (nodeId ? node.getId() : "") + (nodeId && !representation.equals("") ? "," : "") + representation + ")";
}
private String representation(PropertyContainer entity) {
StringBuilder builder = new StringBuilder();
for (String key : propertyKeys) {
Object value = entity.getProperty(key, null);
if (value != null) {
if (builder.length() > 0) {
builder.append(",");
}
builder.append(value);
}
}
return builder.toString();
}
@Override
public String relationshipRepresentation(T path, Node from, Relationship relationship) {
Direction direction = relationship.getEndNode().equals(from) ? Direction.INCOMING : Direction.OUTGOING;
StringBuilder builder = new StringBuilder();
if (direction.equals(Direction.INCOMING)) {
builder.append("<");
}
builder.append("--[" + (relId ? relationship.getId() : ""));
String representation = representation(relationship);
if (relId && !representation.equals("")) {
builder.append(",");
}
builder.append(representation);
builder.append("]--");
if (direction.equals(Direction.OUTGOING)) {
builder.append(">");
}
return builder.toString();
}
};
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class StandardExpander method temporaryTypeMapFrom.
private static Map<Direction, Collection<RelationshipType>> temporaryTypeMapFrom(Map<Direction, RelationshipType[]> typeMap) {
Map<Direction, Collection<RelationshipType>> map = new EnumMap<Direction, Collection<RelationshipType>>(Direction.class);
for (Direction direction : Direction.values()) {
ArrayList<RelationshipType> types = new ArrayList<RelationshipType>();
map.put(direction, types);
RelationshipType[] existing = typeMap.get(direction);
if (existing != null) {
types.addAll(asList(existing));
}
}
return map;
}
use of org.neo4j.graphdb.Direction in project neo4j by neo4j.
the class StandardExpander method create.
public static StandardExpander create(RelationshipType type1, Direction dir1, RelationshipType type2, Direction dir2, Object... more) {
Map<Direction, Collection<RelationshipType>> tempMap = temporaryTypeMap();
tempMap.get(dir1).add(type1);
tempMap.get(dir2).add(type2);
for (int i = 0; i < more.length; i++) {
RelationshipType type = (RelationshipType) more[i++];
Direction direction = (Direction) more[i];
tempMap.get(direction).add(type);
}
return new RegularExpander(toTypeMap(tempMap));
}
use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.
the class TestTraversal method testSanityChecks2.
@Test
public void testSanityChecks2() throws Exception {
// ------------- with traverser direction -------------
// Valid data
Node root = getGraphDb().createNode();
RelationshipType[] traversableRels = new RelationshipType[] { MyRelTypes.TEST };
Direction[] traversableDirs = new Direction[] { Direction.OUTGOING };
// Null traversable relationships
this.sanityCheckTraverser("Sanity check failed: null traversable " + "rels should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, null, traversableDirs[0], StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL);
// Null traversable directions
this.sanityCheckTraverser("Sanity check failed: null traversable " + "rels should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], null, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL);
// Null stop evaluator
this.sanityCheckTraverser("Sanity check failed: null stop eval " + "should throw an IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], traversableDirs[0], null, ReturnableEvaluator.ALL);
// Null returnable evaluator
this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], traversableDirs[0], StopEvaluator.END_OF_GRAPH, null);
// traversable relationships length not equal to traversable directions
// length
this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, traversableRels[0], null, StopEvaluator.END_OF_GRAPH, null);
this.sanityCheckTraverser("Sanity check failed: null returnable " + "evaluator should throw an " + "IllegalArgumentException", BREADTH_FIRST, root, null, traversableDirs[0], StopEvaluator.END_OF_GRAPH, null);
root.delete();
}
Aggregations