<commit_before>package org.maltparser.parser.algorithm.stack;

import java.util.Stack;

import org.maltparser.core.exception.MaltChainedException;
import org.maltparser.core.syntaxgraph.DependencyStructure;
import org.maltparser.core.syntaxgraph.node.DependencyNode;
import org.maltparser.parser.DependencyParserConfig;
import org.maltparser.parser.Oracle;
import org.maltparser.parser.ParserConfiguration;
import org.maltparser.parser.history.GuideUserHistory;
import org.maltparser.parser.history.action.GuideUserAction;
/**
 * @author <NAME>
 *
 */
public class IncrementalOracle  extends Oracle {
	public IncrementalOracle(DependencyParserConfig manager, GuideUserHistory history) throws MaltChainedException {
		super(manager, history);
		setGuideName("incremental");
	}
	
	public GuideUserAction predict(DependencyStructure gold, ParserConfiguration configuration) throws MaltChainedException {
		StackConfig config = (StackConfig)configuration;
		Stack<DependencyNode> stack = config.getStack();
		Stack<DependencyNode> input = config.getInput();

		if (stack.size() < 2) {
			return updateActionContainers(Incremental.SHIFT, null);
		} else {
			DependencyNode left = stack.get(stack.size()-2);
			DependencyNode right = stack.get(stack.size()-1);

			int leftIndex = left.getIndex();
			int rightIndex = right.getIndex();
			if (!left.isRoot() && gold.getTokenNode(leftIndex).getHead().getIndex() == rightIndex) {
				return updateActionContainers(Incremental.LEFTARC, gold.getTokenNode(leftIndex).getHeadEdge().getLabelSet());
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() == leftIndex && !right.hasHead()) {
				return updateActionContainers(Incremental.RIGHTARC, gold.getTokenNode(rightIndex).getHeadEdge().getLabelSet());
			/* } else if (input.isEmpty()) { // && right.hasHead()
			    return updateActionContainers(Incremental.REDUCE, null);
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() != input.peek().getIndex() && gold.getTokenNode(input.peek().getIndex()).hasLeftDependent() &&
				   gold.getTokenNode(input.peek().getIndex()).getLeftmostDependent().getIndex() < rightIndex) {
			    return updateActionContainers(Incremental.REDUCE, null);
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() != input.peek().getIndex() && gold.getTokenNode(input.peek().getIndex()).getHead().getIndex() < rightIndex) {
			return updateActionContainers(Incremental.REDUCE, null);*/
			} else if (right.hasHead() && checkRightDependent(gold, config.getDependencyGraph(), rightIndex)) {
			    return updateActionContainers(Incremental.REDUCE, null);
			} else {
			    return updateActionContainers(Incremental.SHIFT, null);
			} // Solve the problem with non-projective input.<commit_msg>bug fix InputArcFeature.java<commit_after>package org.maltparser.parser.algorithm.stack;

import java.util.Stack;

import org.maltparser.core.exception.MaltChainedException;
import org.maltparser.core.syntaxgraph.DependencyStructure;
import org.maltparser.core.syntaxgraph.node.DependencyNode;
import org.maltparser.parser.DependencyParserConfig;
import org.maltparser.parser.Oracle;
import org.maltparser.parser.ParserConfiguration;
import org.maltparser.parser.history.GuideUserHistory;
import org.maltparser.parser.history.action.GuideUserAction;
/**
 * @author <NAME>
 *
 */
public class IncrementalOracle  extends Oracle {
	public IncrementalOracle(DependencyParserConfig manager, GuideUserHistory history) throws MaltChainedException {
		super(manager, history);
		setGuideName("incremental");
	}
	
	public GuideUserAction predict(DependencyStructure gold, ParserConfiguration configuration) throws MaltChainedException {
		StackConfig config = (StackConfig)configuration;
		Stack<DependencyNode> stack = config.getStack();
		Stack<DependencyNode> input = config.getInput();

		if (stack.size() < 2) {
			return updateActionContainers(Incremental.SHIFT, null);
		} else { // Add 4 (simple else)
			DependencyNode left = stack.get(stack.size()-2);
			DependencyNode right = stack.get(stack.size()-1);

			int leftIndex = left.getIndex();
			int rightIndex = right.getIndex();
			if (!left.isRoot() && gold.getTokenNode(leftIndex).getHead().getIndex() == rightIndex) {
				return updateActionContainers(Incremental.LEFTARC, gold.getTokenNode(leftIndex).getHeadEdge().getLabelSet());
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() == leftIndex && !right.hasHead()) {
				return updateActionContainers(Incremental.RIGHTARC, gold.getTokenNode(rightIndex).getHeadEdge().getLabelSet());
			/* } else if (input.isEmpty()) { // && right.hasHead()
			    return updateActionContainers(Incremental.REDUCE, null);
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() != input.peek().getIndex() && gold.getTokenNode(input.peek().getIndex()).hasLeftDependent() &&
				   gold.getTokenNode(input.peek().getIndex()).getLeftmostDependent().getIndex() < rightIndex) {
			    return updateActionContainers(Incremental.REDUCE, null);
			} else if (gold.getTokenNode(rightIndex).getHead().getIndex() != input.peek().getIndex() && gold.getTokenNode(input.peek().getIndex()).getHead().getIndex() < rightIndex) {
			return updateActionContainers(Incremental.REDUCE, null);*/
			} else if (right.hasHead() && checkRightDependent(gold, config.getDependencyGraph(), rightIndex)) {
			    return updateActionContainers(Incremental.REDUCE, null);
			} else {
			    return updateActionContainers(Incremental.SHIFT, null);
			} // Solve the problem with non-projective input.
{'fraction_non_alphanumeric': 0.1334178131788559, 'fraction_numerical': 0.0012671976828385228, 'mean_word_length': 5.7958179581795815, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '7059158', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1594, 'n_words': 271}