Java Code Examples for org.neo4j.graphdb.Direction#INCOMING

The following examples show how to use org.neo4j.graphdb.Direction#INCOMING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4jUtil.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isConnected(final Node source, final Node target, final RelationshipType relationshipType) {
	final int sourceDegree = source.getDegree(relationshipType, Direction.OUTGOING);
	final int targetDegree = target.getDegree(relationshipType, Direction.INCOMING);
	
	final Direction searchDirection;
	final Node searchSource;
	final Node searchTarget;
	if (sourceDegree <= targetDegree) {
		searchDirection = Direction.OUTGOING;
		searchSource = source;
		searchTarget = target;
	} else {
		searchDirection = Direction.INCOMING;
		searchSource = target;
		searchTarget = source;
	}
	
	final Iterator<Relationship> edges = searchSource.getRelationships(searchDirection, relationshipType).iterator();
	while (edges.hasNext()) {
		final Relationship edge = edges.next();
		final Node otherNode = edge.getOtherNode(searchSource);
		if (searchTarget.equals(otherNode)) {
			return true;
		}
	}

	return false;
}
 
Example 2
Source File: DegreeCentralityTest.java    From graph_processing with MIT License 5 votes vote down vote up
@Test
public void shouldCalculateInDegreeCentralityArrayStorageSPI() throws IOException {
    DegreeArrayStorageParallelSPI inDegree = new DegreeArrayStorageParallelSPI(db, pool, Direction.INCOMING);
    inDegree.compute("Movie", "ACTED_IN", 1);
    long id = (long) getMovieEntry("The Matrix", db).get("id");
    assertTrue("InDegree Centrality calculted incorrectly", 5 == inDegree.getResult(id));
}
 
Example 3
Source File: ReachabilityEvaluator.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Evaluation evaluate(Path path) {
  long currentId = path.endNode().getId();
  if (!nodePredicate.apply(path.endNode())) {
    inMemoryIndex.get(currentId);
    return Evaluation.EXCLUDE_AND_PRUNE;
  }

  long startId = path.startNode().getId(); // Vi
  InOutList listPair = inMemoryIndex.get(currentId);

  if (0 == path.length()) {
    // first node in the traverse - add itself to the in-out list
    listPair.getInList().add(currentId);
    listPair.getOutList().add(currentId);
    return Evaluation.INCLUDE_AND_CONTINUE;
  }
  else if (direction == Direction.INCOMING ) {
    // doing reverse BFS
    if (nodesAreConnected(currentId, startId)) {
      return Evaluation.EXCLUDE_AND_PRUNE;
    } else {
      listPair.getOutList().add(startId);
      return Evaluation.INCLUDE_AND_CONTINUE;
    }
  } else {
    //doing BFS
    if (nodesAreConnected(startId, currentId)) { // cur is w
      return Evaluation.EXCLUDE_AND_PRUNE;
    } else {
      listPair.getInList().add(startId);
      return Evaluation.INCLUDE_AND_CONTINUE;
    }
  }
}
 
Example 4
Source File: StronglyConnectedComponents.java    From Neo4jSNA with Apache License 2.0 4 votes vote down vote up
public StronglyConnectedComponents() {
	super();
	this.direction = Direction.INCOMING;
}