private Traverser getPatternMatch(Node startNode, final List<String> patterns, final List<NodeLabel> nodeLabels, final List<LinkLabel> linkLabels) { TraversalDescription td = database.traversalDescription() .depthFirst() .evaluator( new Evaluator() { public Evaluation evaluate( final org.neo4j.graphdb.Path path ) { if ( path.length() == 0 ) { return Evaluation.EXCLUDE_AND_CONTINUE; } boolean isToken = path.endNode().hasLabel(NodeLabel.WordToken); boolean included = isToken && (path.length() == 1 || nodeHasAnnotation(path.endNode(), linkLabels.get(path.length() - 1), patterns.get(path.length() - 1))); boolean continued = path.length() < patterns.size(); return Evaluation.of( included, continued ); } } ) .relationships(LinkLabel.NEXT, Direction.OUTGOING) .relationships(LinkLabel.HAS_TYPE, Direction.INCOMING) .relationships(LinkLabel.HAS_LEMMA, Direction.INCOMING) .relationships(LinkLabel.HAS_POS_TAG, Direction.INCOMING) .relationships(LinkLabel.HAS_HEAD, Direction.INCOMING); return td.traverse(startNode); }
/** * Evaluates a node and determines whether to include and / or continue. * Continues on and returns exactly those nodes that: * <ul> * <li>haven't been visited yet and</li> * <li>are the start node * <ul> * <li>have a sequence < threshold (and thus belong to the same cluster)</li> * </ul> * </ul> */ @Override public Evaluation evaluate(Path path) { Node end = path.endNode(); int score = is.compute(new Neo4jScoreContainer(end)); end.setProperty(SequenceProperties.INTERESTINGNESS.name(), score); String id = (String) end.getProperty(ID.name()); if (!visited.contains(id) && (path.startNode().getId() == path.endNode().getId() || score < threshold)) { visited.add(id); return Evaluation.INCLUDE_AND_CONTINUE; } return Evaluation.EXCLUDE_AND_PRUNE; }
public Evaluation evaluate( Path position ) { boolean includes = true; boolean continues = true; for ( Evaluator evaluator : this.evaluators ) { Evaluation bla = evaluator.evaluate( position ); if ( !bla.includes() ) { includes = false; } if ( !bla.continues() ) { continues = false; } if ( !continues && !includes ) { return Evaluation.EXCLUDE_AND_PRUNE; } } return Evaluation.of( includes, continues ); }
@Override public Evaluation evaluate(Path path, BranchState branchState) { if (path.endNode().hasLabel(stopLabel)) { return Evaluation.EXCLUDE_AND_PRUNE; } else { return Evaluation.INCLUDE_AND_CONTINUE; } }
@Override public Evaluation evaluate(Path path, BranchState<Double> branchState) { // Path with just the single node, ignore it and continue if (path.length() == 0 ) { return Evaluation.INCLUDE_AND_CONTINUE; } // Make sure last Equipment voltage is equal to or lower than previous voltage Double voltage = (Double) path.endNode().getProperty("voltage", 999.0); if (voltage <= branchState.getState()) { return Evaluation.INCLUDE_AND_CONTINUE; } else { return Evaluation.EXCLUDE_AND_PRUNE; } }
@Override public Evaluation evaluate(Path path) { Node lastNode = path.endNode(); if (!lastNode.hasLabel(Labels.AirportDay)){ return Evaluation.EXCLUDE_AND_CONTINUE; } else if (destinations.contains( ((String)lastNode.getProperty("key")).substring(0,3) )) { return Evaluation.INCLUDE_AND_PRUNE; } return Evaluation.EXCLUDE_AND_CONTINUE; }
@Override public Evaluation evaluate(Path path) { if (path.length() < length) { return Evaluation.EXCLUDE_AND_CONTINUE; } Node lastNode = path.endNode(); if (!lastNode.hasLabel(Labels.AirportDay)){ return Evaluation.EXCLUDE_AND_CONTINUE; } else if (destinations.contains( ((String)lastNode.getProperty("key")).substring(0,3) )) { return Evaluation.INCLUDE_AND_PRUNE; } return Evaluation.EXCLUDE_AND_PRUNE; }
@Override public Evaluation evaluate(Path path) { if (!path.endNode().hasRelationship(Direction.OUTGOING)) { leaves++; depthSum += path.length(); } return Evaluation.EXCLUDE_AND_CONTINUE; }
@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; } } }
public Evaluation evaluate( Path path ) { // Before the Evaluator, when PruneEvaluator was used individually a PruneEvaluator // was never called with the start node as argument. This condition mimics that behaviour. if ( path.length() == 0 ) { return Evaluation.INCLUDE_AND_CONTINUE; } return pruning.pruneAfter( path ) ? Evaluation.INCLUDE_AND_PRUNE : Evaluation.INCLUDE_AND_CONTINUE; }
@Override public Evaluation evaluate(Path path) { Node n = path.endNode(); UsageFacts facts = dao.readFacts(n.getId()); int size = facts == null ? -1 : facts.metrics.getNumDescendants() + facts.metrics.getNumSynonyms(); if (size > minChunkSize && (size < chunkSize || size - facts.metrics.getNumChildren() < minChunkSize)) { chunkIds.add(n.getId()); return Evaluation.INCLUDE_AND_PRUNE; } else { return Evaluation.INCLUDE_AND_CONTINUE; } }
@Override public Evaluation evaluate(Path path) { return null; }
private Evaluation printResult( Evaluation evaluation ) { System.out.print( String.format( " %s\n", evaluation.name() ) ); return evaluation; }
public Evaluation evaluate( Path path ) { printPath( path ); return printResult( innerEvaluator.evaluate( path ) ); }
@Override public Evaluation evaluate( Path path ) { // TODO deal with this in better way throw new UnsupportedOperationException(); }
@Override public Evaluation evaluate( Path path, BranchState<StepState> state ) { int currentStep = state.getState().step(); int stepStateState = state.getState().state(); while ( true ) { StepEvaluationResult result = stepEvaluators[currentStep].evaluate( path, stepStateState ); switch ( result.stepEvaluation() ) { case REJECT_STAY_EXCLUDE_PRUNE: /* * evaluator failed fatally */ return Evaluation.EXCLUDE_AND_PRUNE; case REJECT_ADVANCE_EXCLUDE_CONTINUE: /* * evaluator failed & exhausted * advance evaluator immediately (current step) & retry */ currentStep++; stepStateState = result.stepState(); continue; case ACCEPT_ADVANCE_EXCLUDE_CONTINUE: /* * evaluator succeeded & exhausted * advance evaluator for next step */ currentStep++; state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.EXCLUDE_AND_CONTINUE; case ACCEPT_STAY_EXCLUDE_CONTINUE: /* * evaluator succeeded but not exhausted * reuse evaluator @ next step */ state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.EXCLUDE_AND_CONTINUE; case ACCEPT_STAY_INCLUDE_CONTINUE: /* * final evaluator succeeded but not exhausted * return path & reuse evaluator @ next step */ state.setState( new StepState( currentStep, result.stepState() ) ); return Evaluation.INCLUDE_AND_CONTINUE; case ACCEPT_ADVANCE_INCLUDE_PRUNE: /* * final evaluator succeeded & exhausted * return path */ return Evaluation.INCLUDE_AND_PRUNE; } } }
public Evaluation evaluation() { return evaluation; }
public Evaluation evaluation() { return null; }
public Evaluation evaluate( Path path ) { return filter.accept( path ) ? Evaluation.INCLUDE_AND_CONTINUE : Evaluation.EXCLUDE_AND_CONTINUE; }
@Override public Evaluation evaluate(Path path) { Node end = path.endNode(); Rank r = Rank.values()[(int) end.getProperty(NeoProperties.RANK, Rank.UNRANKED.ordinal())]; return r.isLinnean() ? Evaluation.INCLUDE_AND_CONTINUE : Evaluation.EXCLUDE_AND_CONTINUE; }
@Override public Evaluation evaluate(Path path) { Node end = path.endNode(); return end.hasLabel(Labels.SYNONYM) ? Evaluation.EXCLUDE_AND_CONTINUE : Evaluation.INCLUDE_AND_CONTINUE; }
@Override public Evaluation evaluate(Path path) { return evaluateNode(path.endNode()) ? Evaluation.INCLUDE_AND_CONTINUE : Evaluation.EXCLUDE_AND_CONTINUE; }
/** * note: we maybe can also utilise the qualified attribute __LITERAL__ here or the __LITERAL__ node label; * * @param path * @return */ @Override public Evaluation evaluate(final Path path) { if(path.length() < 1) { return Evaluation.EXCLUDE_AND_CONTINUE; } if(path.lastRelationship().getStartNode().getId() != subjectNodeId) { return Evaluation.EXCLUDE_AND_CONTINUE; } if(path.endNode().hasRelationship(Direction.OUTGOING)) { return Evaluation.EXCLUDE_AND_PRUNE; } if(path.lastRelationship().hasProperty(DeltaStatics.MATCHED_PROPERTY) && Boolean.TRUE.equals(path.lastRelationship().getProperty(DeltaStatics.MATCHED_PROPERTY, null))) { // only non-matched statements return Evaluation.EXCLUDE_AND_PRUNE; } return Evaluation.INCLUDE_AND_PRUNE; }
@Override public Evaluation evaluate(final Path path) { if (path.length() > relativeAttributePathSizeAttributePathSize) { return Evaluation.EXCLUDE_AND_PRUNE; } if (path.length() > currentHierarchy) { currentHierarchy++; } if (path.length() < currentHierarchy) { return Evaluation.EXCLUDE_AND_CONTINUE; } final Relationship lastRelationship = path.lastRelationship(); final String attributeURI = relativeAttributePathAttributes.get(currentHierarchy - 1).getUri(); // TODO: this was for debugging, or? //lastRelationship.getType().name(); //Paths.pathToString(path, new PathPrinter()); if (!lastRelationship.isType(DynamicRelationshipType.withName(attributeURI))) { return Evaluation.EXCLUDE_AND_PRUNE; } if (currentHierarchy < relativeAttributePathSizeAttributePathSize) { return Evaluation.EXCLUDE_AND_CONTINUE; } return Evaluation.INCLUDE_AND_PRUNE; }