Search in sources :

Example 21 with Direction

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) throws EntityNotFoundException {
    int fromDegree = readOperations.nodeGetDegree(fromNode, direction);
    if (fromDegree == 0) {
        return RelationshipIterator.EMPTY;
    }
    int toDegree = readOperations.nodeGetDegree(toNode, direction.reverse());
    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);
    return connectingRelationshipsIterator(allRelationships, startNode, endNode);
}
Also used : RelationshipIterator(org.neo4j.kernel.impl.api.store.RelationshipIterator) Direction(org.neo4j.graphdb.Direction)

Example 22 with Direction

use of org.neo4j.graphdb.Direction in project neo4j-mobile-android by neo4j-contrib.

the class StandardExpander method create.

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));
}
Also used : RelationshipType(org.neo4j.graphdb.RelationshipType) Collection(java.util.Collection) Direction(org.neo4j.graphdb.Direction)

Example 23 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class Ls method wrapInLimitingIterator.

private Iterator<Relationship> wrapInLimitingIterator(AppCommandParser parser, Iterator<Relationship> iterator, Map<String, Object> filterMap, boolean caseInsensitiveFilters, boolean looseFilters) throws ShellException {
    final AtomicBoolean handBreak = new AtomicBoolean();
    int maxRelsPerType = parser.optionAsNumber("m", DEFAULT_MAX_RELS_PER_TYPE_LIMIT).intValue();
    Map<String, Direction> types = filterMapToTypes(getServer().getDb(), Direction.BOTH, filterMap, caseInsensitiveFilters, looseFilters);
    return new FilteringIterator<Relationship>(iterator, new LimitPerTypeFilter(maxRelsPerType, types, handBreak)) {

        @Override
        protected Relationship fetchNextOrNull() {
            return handBreak.get() ? null : super.fetchNextOrNull();
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FilteringIterator(org.neo4j.helpers.collection.FilteringIterator) Direction(org.neo4j.graphdb.Direction)

Example 24 with Direction

use of org.neo4j.graphdb.Direction in project neo4j by neo4j.

the class Mkrel method exec.

@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
    assertCurrentIsNode(session);
    boolean createNode = parser.options().containsKey("c");
    boolean suppliedNode = !parser.arguments().isEmpty();
    Node node = null;
    if (createNode) {
        node = getServer().getDb().createNode(parseLabels(parser));
        session.set(KEY_LAST_CREATED_NODE, "" + node.getId());
        setProperties(node, parser.options().get("np"));
    } else if (suppliedNode) {
        node = getNodeById(Long.parseLong(parser.arguments().get(0)));
    } else {
        throw new ShellException("Must either create node (-c)" + " or supply node id as the first argument");
    }
    if (parser.options().get("t") == null) {
        throw new ShellException("Must supply relationship type " + "(-t <relationship-type-name>)");
    }
    RelationshipType type = getRelationshipType(parser.options().get("t"));
    Direction direction = getDirection(parser.options().get("d"));
    NodeOrRelationship current = getCurrent(session);
    Node currentNode = current.asNode();
    Node startNode = direction == Direction.OUTGOING ? currentNode : node;
    Node endNode = direction == Direction.OUTGOING ? node : currentNode;
    Relationship relationship = startNode.createRelationshipTo(endNode, type);
    setProperties(relationship, parser.options().get("rp"));
    session.set(KEY_LAST_CREATED_RELATIONSHIP, relationship.getId());
    boolean verbose = parser.options().containsKey("v");
    if (createNode && verbose) {
        out.println("Node " + getDisplayName(getServer(), session, node, false) + " created");
    }
    if (verbose) {
        out.println("Relationship " + getDisplayName(getServer(), session, relationship, true, false) + " created");
    }
    if (parser.options().containsKey("cd")) {
        cdTo(session, node);
    }
    return Continuation.INPUT_COMPLETE;
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) ShellException(org.neo4j.shell.ShellException) Direction(org.neo4j.graphdb.Direction)

Example 25 with Direction

use of org.neo4j.graphdb.Direction in project graphdb by neo4j-attic.

the class DijkstraDirectionTest method testDijkstraDirection3.

@Test
public void testDijkstraDirection3() {
    Relationship r1 = graph.makeEdge("start", "b");
    Relationship r2 = graph.makeEdge("c", "b");
    Relationship r3 = graph.makeEdge("c", "d");
    Relationship r4 = graph.makeEdge("e", "d");
    Relationship r5 = graph.makeEdge("e", "f");
    Relationship r6 = graph.makeEdge("g", "f");
    Relationship r7 = graph.makeEdge("g", "end");
    HashMap<Relationship, Direction> dirs = new HashMap<Relationship, Direction>();
    Dijkstra<Double> dijkstra = new Dijkstra<Double>((double) 0, graph.getNode("start"), graph.getNode("end"), new directionSavingCostEvaluator(dirs), new org.neo4j.graphalgo.impl.util.DoubleAdder(), new org.neo4j.graphalgo.impl.util.DoubleComparator(), Direction.BOTH, MyRelTypes.R1);
    dijkstra.getCost();
    assertEquals(Direction.OUTGOING, dirs.get(r1));
    assertEquals(Direction.INCOMING, dirs.get(r2));
    assertEquals(Direction.OUTGOING, dirs.get(r3));
    assertEquals(Direction.INCOMING, dirs.get(r4));
    assertEquals(Direction.OUTGOING, dirs.get(r5));
    assertEquals(Direction.INCOMING, dirs.get(r6));
    assertEquals(Direction.OUTGOING, dirs.get(r7));
}
Also used : HashMap(java.util.HashMap) Direction(org.neo4j.graphdb.Direction) Dijkstra(org.neo4j.graphalgo.impl.shortestpath.Dijkstra) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

Direction (org.neo4j.graphdb.Direction)42 Relationship (org.neo4j.graphdb.Relationship)25 Test (org.junit.Test)21 RelationshipType (org.neo4j.graphdb.RelationshipType)14 Node (org.neo4j.graphdb.Node)11 EigenvectorCentrality (org.neo4j.graphalgo.impl.centrality.EigenvectorCentrality)10 HashMap (java.util.HashMap)6 Dijkstra (org.neo4j.graphalgo.impl.shortestpath.Dijkstra)6 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 DoubleAdder (org.neo4j.graphalgo.impl.util.DoubleAdder)4 DoubleComparator (org.neo4j.graphalgo.impl.util.DoubleComparator)4 EnumMap (java.util.EnumMap)3 PropertyContainer (org.neo4j.graphdb.PropertyContainer)3 NestingIterator (org.neo4j.helpers.collection.NestingIterator)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Stack (java.util.Stack)2 TreeMap (java.util.TreeMap)2