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); }
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 ); }
private Evaluator addBlaEvaluator( Evaluator evaluator ) { if ( this.evaluator instanceof MultiEvaluator ) { return ((MultiEvaluator) this.evaluator).add( evaluator ); } else { if ( this.evaluator == Evaluators.all() ) { return evaluator; } else { return new MultiEvaluator( new Evaluator[] { this.evaluator, evaluator } ); } } }
public MultiEvaluator add( Evaluator evaluator ) { Evaluator[] newArray = new Evaluator[this.evaluators.length+1]; System.arraycopy( this.evaluators, 0, newArray, 0, this.evaluators.length ); newArray[newArray.length-1] = evaluator; return new MultiEvaluator( newArray ); }
private TraversalDescriptionImpl( Expander expander, UniquenessFactory uniqueness, Object uniquenessParameter, Evaluator evaluator, BranchOrderingPolicy branchSelector ) { this.expander = expander; this.uniqueness = uniqueness; this.uniquenessParameter = uniquenessParameter; this.evaluator = evaluator; this.branchSelector = branchSelector; }
public TraversalPrinter( Evaluator innerEvaluator, String... propertyNames ) { this.innerEvaluator = innerEvaluator; this.propertyNames = asList( propertyNames ); }
MultiEvaluator( Evaluator... prunings ) { this.evaluators = prunings; }