本文整理汇总了Java中org.neo4j.graphalgo.GraphAlgoFactory.shortestPath方法的典型用法代码示例。如果您正苦于以下问题:Java GraphAlgoFactory.shortestPath方法的具体用法?Java GraphAlgoFactory.shortestPath怎么用?Java GraphAlgoFactory.shortestPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.graphalgo.GraphAlgoFactory
的用法示例。
在下文中一共展示了GraphAlgoFactory.shortestPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shortestPath
import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
@Override
public void shortestPath(Node n1, Integer i)
{
PathFinder<Path> finder
= GraphAlgoFactory.shortestPath(Traversal.expanderForTypes(Neo4jGraphDatabase.RelTypes.SIMILAR), 5);
Node n2 = getVertex(i);
Path path = finder.findSinglePath(n1, n2);
}
示例2: shortestDistance
import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
public Integer shortestDistance( Node source, Node target, Integer depth, String type, String direction ) {
PathFinder<org.neo4j.graphdb.Path> finder;
if ( type.equals("go") ) {
// The relationships we will follow
RelationshipType isa = DynamicRelationshipType.withName( "is_a" );
RelationshipType partof = DynamicRelationshipType.withName( "part_of" );
if ( direction.equals( "direction" ) ) {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.OUTGOING, partof, Direction.OUTGOING ), depth );
} else {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.BOTH, partof, Direction.BOTH ), depth );
}
} else {
// The relationships we will follow
RelationshipType parent = DynamicRelationshipType.withName( "has_parent" );
if ( direction.equals( "direction" ) ) {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection( parent, Direction.OUTGOING ), depth );
} else {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forType( parent ), depth );
}
}
Iterable<org.neo4j.graphdb.Path> ListPaths = finder.findAllPaths( source, target );
Iterator<org.neo4j.graphdb.Path> itr = ListPaths.iterator();
while ( itr.hasNext() ) {
Integer hoplength = itr.next().length();
if ( hoplength < depth ) {
depth = hoplength;
}
}
return depth;
}
示例3: shortestPathNodes
import org.neo4j.graphalgo.GraphAlgoFactory; //导入方法依赖的package包/类
public ArrayList<Long> shortestPathNodes( Node source, Node target, Integer depth, String type, String direction ) {
ArrayList<Long> pathNodes = new ArrayList<Long>();
PathFinder<org.neo4j.graphdb.Path> finder;
BioRelationHelper helper = new BioRelationHelper();
if ( type.equals("go") ) {
// The relationships we will follow
RelationshipType isa = DynamicRelationshipType.withName( "is_a" );
RelationshipType partof = DynamicRelationshipType.withName( "part_of" );
if ( direction.equals( "direction" ) ) {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.OUTGOING, partof, Direction.OUTGOING ), depth );
} else {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypesAndDirections( isa, Direction.BOTH, partof, Direction.BOTH ), depth );
}
} else {
// The relationships we will follow
RelationshipType parent = DynamicRelationshipType.withName( "has_parent" );
if ( direction.equals( "direction" ) ) {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forTypeAndDirection( parent, Direction.OUTGOING ), depth );
} else {
finder = GraphAlgoFactory.shortestPath( PathExpanders.forType( parent ), depth );
}
}
Iterable<org.neo4j.graphdb.Path> ListPaths = finder.findAllPaths( source, target );
Iterator<org.neo4j.graphdb.Path> itr = ListPaths.iterator();
while ( itr.hasNext() ) {
org.neo4j.graphdb.Path nodePath = itr.next();
Integer hoplength = nodePath.length();
if ( hoplength < depth ) {
depth = hoplength;
pathNodes.clear(); // Clear arrayList
Iterable<Node> ListNodes = nodePath.nodes();
pathNodes = helper.nodes2Array( ListNodes );
}
}
return pathNodes;
}