Java Code Examples for org.neo4j.graphdb.Node#getDegree()
The following examples show how to use
org.neo4j.graphdb.Node#getDegree() .
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 |
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: PageRank.java From Neo4jSNA with Apache License 2.0 | 5 votes |
@Override public void apply(Node node) { double secondMember = 0.0; for( Relationship rin : node.getRelationships() ) { Node neigh = rin.getOtherNode(node); double neighRank = (double) neigh.getProperty(attName); secondMember += neighRank / neigh.getDegree(); } secondMember *= this.dampingFactor; node.setProperty(attName, firstMember + secondMember); }
Example 3
Source File: DirectedModularity.java From Neo4jSNA with Apache License 2.0 | 4 votes |
@Override public void compute(Node n) { double degree = n.getDegree(Direction.INCOMING) * n.getDegree(Direction.OUTGOING); ai += degree; }