001 package org.maltparser.parser.algorithm.nivre;
002
003 import org.maltparser.core.exception.MaltChainedException;
004 import org.maltparser.core.syntaxgraph.DependencyStructure;
005 import org.maltparser.core.syntaxgraph.node.DependencyNode;
006 import org.maltparser.parser.DependencyParserConfig;
007 import org.maltparser.parser.Oracle;
008 import org.maltparser.parser.ParserConfiguration;
009 import org.maltparser.parser.history.GuideUserHistory;
010 import org.maltparser.parser.history.action.GuideUserAction;
011 /**
012 * @author Johan Hall
013 *
014 */
015 public class ArcStandardOracle extends Oracle {
016
017 public ArcStandardOracle(DependencyParserConfig manager, GuideUserHistory history) throws MaltChainedException {
018 super(manager, history);
019 setGuideName("ArcStandard");
020 }
021
022 public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException {
023 NivreConfig nivreConfig = (NivreConfig)config;
024 DependencyNode stackPeek = nivreConfig.getStack().peek();
025 int stackPeekIndex = stackPeek.getIndex();
026 int inputPeekIndex = nivreConfig.getInput().peek().getIndex();
027
028 if (nivreConfig.getRootHandling() != NivreConfig.NORMAL && stackPeek.isRoot()) {
029 return updateActionContainers(ArcStandard.SHIFT, null);
030 }
031 if (!stackPeek.isRoot() && gold.getTokenNode(stackPeekIndex).getHead().getIndex() == inputPeekIndex) {
032 return updateActionContainers(ArcStandard.LEFTARC, gold.getTokenNode(stackPeekIndex).getHeadEdge().getLabelSet());
033 } else if (gold.getTokenNode(inputPeekIndex).getHead().getIndex() == stackPeekIndex && checkRightDependent(gold, nivreConfig.getDependencyGraph(), inputPeekIndex)) {
034 return updateActionContainers(ArcStandard.RIGHTARC, gold.getTokenNode(inputPeekIndex).getHeadEdge().getLabelSet());
035 } else {
036 return updateActionContainers(ArcStandard.SHIFT, null);
037 }
038 }
039
040 private boolean checkRightDependent(DependencyStructure gold, DependencyStructure parseDependencyGraph, int inputPeekIndex) throws MaltChainedException {
041 if (gold.getTokenNode(inputPeekIndex).getRightmostDependent() == null) {
042 return true;
043 } else if (parseDependencyGraph.getTokenNode(inputPeekIndex).getRightmostDependent() != null) {
044 if (gold.getTokenNode(inputPeekIndex).getRightmostDependent().getIndex() == parseDependencyGraph.getTokenNode(inputPeekIndex).getRightmostDependent().getIndex()) {
045 return true;
046 }
047 }
048 return false;
049 }
050
051 public void finalizeSentence(DependencyStructure dependencyGraph) throws MaltChainedException {
052
053 }
054
055 public void terminate() throws MaltChainedException {
056
057 }
058 }