public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { PlanarConfig planarConfig = (PlanarConfig)config; if (planarConfig.getRootHandling() != PlanarConfig.NORMAL && planarConfig.getStack().peek().isRoot()) { return updateActionContainers(history, Planar.SHIFT, null); } return null; }
public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { NivreConfig nivreConfig = (NivreConfig)config; if (!nivreConfig.isAllowRoot() && nivreConfig.getStack().peek().isRoot()) { return updateActionContainers(history, ArcStandard.SHIFT, null); } return null; }
public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { TwoPlanarConfig theConfig = (TwoPlanarConfig)config; if (theConfig.getRootHandling() != TwoPlanarConfig.NORMAL && theConfig.getActiveStack().peek().isRoot()) { return updateActionContainers(history, TwoPlanar.SHIFT, null); } return null; }
public boolean permissible(GuideUserAction currentAction, ParserConfiguration config) throws MaltChainedException { currentAction.getAction(actionContainers); int trans = transActionContainer.getActionCode(); if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) { return false; } DependencyNode stackTop = ((NivreConfig)config).getStack().peek(); if (!((NivreConfig)config).isAllowRoot() && stackTop.isRoot() && trans != SHIFT) { return false; } if (trans == LEFTARC && stackTop.isRoot()) { return false; } return true; }
public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { final CovingtonConfig covingtonConfig = (CovingtonConfig)config; if (!covingtonConfig.isAllowRoot() && covingtonConfig.getLeftTarget().isRoot()) { return updateActionContainers(history, NonProjective.NOARC, null); } return null; }
public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { final CovingtonConfig covingtonConfig = (CovingtonConfig)config; if (!covingtonConfig.isAllowRoot() && covingtonConfig.getLeftTarget().isRoot()) { return updateActionContainers(history, Projective.NOARC, null); } return null; }
public DependencyNode getProperAncestor() throws MaltChainedException { if (!this.hasHead()) { return null; } DependencyNode tmp = this; while (tmp.hasHead() && !tmp.isRoot()) { tmp = tmp.getHead(); } return tmp; }
public boolean permissible(GuideUserAction currentAction, ParserConfiguration configuration) throws MaltChainedException { final StackConfig config = (StackConfig)configuration; currentAction.getAction(actionContainers); final int trans = transActionContainer.getActionCode(); if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) { return false; } final Stack<DependencyNode> stack = config.getStack(); if ((trans == LEFTARC || trans == RIGHTARC) && stack.size() < 2) { return false; } if (trans == LEFTARC && stack.get(stack.size()-2).isRoot()) { return false; } if (trans == SHIFT && config.getInput().isEmpty()) { return false; } return true; }
public GuideUserAction getDeterministicAction(GuideUserHistory history, ParserConfiguration config) throws MaltChainedException { final NivreConfig nivreConfig = (NivreConfig)config; if (!nivreConfig.isEnforceTree()) { if (!nivreConfig.isAllowRoot() && nivreConfig.getStack().peek().isRoot()) { return updateActionContainers(history, ArcEager.SHIFT, null); } } else { //Added if (!nivreConfig.isAllowRoot() && nivreConfig.getStack().peek().isRoot() && !nivreConfig.isEnd()) { return updateActionContainers(history, ArcEager.SHIFT, null); } if (nivreConfig.getInput().isEmpty() && nivreConfig.getStack().peek().hasHead()) { return updateActionContainers(history, ArcEager.REDUCE, null); } if (nivreConfig.getInput().isEmpty() && !nivreConfig.getStack().peek().hasHead()) { return updateActionContainers(history, ArcEager.UNSHIFT, null); } } return null; }
public GuideUserAction predict(DependencyStructure gold, ParserConfiguration configuration) throws MaltChainedException { StackConfig config = (StackConfig)configuration; Stack<DependencyNode> stack = config.getStack(); if (stack.size() < 2) { return updateActionContainers(Projective.SHIFT, null); } else { DependencyNode left = stack.get(stack.size()-2); int leftIndex = left.getIndex(); int rightIndex = stack.get(stack.size()-1).getIndex(); if (!left.isRoot() && gold.getTokenNode(leftIndex).getHead().getIndex() == rightIndex) { return updateActionContainers(Projective.LEFTARC, gold.getTokenNode(leftIndex).getHeadEdge().getLabelSet()); } else if (gold.getTokenNode(rightIndex).getHead().getIndex() == leftIndex && checkRightDependent(gold, config.getDependencyGraph(), rightIndex)) { return updateActionContainers(Projective.RIGHTARC, gold.getTokenNode(rightIndex).getHeadEdge().getLabelSet()); } else { return updateActionContainers(Projective.SHIFT, null); } // Solve the problem with non-projective input. } }
public boolean permissible(GuideUserAction currentAction, ParserConfiguration config) throws MaltChainedException { currentAction.getAction(actionContainers); final int trans = transActionContainer.getActionCode(); final NivreConfig nivreConfig = (NivreConfig)config; final DependencyNode stackPeek = nivreConfig.getStack().peek(); if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) { return false; } if ((trans == LEFTARC || trans == REDUCE) && stackPeek.isRoot()) { return false; } if (trans == LEFTARC && stackPeek.hasHead()) { return false; } if (trans == REDUCE && !stackPeek.hasHead() && !nivreConfig.isAllowReduce()) { return false; } //Added if (trans == SHIFT && nivreConfig.isEnforceTree() && nivreConfig.isEnd()){ return false; } return true; }
public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException { NivreConfig nivreConfig = (NivreConfig)config; DependencyNode stackPeek = nivreConfig.getStack().peek(); int stackPeekIndex = stackPeek.getIndex(); int inputPeekIndex = nivreConfig.getInput().peek().getIndex(); if (!nivreConfig.isAllowRoot() && stackPeek.isRoot()) { return updateActionContainers(ArcStandard.SHIFT, null); } if (!stackPeek.isRoot() && gold.getTokenNode(stackPeekIndex).getHead().getIndex() == inputPeekIndex) { return updateActionContainers(ArcStandard.LEFTARC, gold.getTokenNode(stackPeekIndex).getHeadEdge().getLabelSet()); } else if (gold.getTokenNode(inputPeekIndex).getHead().getIndex() == stackPeekIndex && checkRightDependent(gold, nivreConfig.getDependencyGraph(), inputPeekIndex)) { return updateActionContainers(ArcStandard.RIGHTARC, gold.getTokenNode(inputPeekIndex).getHeadEdge().getLabelSet()); } else { return updateActionContainers(ArcStandard.SHIFT, null); } }
protected Edge addDependencyEdge(DependencyNode head, DependencyNode dependent) throws MaltChainedException { if (head == null || dependent == null) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!dependent.isRoot()) { if (singleHeadedConstraint && dependent.hasHead()) { return moveDependencyEdge(head, dependent); } final DependencyNode hc = ((DependencyNode)head).findComponent(); final DependencyNode dc = ((DependencyNode)dependent).findComponent(); if (hc != dc) { link(hc, dc); numberOfComponents--; } Edge e = edgePool.checkOut(); e.setBelongsToGraph(this); e.setEdge((Node)head, (Node)dependent, Edge.DEPENDENCY_EDGE); graphEdges.add(e); return e; } else { throw new SyntaxGraphException("Head node is not a root node or a terminal node."); } }
public Edge addDependencyEdge(DependencyNode head, DependencyNode dependent) throws MaltChainedException { if (head == null || dependent == null || head.getBelongsToGraph() != this || dependent.getBelongsToGraph() != this) { throw new SyntaxGraphException("Head or dependent node is missing."); } else if (!dependent.isRoot()) { if (singleHeadedConstraint && dependent.hasHead()) { throw new SyntaxGraphException("The dependent already have a head. "); } DependencyNode hc = ((DependencyNode)head).findComponent(); DependencyNode dc = ((DependencyNode)dependent).findComponent(); if (hc != dc) { link(hc, dc); numberOfComponents--; } Edge e = edgePool.checkOut(); e.setBelongsToGraph(this); e.setEdge((Node)head, (Node)dependent, Edge.DEPENDENCY_EDGE); graphEdges.add(e); return e; } else { throw new SyntaxGraphException("Head node is not a root node or a terminal node."); } }
private void connectUnattachedSpines(MappablePhraseStructureGraph graph, DependencyNode depNode) throws MaltChainedException { if (!depNode.isRoot()) { PhraseStructureNode dependentSpine = (PhraseStructureNode)depNode; while (dependentSpine.getParent() != null) { dependentSpine = dependentSpine.getParent(); } if (!dependentSpine.isRoot()) { updatePhraseStructureGraph(graph,depNode.getHeadEdge(),true); } } for (int i = 0; i < depNode.getLeftDependentCount(); i++) { connectUnattachedSpines(graph, depNode.getLeftDependent(i)); } for (int i = depNode.getRightDependentCount()-1; i >= 0 ; i--) { connectUnattachedSpines(graph, depNode.getRightDependent(i)); } }
public boolean permissible(GuideUserAction currentAction, ParserConfiguration config) throws MaltChainedException { CovingtonConfig covingtonConfig = (CovingtonConfig)config; DependencyNode leftTarget = covingtonConfig.getLeftTarget(); DependencyNode rightTarget = covingtonConfig.getRightTarget(); DependencyStructure dg = covingtonConfig.getDependencyGraph(); currentAction.getAction(actionContainers); int trans = transActionContainer.getActionCode(); if (trans == SHIFT && covingtonConfig.isAllowShift() == false) { return false; } if ((trans == LEFTARC || trans == RIGHTARC) && !isActionContainersLabeled()) { return false; } if (trans == LEFTARC && leftTarget.isRoot()) { return false; } if (trans == LEFTARC && dg.hasLabeledDependency(leftTarget.getIndex())) { return false; } if (trans == RIGHTARC && dg.hasLabeledDependency(rightTarget.getIndex())) { return false; } return true; }
public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException { final NivreConfig nivreConfig = (NivreConfig)config; final DependencyNode stackPeek = nivreConfig.getStack().peek(); final int stackPeekIndex = stackPeek.getIndex(); final int inputPeekIndex = nivreConfig.getInput().peek().getIndex(); if (!stackPeek.isRoot() && gold.getTokenNode(stackPeekIndex).getHead().getIndex() == inputPeekIndex) { return updateActionContainers(ArcEager.LEFTARC, gold.getTokenNode(stackPeekIndex).getHeadEdge().getLabelSet()); } else if (gold.getTokenNode(inputPeekIndex).getHead().getIndex() == stackPeekIndex) { return updateActionContainers(ArcEager.RIGHTARC, gold.getTokenNode(inputPeekIndex).getHeadEdge().getLabelSet()); } else if (!nivreConfig.isAllowReduce() && !stackPeek.hasHead()) { return updateActionContainers(ArcEager.SHIFT, null); } else if (gold.getTokenNode(inputPeekIndex).hasLeftDependent() && gold.getTokenNode(inputPeekIndex).getLeftmostDependent().getIndex() < stackPeekIndex) { return updateActionContainers(ArcEager.REDUCE, null); } else if (gold.getTokenNode(inputPeekIndex).getHead().getIndex() < stackPeekIndex && (!gold.getTokenNode(inputPeekIndex).getHead().isRoot() || nivreConfig.isAllowRoot())) { return updateActionContainers(ArcEager.REDUCE, null); } else { return updateActionContainers(ArcEager.SHIFT, null); } }
public void update() throws MaltChainedException { final AddressValue a = addressFunction.getAddressValue(); if (a.getAddress() == null) { featureValue.update(symbolTable.getNullValueCode(NullValueId.NO_NODE), symbolTable.getNullValueSymbol(NullValueId.NO_NODE), true, 1); } else { final DependencyNode node = (DependencyNode)a.getAddress(); if (!node.isRoot()) { int indexCode = node.getLabelCode(symbolTable); if (column.getType() == ColumnDescription.STRING) { featureValue.update(indexCode, symbolTable.getSymbolCodeToString(indexCode), false, 1); } else { castFeatureValue(symbolTable.getSymbolCodeToString(indexCode)); } } else { featureValue.update(symbolTable.getNullValueCode(NullValueId.ROOT_NODE), symbolTable.getNullValueSymbol(NullValueId.ROOT_NODE), true, 1); } } }
public GuideUserAction predict(DependencyStructure gold, ParserConfiguration config) throws MaltChainedException { CovingtonConfig covingtonConfig = (CovingtonConfig)config; DependencyNode leftTarget = covingtonConfig.getLeftTarget(); int leftTargetIndex = leftTarget.getIndex(); int rightTargetIndex = covingtonConfig.getRightTarget().getIndex(); if (!leftTarget.isRoot() && gold.getTokenNode(leftTargetIndex).getHead().getIndex() == rightTargetIndex) { return updateActionContainers(NonProjective.LEFTARC, gold.getTokenNode(leftTargetIndex).getHeadEdge().getLabelSet()); } else if (gold.getTokenNode(rightTargetIndex).getHead().getIndex() == leftTargetIndex) { return updateActionContainers(NonProjective.RIGHTARC, gold.getTokenNode(rightTargetIndex).getHeadEdge().getLabelSet()); } else if (covingtonConfig.isAllowShift() == true && (!(gold.getTokenNode(rightTargetIndex).hasLeftDependent() && gold.getTokenNode(rightTargetIndex).getLeftmostDependent().getIndex() < leftTargetIndex) && !(gold.getTokenNode(rightTargetIndex).getHead().getIndex() < leftTargetIndex && (!gold.getTokenNode(rightTargetIndex).getHead().isRoot() || covingtonConfig.getLeftstop() == 0)))) { return updateActionContainers(NonProjective.SHIFT, null); } else { return updateActionContainers(NonProjective.NOARC, null); } }
public void update() throws MaltChainedException { final AddressValue a = addressFunction.getAddressValue(); if (a.getAddress() == null) { featureValue.update(symbolTable.getNullValueCode(NullValueId.NO_NODE), symbolTable.getNullValueSymbol(NullValueId.NO_NODE), true, 1); } else { final DependencyNode node = (DependencyNode)a.getAddress(); if (!node.isRoot()) { if (node.hasHead()) { int indexCode = node.getHeadEdge().getLabelCode(symbolTable); String symbol = symbolTable.getSymbolCodeToString(indexCode); if (column.getType() == ColumnDescription.STRING) { featureValue.update(indexCode, symbol, false, 1); } else { castFeatureValue(symbol); } } else { featureValue.update(symbolTable.getNullValueCode(NullValueId.NO_VALUE), symbolTable.getNullValueSymbol(NullValueId.NO_VALUE), true, 1); } } else { featureValue.update(symbolTable.getNullValueCode(NullValueId.ROOT_NODE), symbolTable.getNullValueSymbol(NullValueId.ROOT_NODE), true, 1); } } }