<commit_before>/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.operator.query;

import org.animotron.manipulator.OnQuestion;
import org.animotron.manipulator.PFlow;
import org.animotron.operator.Utils;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

import java.util.List;

/**
 * Query operator 'ANY'.
 * 
 * Return amy first 'perfect' USE
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ANY extends AbstractQuery {
	
	public static final ANY _ = new ANY();
	
	private ANY() { super("any", "animo/query/any"); }

	public OnQuestion onCalcQuestion() {
        return question;
    }

	private OnQuestion question = new OnQuestion() {
        @Override
        public void onMessage(final PFlow pf) {
			System.out.println("ANY **************************");
            
			final Node n = pf.getOP().getEndNode();
			Node node = Utils.getByREF(n);

			List<Node>[] lists = getUSEs(node, pf.getStartOP());
			List<Node> uses = lists[1];
			List<Node> directed = lists[0];
			
			boolean underUSE = false;
			if (directed.size() == 1) { 
				underUSE = true;
				node = directed.get(0);
			}

			System.out.println(" node = "+node);

			if (underUSE && filtering(pf, node, uses)) {
				pf.sendAnswer( createResultInMemory( n, getThe(node) ) );
			} else {
	            for (Relationship tdR : td_IS.traverse(node).relationships()) {
                    System.out.println("ANY get next "+tdR+" ["+tdR.getStartNode()+"]");
                    Node res = tdR.getStartNode();
                    if (filtering(pf, res, uses)) {

                        pf.sendAnswer( createResultInMemory( n, getThe(res) ) );
                        break;
                    }
                }
			}
            pf.done();
        }<commit_msg>avoid NPE<commit_after>/*
 *  Copyright (C) 2011 The Animo Project
 *  http://animotron.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 3
 *  of the License, or (at your option) any later version.
 *
 *  This program 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.animotron.operator.query;

import org.animotron.manipulator.OnQuestion;
import org.animotron.manipulator.PFlow;
import org.animotron.operator.Utils;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;

import java.util.List;

/**
 * Query operator 'ANY'.
 * 
 * Return amy first 'perfect' USE
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ANY extends AbstractQuery {
	
	public static final ANY _ = new ANY();
	
	private ANY() { super("any", "animo/query/any"); }

	public OnQuestion onCalcQuestion() {
        return question;
    }

	private OnQuestion question = new OnQuestion() {
        @Override
        public void onMessage(final PFlow pf) {
			System.out.println("ANY **************************");
            
			final Node n = pf.getOP().getEndNode();
			Node node = Utils.getByREF(n);

			List<Node>[] lists = getUSEs(node, pf.getStartOP());
			List<Node> uses = lists[1];
			List<Node> directed = lists[0];
			
			boolean underUSE = false;
			if (directed != null && directed.size() == 1) { 
				underUSE = true;
				node = directed.get(0);
			}

			System.out.println(" node = "+node);

			if (underUSE && filtering(pf, node, uses)) {
				pf.sendAnswer( createResultInMemory( n, getThe(node) ) );
			} else {
	            for (Relationship tdR : td_IS.traverse(node).relationships()) {
                    System.out.println("ANY get next "+tdR+" ["+tdR.getStartNode()+"]");
                    Node res = tdR.getStartNode();
                    if (filtering(pf, res, uses)) {

                        pf.sendAnswer( createResultInMemory( n, getThe(res) ) );
                        break;
                    }
                }
			}
            pf.done();
        }
{'fraction_non_alphanumeric': 0.12725874663590928, 'fraction_numerical': 0.007304882737408689, 'mean_word_length': 2.727077363896848, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '249929', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1525, 'n_words': 491}