<commit_before>/*
 *  Copyright (C) 2011-2012 The Animo Project
 *  http://animotron.org
 *  	
 *  This file is part of Animotron.
 *  
 *  Animotron is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 *  
 *  Animotron is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *  
 *  You should have received a copy of 
 *  the GNU Affero General Public License along with Animotron.  
 *  If not, see <http://www.gnu.org/licenses/>.
 */
package org.animotron.statement.query;

import javolution.util.FastSet;
import javolution.util.FastTable;

import org.animotron.graph.index.Order;
import org.animotron.manipulator.PFlow;
import org.animotron.manipulator.QCAVector;
import org.animotron.statement.Statement;
import org.animotron.statement.Statements;
import org.animotron.statement.operator.*;
import org.animotron.statement.relation.SHALL;
import org.animotron.statement.relation.USE;
import org.animotron.statement.relation.WEAK_USE;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.traversal.Evaluator;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.kernel.Traversal;
import org.neo4j.kernel.Uniqueness;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static org.animotron.graph.Properties.FREEZE;
import static org.animotron.graph.RelationshipTypes.RESULT;
import static org.neo4j.graphdb.Direction.INCOMING;
import static org.neo4j.graphdb.Direction.OUTGOING;
import static org.neo4j.graphdb.traversal.Evaluation.*;

/**
 * Abstract Query
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractQuery extends Operator implements Evaluable, Query {
	
	private static boolean debugUSE = false;

    public AbstractQuery(String... name) {
        super(name);
    }

    protected static TraversalDescription td_IS =
        Traversal.description().
            breadthFirst().
            relationships(REF._, INCOMING ).
            relationships(AN._, INCOMING ).
            //evaluator(Evaluators.excludeStartPosition()).
            evaluator(new org.neo4j.graphdb.traversal.Evaluator(){
    			@Override
    			public Evaluation evaluate(Path path) {
    				//System.out.println(path);
    				
    				if (path.length() < 2)
    					return EXCLUDE_AND_CONTINUE;
    				
    				Relationship r = path.lastRelationship();
    				if (r.isType(REF._) && FREEZE.has(r))
    					return EXCLUDE_AND_PRUNE;

    				if (path.length() % 2 == 0 && r.isType(AN._))
    					return INCLUDE_AND_CONTINUE;
    				
    				if (path.length() % 2 == 1 && !r.isType(REF._))
    					return EXCLUDE_AND_PRUNE;
    					

    				return EXCLUDE_AND_CONTINUE;
    			}
    		});

    protected static TraversalDescription td_IS_leaf =
            Traversal.description().
                breadthFirst().
                relationships(REF._, INCOMING ).
                relationships(AN._, INCOMING ).
                //evaluator(Evaluators.excludeStartPosition()).
                evaluator(new org.neo4j.graphdb.traversal.Evaluator(){
        			@Override
        			public Evaluation evaluate(Path path) {
        				if (path.endNode().getId() == 0)
        					return EXCLUDE_AND_PRUNE;
        				
        				//System.out.println(path);
        				
        				if (path.length() < 2)
        					return EXCLUDE_AND_CONTINUE;
        				
        				Relationship r = path.lastRelationship();
        				if (r.isType(REF._) && FREEZE.has(r))
        					return EXCLUDE_AND_PRUNE;

        				if (path.length() % 2 == 0 && r.isType(AN._))
        					return INCLUDE_AND_CONTINUE;
        				<commit_msg>add STOPPER at traverse<commit_after>/*
 *  Copyright (C) 2011-2012 The Animo Project
 *  http://animotron.org
 *  	
 *  This file is part of Animotron.
 *  
 *  Animotron is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as 
 *  published by the Free Software Foundation, either version 3 of 
 *  the License, or (at your option) any later version.
 *  
 *  Animotron is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Affero General Public License for more details.
 *  
 *  You should have received a copy of 
 *  the GNU Affero General Public License along with Animotron.  
 *  If not, see <http://www.gnu.org/licenses/>.
 */
package org.animotron.statement.query;

import javolution.util.FastSet;
import javolution.util.FastTable;

import org.animotron.graph.index.Order;
import org.animotron.manipulator.PFlow;
import org.animotron.manipulator.QCAVector;
import org.animotron.statement.Statement;
import org.animotron.statement.Statements;
import org.animotron.statement.operator.*;
import org.animotron.statement.relation.SHALL;
import org.animotron.statement.relation.USE;
import org.animotron.statement.relation.WEAK_USE;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.index.IndexHits;
import org.neo4j.graphdb.traversal.Evaluation;
import org.neo4j.graphdb.traversal.Evaluator;
import org.neo4j.graphdb.traversal.TraversalDescription;
import org.neo4j.kernel.Traversal;
import org.neo4j.kernel.Uniqueness;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static org.animotron.graph.Properties.FREEZE;
import static org.animotron.graph.RelationshipTypes.RESULT;
import static org.neo4j.graphdb.Direction.INCOMING;
import static org.neo4j.graphdb.Direction.OUTGOING;
import static org.neo4j.graphdb.traversal.Evaluation.*;

/**
 * Abstract Query
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public abstract class AbstractQuery extends Operator implements Evaluable, Query {
	
	private static boolean debugUSE = false;

    public AbstractQuery(String... name) {
        super(name);
    }

    protected static TraversalDescription td_IS =
        Traversal.description().
            breadthFirst().
            relationships(REF._, INCOMING ).
            relationships(AN._, INCOMING ).
            //evaluator(Evaluators.excludeStartPosition()).
            evaluator(new org.neo4j.graphdb.traversal.Evaluator(){
    			@Override
    			public Evaluation evaluate(Path path) {
    				//System.out.println(path);
    				
    				if (path.length() < 2)
    					return EXCLUDE_AND_CONTINUE;
    				
    				Relationship r = path.lastRelationship();
    				if (r.isType(REF._) && FREEZE.has(r))
    					return EXCLUDE_AND_PRUNE;

    				if (path.length() % 2 == 0 && r.isType(AN._))
    					return INCLUDE_AND_CONTINUE;
    				
    				if (path.length() % 2 == 1 && !r.isType(REF._))
    					return EXCLUDE_AND_PRUNE;
    					

    				return EXCLUDE_AND_CONTINUE;
    			}
    		});

    protected static TraversalDescription td_IS_leaf =
            Traversal.description().
                breadthFirst().
                relationships(REF._, INCOMING ).
                relationships(AN._, INCOMING ).
                //evaluator(Evaluators.excludeStartPosition()).
                evaluator(new org.neo4j.graphdb.traversal.Evaluator(){
        			@Override
        			public Evaluation evaluate(Path path) {
        				if (path.endNode().getId() == 0)
        					return EXCLUDE_AND_PRUNE;
        				
        				System.out.println(path);
        				
        				if (path.length() < 2)
        					return EXCLUDE_AND_CONTINUE;
        				
        				Relationship r = path.lastRelationship();
        				if (r.isType(REF._) && FREEZE.has(r))
        					return EXCLUDE_AND_PRUNE;

        				if (path.length() % 2 == 0 && r.isType(AN._)) {
        					if (r.hasProperty(STOPPER._.name()))
        						return INCLUDE_AND_PRUNE;
        					return INCLUDE_AND_CONTINUE;
        				}
        				
{'fraction_non_alphanumeric': 0.10347238405965975, 'fraction_numerical': 0.0076905150314611976, 'mean_word_length': 2.6805317324185247, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1371492', 'n_tokens_mistral': 2977, 'n_tokens_neox': 2700, 'n_words': 599}