001package org.maltparser.parser.algorithm.covington; 002 003import org.maltparser.core.exception.MaltChainedException; 004import org.maltparser.core.syntaxgraph.DependencyStructure; 005import org.maltparser.core.syntaxgraph.node.DependencyNode; 006import org.maltparser.parser.DependencyParserConfig; 007import org.maltparser.parser.Oracle; 008import org.maltparser.parser.ParserConfiguration; 009import org.maltparser.parser.history.GuideUserHistory; 010import org.maltparser.parser.history.action.GuideUserAction; 011/** 012 * @author Johan Hall 013 * 014 */ 015public class CovingtonOracle extends Oracle { 016 public CovingtonOracle(DependencyParserConfig manager, GuideUserHistory history) throws MaltChainedException { 017 super(manager, history); 018 setGuideName("NonProjective"); 019 } 020 021 public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException { 022 CovingtonConfig covingtonConfig = (CovingtonConfig)config; 023 DependencyNode leftTarget = covingtonConfig.getLeftTarget(); 024 int leftTargetIndex = leftTarget.getIndex(); 025 int rightTargetIndex = covingtonConfig.getRightTarget().getIndex(); 026 027 if (!leftTarget.isRoot() && gold.getTokenNode(leftTargetIndex).getHead().getIndex() == rightTargetIndex) { 028 return updateActionContainers(NonProjective.LEFTARC, gold.getTokenNode(leftTargetIndex).getHeadEdge().getLabelSet()); 029 } else if (gold.getTokenNode(rightTargetIndex).getHead().getIndex() == leftTargetIndex) { 030 return updateActionContainers(NonProjective.RIGHTARC, gold.getTokenNode(rightTargetIndex).getHeadEdge().getLabelSet()); 031 } else if (covingtonConfig.isAllowShift() == true && (!(gold.getTokenNode(rightTargetIndex).hasLeftDependent() 032 && gold.getTokenNode(rightTargetIndex).getLeftmostDependent().getIndex() < leftTargetIndex) 033 && !(gold.getTokenNode(rightTargetIndex).getHead().getIndex() < leftTargetIndex 034 && (!gold.getTokenNode(rightTargetIndex).getHead().isRoot() || covingtonConfig.getLeftstop() == 0)))) { 035 return updateActionContainers(NonProjective.SHIFT, null); 036 } else { 037 return updateActionContainers(NonProjective.NOARC, null); 038 } 039 } 040 041 public void finalizeSentence(DependencyStructure dependencyGraph) throws MaltChainedException { 042 043 } 044 045 public void terminate() throws MaltChainedException { 046 047 } 048}