public int getDependencyNodeDepth() throws MaltChainedException { DependencyNode tmp = this; int depth = 0; while (tmp.hasHead()) { depth++; tmp = tmp.getHead(); } return depth; }
public int getDependencyNodeDepth() throws MaltChainedException { DependencyNode tmp = this; int depth = 0; while (tmp.hasHead()) { depth++; tmp = tmp.getHead(); } return depth; }
public String toStringTerminalNode(TokenNode node) { final StringBuilder sb = new StringBuilder(); final DependencyNode depnode = node; sb.append(node.toString().trim()); if (depnode.hasHead()) { sb.append('\t'); try { sb.append(depnode.getHead().getIndex()); sb.append('\t'); sb.append(depnode.getHeadEdge().toString()); } catch (MaltChainedException e) { System.err.println(e); } } sb.append('\n'); return sb.toString(); }
public String toStringTerminalNode(TokenNode node) { final StringBuilder sb = new StringBuilder(); final DependencyNode depnode = node; sb.append(node.toString().trim()); if (depnode.hasHead()) { sb.append('\t'); try { sb.append(depnode.getHead().getIndex()); sb.append('\t'); sb.append(depnode.getHeadEdge().toString()); } catch (MaltChainedException e) { System.err.println(e); } } sb.append('\n'); return sb.toString(); }
public void initialize() throws MaltChainedException { stack.push(dependencyGraph.getDependencyRoot()); for (int i = dependencyGraph.getHighestTokenIndex(); i > 0; i--) { final DependencyNode node = dependencyGraph.getDependencyNode(i); if (node != null && !node.hasHead()) { // added !node.hasHead() input.push(node); } } }
public void initialize() throws MaltChainedException { stack.push(dependencyGraph.getDependencyRoot()); for (int i = dependencyGraph.getHighestTokenIndex(); i > 0; i--) { final DependencyNode node = dependencyGraph.getDependencyNode(i); if (node != null && !node.hasHead()) { input.push(node); } } }
public DependencyNode getAncestor() throws MaltChainedException { if (!this.hasHead()) { return this; } DependencyNode tmp = this; while (tmp.hasHead()) { tmp = tmp.getHead(); } return tmp; }
public DependencyNode getAncestor() throws MaltChainedException { if (!this.hasHead()) { return this; } DependencyNode tmp = this; while (tmp.hasHead()) { tmp = tmp.getHead(); } return tmp; }
public void initialize() throws MaltChainedException { stack.push(dependencyGraph.getDependencyRoot()); for (int i = dependencyGraph.getHighestTokenIndex(); i > 0; i--) { final DependencyNode node = dependencyGraph.getDependencyNode(i); if (node != null && !node.hasHead()) { input.push(node); } } } /*
public DependencyNode getProperAncestor() throws MaltChainedException { if (!this.hasHead()) { return null; } DependencyNode tmp = this; while (tmp.hasHead()) { tmp = tmp.getHead(); } return tmp; }
public DependencyNode getProperAncestor() throws MaltChainedException { if (!this.hasHead()) { return null; } DependencyNode tmp = this; while (tmp.hasHead() && !tmp.isRoot()) { tmp = tmp.getHead(); } return tmp; }
public void initialize(ParserConfiguration parserConfiguration) throws MaltChainedException { if (parserConfiguration != null) { PlanarConfig planarConfig = (PlanarConfig)parserConfiguration; Stack<DependencyNode> sourceStack = planarConfig.getStack(); Stack<DependencyNode> sourceInput = planarConfig.getInput(); setDependencyGraph(planarConfig.getDependencyGraph()); for (int i = 0, n = sourceStack.size(); i < n; i++) { stack.add(dependencyGraph.getDependencyNode(sourceStack.get(i).getIndex())); } for (int i = 0, n = sourceInput.size(); i < n; i++) { input.add(dependencyGraph.getDependencyNode(sourceInput.get(i).getIndex())); } } else { stack.push(dependencyGraph.getDependencyRoot()); for (int i = dependencyGraph.getHighestTokenIndex(); i > 0; i--) { final DependencyNode node = dependencyGraph.getDependencyNode(i); if (node != null && !node.hasHead()) { input.push(node); } } } }
public boolean hasLabeledDependency(int index) throws MaltChainedException { return (getDependencyNode(index).hasHead() && getDependencyNode(index).getHeadEdge().isLabeled()); }
public boolean hasLabeledDependency(int index) throws MaltChainedException { return (getDependencyNode(index).hasHead() && getDependencyNode(index).getHeadEdge().isLabeled()); }
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 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."); } }
protected Edge moveDependencyEdge(DependencyNode newHead, DependencyNode dependent) throws MaltChainedException { if (dependent == null || !dependent.hasHead()) { return null; } Edge headEdge = dependent.getHeadEdge(); final LabelSet labels = checkOutNewLabelSet(); for (SymbolTable table : headEdge.getLabelTypes()) { labels.put(table, headEdge.getLabelCode(table)); } headEdge.clear(); headEdge.setBelongsToGraph(this); headEdge.setEdge((Node)newHead, (Node)dependent, Edge.DEPENDENCY_EDGE); headEdge.addLabel(labels); labels.clear(); checkInLabelSet(labels); return headEdge; }
/** * Copies the edges of the source dependency structure to the target dependency structure * * @param source a source dependency structure * @param target a target dependency structure * @throws MaltChainedException */ protected void copyEdges(DependencyStructure source, DependencyStructure target) throws MaltChainedException { for (int index : source.getTokenIndices()) { DependencyNode snode = source.getDependencyNode(index); if (snode.hasHead()) { Edge s = snode.getHeadEdge(); Edge t = target.addDependencyEdge(s.getSource().getIndex(), s.getTarget().getIndex()); for (SymbolTable table : s.getLabelTypes()) { t.addLabel(table, s.getLabelSymbol(table)); } } } }
public Edge moveDependencyEdge(DependencyNode newHead, DependencyNode dependent) throws MaltChainedException { if (dependent == null || !dependent.hasHead() || newHead.getBelongsToGraph() != this || dependent.getBelongsToGraph() != this) { return null; } Edge headEdge = dependent.getHeadEdge(); LabelSet labels = null; if (headEdge.isLabeled()) { labels = checkOutNewLabelSet(); for (SymbolTable table : headEdge.getLabelTypes()) { labels.put(table, headEdge.getLabelCode(table)); } } headEdge.clear(); headEdge.setBelongsToGraph(this); headEdge.setEdge((Node)newHead, (Node)dependent, Edge.DEPENDENCY_EDGE); if (labels != null) { headEdge.addLabel(labels); labels.clear(); checkInLabelSet(labels); } return headEdge; }
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); } }