<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.exist.interpreter;

import org.animotron.Namespaces;
import org.exist.dom.ElementAtExist;
import org.exist.dom.QName;
import org.exist.memtree.MemTreeBuilder;
import org.exist.xquery.AnalyzeContextInfo;
import org.exist.xquery.Constants;
import org.exist.xquery.Expression;
import org.exist.xquery.LocationStep;
import org.exist.xquery.NameTest;
import org.exist.xquery.PathExpr;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.Type;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class ProcessReference extends AbstractProcessReference {
	
	ProcessReference(Controller controller) {
		super(controller);
	}
	
	public Sequence resolve() throws XPathException{
		
		Sequence source = controller.getSource();
		ElementAtExist input = controller.getCurrentStep();
		
		if (source == null) {
			return controller.getIndexWorker().getNode(input.getLocalName());
		} else {
			XQueryContext context = getXQueryContext();
			LocationStep step = new LocationStep(context, Constants.SELF_AXIS, new NameTest(Type.ELEMENT, new QName (input.getLocalName(), Namespaces.THE.namespace())));
			AnalyzeContextInfo info = new AnalyzeContextInfo(context);
			info.setFlags(Expression.UNORDERED);
			PathExpr exp = new PathExpr(context);
			exp.add(step);
			exp.analyze(info);
			exp.reset();
			return exp.eval(source);
		}
		
	}

	@Override
	public void process(MemTreeBuilder builder) throws XPathException{
		
		Sequence res = resolve();
		
		if (res == null || res.isEmpty())
			return;
		
		if (getCurrentStep().hasChildNodes()){
			Sequence newContext;
			Controller ctrl = new Controller(getXQueryContext(), controller.getChildNodes(getCurrentStep()) , getContext());
			newContext = ctrl.process();
			//controller.pushContext(newContext);
		}
		
		process(res, builder);
		
	}
	
}
<commit_msg>push context<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.exist.interpreter;

import org.animotron.Namespaces;
import org.exist.dom.ElementAtExist;
import org.exist.dom.QName;
import org.exist.memtree.MemTreeBuilder;
import org.exist.xquery.AnalyzeContextInfo;
import org.exist.xquery.Constants;
import org.exist.xquery.Expression;
import org.exist.xquery.LocationStep;
import org.exist.xquery.NameTest;
import org.exist.xquery.PathExpr;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.Type;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class ProcessReference extends AbstractProcessReference {
	
	ProcessReference(Controller controller) {
		super(controller);
	}
	
	public Sequence resolve() throws XPathException{
		
		Sequence source = controller.getSource();
		ElementAtExist input = controller.getCurrentStep();
		
		if (source == null) {
			return controller.getIndexWorker().getNode(input.getLocalName());
		} else {
			XQueryContext context = getXQueryContext();
			LocationStep step = new LocationStep(context, Constants.SELF_AXIS, new NameTest(Type.ELEMENT, new QName (input.getLocalName(), Namespaces.THE.namespace())));
			AnalyzeContextInfo info = new AnalyzeContextInfo(context);
			info.setFlags(Expression.UNORDERED);
			PathExpr exp = new PathExpr(context);
			exp.add(step);
			exp.analyze(info);
			exp.reset();
			return exp.eval(source);
		}
		
	}

	@Override
	public void process(MemTreeBuilder builder) throws XPathException{
		
		Sequence res = resolve();
		
		if (res == null || res.isEmpty())
			return;
		
		if (getCurrentStep().hasChildNodes()){
			Sequence newContext;
			Controller ctrl = new Controller(getXQueryContext(), controller.getChildNodes(getCurrentStep()) , getContext());
			newContext = ctrl.process();
			controller.pushContext(newContext);
		}
		
		process(res, builder);
		
	}
	
}

{'fraction_non_alphanumeric': 0.10344199599344382, 'fraction_numerical': 0.004735020943361865, 'mean_word_length': 4.4161735700197235, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6816753', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1574, 'n_words': 477}