当前位置: 首页>>代码示例>>Java>>正文


Java GraphAlgoFactory类代码示例

本文整理汇总了Java中org.neo4j.graphalgo.GraphAlgoFactory的典型用法代码示例。如果您正苦于以下问题:Java GraphAlgoFactory类的具体用法?Java GraphAlgoFactory怎么用?Java GraphAlgoFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GraphAlgoFactory类属于org.neo4j.graphalgo包,在下文中一共展示了GraphAlgoFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: traverse

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
public void traverse() {
	if (null != graph && null != root) {
		try (Transaction tx = graph.beginTx()) {
			PathFinder<Path> finder = GraphAlgoFactory.allPaths(
					PathExpanders.forTypesAndDirections(RelTypes.CHILD_HI, Direction.OUTGOING, RelTypes.CHILD_LO, Direction.OUTGOING), 5);
			// 5 is the number of original relationships + 1
			Iterable<Path> paths = finder.findAllPaths(root, one);
			double total = 0.0;
			for (Path path : paths) {
				double current = 1.0;
				for (Relationship relationship : path.relationships()) {
					current *= (double) relationship.getProperty(PROB, 1.0);
				}
				total += current;
			}
			System.out.format("The probability is %.2f.\n", total);
			tx.success();
		}
	}
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:21,代码来源:Propoli.java

示例2: stamp

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
public void stamp() {
	if (null != graph && null != root) {
		try (Transaction tx = graph.beginTx()) {
			PathFinder<Path> finder = GraphAlgoFactory.allPaths(
					PathExpanders.forTypesAndDirections(RelTypes.CHILD_HI, Direction.OUTGOING, RelTypes.CHILD_LO, Direction.OUTGOING), 5);
			// 5 is the number of original relationships + 1
			Iterable<Path> paths = finder.findAllPaths(root, one);
			for (Path path : paths) {
				boolean first = true;
				for (Relationship relationship : path.relationships()) {
					if (first) {
						System.out.format("(%s)", relationship.getStartNode().getProperty(ID));
						first = false;
					}

					System.out.format(" --[%s,%.2f]-> ", relationship.getType().name(), relationship.getProperty(PROB, 1.0));
					System.out.format("(%s)", relationship.getEndNode().getProperty(ID));
				}
				System.out.println();
			}
			tx.success();
		}
	}
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:25,代码来源:Propoli.java

示例3: analyseDb

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
private void analyseDb() {
	Transaction tx = graphDb.beginTx();
	try {
		PathFinder<Path> finder = GraphAlgoFactory.allPaths(//
				PathExpanders.forTypeAndDirection(RelTypes.KNOWS, Direction.BOTH), -1);
		Iterable<Path> paths = finder.findAllPaths(firstNode, secondNode);
		for (Path path : paths) {
			for (Node node : path.nodes()) {
				for (String prop : node.getPropertyKeys())
					System.out.print(prop);
				System.out.print(node.toString());
			}

			for (Relationship relationship : path.relationships())
				System.out.print(relationship.toString());
		}
		tx.success();
	} finally {
		tx.finish();
	}
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:22,代码来源:Application.java

示例4: traverse

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
public double traverse() {
	if (null != root && value < 0.0) {
		try (Transaction ignore = graph.beginTx()) {
			value = 0.0;
			PathFinder<Path> finder = GraphAlgoFactory.allPaths(
					PathExpanders.forTypesAndDirections(RelType.LO_CHILD, Direction.OUTGOING, RelType.HI_CHILD, Direction.OUTGOING), max);
			Iterable<Path> paths = finder.findAllPaths(root, one);
			for (Path path : paths) {
				double current = 1.0;
				for (Relationship relationship : path.relationships()) {
					current *= (double) relationship.getProperty(PROB, 1.0);
				}
				value += current;
			}
		}
	}
	return value;
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:19,代码来源:BDD.java

示例5: stamp

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
public void stamp() {
	if (null != graph && null != root) {
		try (Transaction tx = graph.beginTx()) {

			// Traverser traverser =
			// graph.traversalDescription().relationships(RelTypes.LINKS,
			// Direction.OUTGOING)
			// .evaluator(Evaluators.excludeStartPosition()).traverse(root);
			// for (Path path : traverser) {

			PathFinder<Path> finder = GraphAlgoFactory.allPaths(//
					PathExpanders.forTypeAndDirection(RelTypes.LINKS, Direction.OUTGOING), 4); // 4
																								// is
																								// the
																								// number
																								// of
																								// nodes
																								// +
																								// 1
			Iterable<Path> paths = finder.findAllPaths(root, done);
			for (Path path : paths) {

				boolean first = true;
				for (Relationship relationship : path.relationships()) {
					if (first) {
						System.out.format("(%s)", relationship.getStartNode().getProperty(ID));
						first = false;
					}
					System.out.format(" --[%s:%d,%.2f]-> ", RelTypes.LINKS, relationship.getProperty(ID), relationship.getProperty(PROB, 1.0));
					System.out.format("(%s)", relationship.getEndNode().getProperty(ID));
				}
				System.out.println();
				// System.out.println(Paths.defaultPathToString(path));
			}
			tx.success();
		}
	}
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:39,代码来源:BiDiDi.java

示例6: correlate

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
public double correlate(Node source, Node target, RelationshipType type, Direction dir, Object... more) {
	if (null == source)
		throw new IllegalArgumentException("Illegal 'source' argument in Problem.correlate(Node, Node, RelationshipType, Direction, Object...): " + source);
	if (null == target)
		throw new IllegalArgumentException("Illegal 'target' argument in Problem.correlate(Node, Node, RelationshipType, Direction, Object...): " + target);
	if (null == type)
		throw new IllegalArgumentException("Illegal 'type' argument in Problem.correlate(Node, Node, RelationshipType, Direction, Object...): " + type);
	if (null == dir)
		throw new IllegalArgumentException("Illegal 'dir' argument in Problem.correlate(Node, Node, RelationshipType, Direction, Object...): " + dir);
	if (source.equals(target))
		return 1.0;
	try (Transaction ignore = graph.beginTx()) {
		PathExpander<Object> expander = null;
		if (null == more || 0 == more.length)
			expander = PathExpanders.forTypeAndDirection(type, dir);
		else {
			RelationshipType t = (RelationshipType) more[0];
			Direction d = (Direction) more[1];
			expander = PathExpanders.forTypesAndDirections(type, dir, t, d, Arrays.copyOfRange(more, 2, more.length));
		}
		PathFinder<Path> finder = GraphAlgoFactory.allPaths(expander, 1 + count);
		Iterable<Path> paths = finder.findAllPaths(source, target);

		Set<Relationship> relationships = new HashSet<>();
		Set<Set<Relationship>> expression = new HashSet<>();
		for (Path path : paths) {
			Set<Relationship> item = new HashSet<>();
			for (Relationship relationship : path.relationships()) {
				relationships.add(relationship);
				item.add(relationship);
			}
			expression.add(item);
		}

		BDD bdd = new BDD(expression, relationships);
		bdd.dump("bdd.gv");
		return bdd.traverse();
	}
}
 
开发者ID:stefano-bragaglia,项目名称:NeoDD,代码行数:40,代码来源:Problem.java

示例7: 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);

}
 
开发者ID:socialsensor,项目名称:graphdb-benchmarks,代码行数:10,代码来源:Neo4jGraphDatabase.java

示例8: 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;
}
 
开发者ID:toniher,项目名称:neo4j-biorelation,代码行数:45,代码来源:BioRelationFunction.java

示例9: 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;
}
 
开发者ID:toniher,项目名称:neo4j-biorelation,代码行数:53,代码来源:BioRelationFunction.java

示例10: createAffinityRelationships

import org.neo4j.graphalgo.GraphAlgoFactory; //导入依赖的package包/类
/**
 * Experimental: Create affinity relationships between patterns that are encountered together during training.
 * @param graphManager is the global graph manager for managing an optimized cache of graph data
 * @param db is the Neo4j database service
 * @param tree is the decision tree for pattern matching
 * @param patternMatchers is the set of pattern matchers produced from the decision tree
 */
private static void createAffinityRelationships(GraphManager graphManager, GraphDatabaseService db, DecisionTree<Long> tree, Map<Long, Integer> patternMatchers) {
    List<String> toFrom = new ArrayList<>();
    for (Long startId : patternMatchers.keySet()) {
        // Get or create the affinity relationship
        try(Transaction tx = db.beginTx()) {
            patternMatchers.keySet().stream().filter(endId -> startId != endId).forEach(endId -> {
                Node startNode = db.getNodeById(startId > endId ? endId : startId);
                Node endNode = db.getNodeById(startId > endId ? startId : endId);
                String key = startNode.getId() + "_" + endNode.getId();

                // If startNode matches the end node
                Pattern generalMatcher = Pattern.compile((String) startNode.getProperty("pattern"));
                Matcher regexMatcher = generalMatcher.matcher(((String) endNode.getProperty("phrase")).replaceAll("(\\{[01]\\})", "word"));

                if (!toFrom.contains(key) && !regexMatcher.find()) {
                    // Depth of the start node must be > 2
                    PathFinder<Path> depthFinder = GraphAlgoFactory.shortestPath(PathExpanders.forTypeAndDirection(withName("NEXT"), Direction.OUTGOING), 100);
                    int depth1 = IteratorUtil.count(depthFinder.findSinglePath(db.getNodeById(tree.root()), startNode).nodes().iterator());
                    int depth2 = IteratorUtil.count(depthFinder.findSinglePath(db.getNodeById(tree.root()), endNode).nodes().iterator());

                    if (depth1 > 3 && depth2 > 3 && depth2 > depth1) {
                        // Eliminate descendant
                        PathFinder<Path> finder = GraphAlgoFactory.shortestPath(PathExpanders.forTypeAndDirection(withName("NEXT"), Direction.OUTGOING), 100);
                        Path findPath = finder.findSinglePath(startNode, endNode);

                        if (findPath == null) {
                            toFrom.add(key);
                            // Get or create the affinity relationship
                            affinityRelationshipCache.getOrCreateRelationship(startNode.getId(), endNode.getId(), db, graphManager, true);
                        }
                    }
                }
            });
            tx.success();
            tx.close();
        } catch (Exception ex) {
            throw ex;
        }
    }
}
 
开发者ID:Graphify,项目名称:graphify,代码行数:48,代码来源:LearningManager.java


注:本文中的org.neo4j.graphalgo.GraphAlgoFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。