org.neo4j.graphdb.traversal.TraversalDescription Java Examples
The following examples show how to use
org.neo4j.graphdb.traversal.TraversalDescription.
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: DecisionTreeTraverser.java From decision_trees_with_rules with MIT License | 5 votes |
private Stream<PathResult> decisionPath(Node tree, Map<String, String> facts) { TraversalDescription myTraversal = db.traversalDescription() .depthFirst() .expand(new DecisionTreeExpander(facts)) .evaluator(decisionTreeEvaluator); return myTraversal.traverse(tree).stream().map(PathResult::new); }
Example #2
Source File: DecisionTreeTraverser.java From decision_trees_with_rules with MIT License | 5 votes |
private Stream<PathResult> decisionPathTwo(Node tree, Map<String, String> facts) { TraversalDescription myTraversal = db.traversalDescription() .depthFirst() .expand(new DecisionTreeExpanderTwo(facts, log)) .evaluator(decisionTreeEvaluator); return myTraversal.traverse(tree).stream().map(PathResult::new); }
Example #3
Source File: AtlasTraversals.java From atlas with GNU General Public License v3.0 | 5 votes |
public TraversalDescription getWayTraversalDescriptionIncludingWayStartNode(GraphDatabaseService db, Node wayStart) { return db.traversalDescription() .depthFirst() //.evaluator(Evaluators.lastRelationshipTypeIs(Evaluation.INCLUDE_AND_PRUNE, Evaluation.EXCLUDE_AND_PRUNE, RelationshipType.withName(Constants.NEXT_WAY_NODE))) .expand( PathExpanderBuilder.allTypesAndDirections() .addRelationshipFilter(relationship -> relationship.hasProperty(Constants.RELATIONSHIP_WAY_PROPERTY)) .addRelationshipFilter(relationship -> { return ((Long)relationship.getProperty(Constants.RELATIONSHIP_WAY_PROPERTY)).equals( (Long)wayStart.getProperty(Constants.CURRENT_ID_STRING) ); }) .build() ); }
Example #4
Source File: GraphApi.java From SciGraph with Apache License 2.0 | 5 votes |
/*** * @param parent * @param relationship * @param traverseEquivalentEdges * @return the entailment */ public Collection<Node> getEntailment(Node parent, DirectedRelationshipType relationship, boolean traverseEquivalentEdges) { Set<Node> entailment = new HashSet<>(); TraversalDescription description = graphDb.traversalDescription().depthFirst() .relationships(relationship.getType(), relationship.getDirection()) .evaluator(Evaluators.fromDepth(0)).evaluator(Evaluators.all()); if (traverseEquivalentEdges) { description = description.relationships(OwlRelationships.OWL_EQUIVALENT_CLASS); } for (Path path : description.traverse(parent)) { entailment.add(path.endNode()); } return entailment; }
Example #5
Source File: AtlasTraversals.java From atlas with GNU General Public License v3.0 | 4 votes |
public TraversalDescription getWayTraversalDescriptionExcludingWayStartNode(GraphDatabaseService db, Node wayStart) { return getWayTraversalDescriptionIncludingWayStartNode(db,wayStart).evaluator(Evaluators.excludeStartPosition()); }
Example #6
Source File: Clique.java From SciGraph with Apache License 2.0 | 4 votes |
@Override public void run() { logger.info("Starting clique merge"); Transaction tx = graphDb.beginTx(); ResourceIterable<Node> allNodes = graphDb.getAllNodes(); int size = Iterators.size(allNodes.iterator()); tx.success(); tx.close(); logger.info(size + " nodes left to process"); tx = graphDb.beginTx(); TraversalDescription traversalDescription = graphDb.traversalDescription().breadthFirst().uniqueness(Uniqueness.NODE_GLOBAL); for (RelationshipType rel : relationships) { traversalDescription = traversalDescription.relationships(rel, Direction.BOTH); } Set<Long> processedNodes = new HashSet<Long>(); for (Node baseNode : allNodes) { size -= 1; if (size % 100000 == 0) { logger.info(size + " nodes left to process"); } if (size % batchCommitSize == 0) { logger.fine("Node batch commit"); tx.success(); tx.close(); tx = graphDb.beginTx(); } logger.fine("Processing Node - " + baseNode.getProperty(NodeProperties.IRI)); if (!processedNodes.contains(baseNode.getId())) { // Keep a list of equivalentNodes List<Node> clique = new ArrayList<Node>(); for (Node node : traversalDescription.traverse(baseNode).nodes()) { logger.fine("-- " + node.getProperty(NodeProperties.IRI)); clique.add(node); processedNodes.add(node.getId()); } logger.fine("clique size: " + clique.size()); if (clique.size() == 1) { Node defactoLeader = clique.get(0); markAsCliqueLeader(defactoLeader); } else { Node leader = electCliqueLeader(clique, prefixLeaderPriority); markAsCliqueLeader(leader); clique.remove(leader); // keep only the peasants moveEdgesToLeader(leader, clique, tx); ensureLabel(leader, clique); } } } tx.success(); tx.close(); }
Example #7
Source File: ReachabilityIndex.java From SciGraph with Apache License 2.0 | 4 votes |
/** * Create a reachability index on a graph. * * @throws InterruptedException */ public void createIndex(Predicate<Node> nodePredicate) throws InterruptedException { if (indexExists()) { throw new IllegalStateException( "Reachability index already exists. Drop it first and then recreate it."); } long startTime = System.currentTimeMillis(); Set<Entry<Long, Integer>> hopCoverages = getHopCoverages(nodePredicate); logger.info(format("Calculated hop coverage in %d second(s)", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime))); InMemoryReachabilityIndex inMemoryIndex = new InMemoryReachabilityIndex(); TraversalDescription incomingTraversal = graphDb.traversalDescription().breadthFirst() .uniqueness(Uniqueness.NODE_GLOBAL).expand(new DirectionalPathExpander(Direction.INCOMING)) .evaluator(new ReachabilityEvaluator(inMemoryIndex, Direction.INCOMING, nodePredicate)); TraversalDescription outgoingTraversal = graphDb.traversalDescription().breadthFirst() .uniqueness(Uniqueness.NODE_GLOBAL).expand(new DirectionalPathExpander(Direction.OUTGOING)) .evaluator(new ReachabilityEvaluator(inMemoryIndex, Direction.OUTGOING, nodePredicate)); startTime = System.currentTimeMillis(); try (Transaction tx = graphDb.beginTx()) { for (Entry<Long, Integer> coverage : hopCoverages) { Node workingNode = graphDb.getNodeById(coverage.getKey()); if (coverage.getValue() < 0) { inMemoryIndex.put(coverage.getKey(), new InOutList()); } else { InOutListTraverser incomingListTaverser = new InOutListTraverser(incomingTraversal, workingNode); incomingListTaverser.start(); InOutListTraverser outgoingListTaverser = new InOutListTraverser(outgoingTraversal, workingNode); outgoingListTaverser.start(); incomingListTaverser.join(); outgoingListTaverser.join(); } } tx.success(); } logger.info("Built an InMemoryReachability index in " + ((System.currentTimeMillis() - startTime) / 1000) + " sec(s)."); commitIndexToGraph(inMemoryIndex); logger.info("Reachability index created."); }
Example #8
Source File: ReachabilityIndex.java From SciGraph with Apache License 2.0 | 4 votes |
InOutListTraverser(TraversalDescription td, Node startNode) { checkNotNull(startNode, "startNode must not be null."); this.traversalDescription = td; this.startNode = startNode; }