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(); }
protected void copyDynamicInput(DependencyStructure source, DependencyStructure target) throws MaltChainedException { for (int index : source.getTokenIndices()) { DependencyNode snode = source.getDependencyNode(index); DependencyNode tnode = target.getDependencyNode(index); for (SymbolTable table : snode.getLabelTypes()) { if (!tnode.hasLabel(table)) { tnode.addLabel(table,snode.getLabelSymbol(table)); } } } } }
private DependencyNode findComponent(DependencyNode x) { if (x != x.getComponent()) { x.setComponent(findComponent(x.getComponent())); } return x.getComponent(); }
private boolean leftComplete(DependencyStructure gold, DependencyNode right) throws MaltChainedException { final DependencyNode goldNode = gold.getDependencyNode(right.getIndex()); if (!goldNode.hasLeftDependent()) { return true; } else if (!right.hasLeftDependent()) { return false; } else if (goldNode.getLeftmostDependent().getIndex() == right.getLeftmostDependent().getIndex()) { return true; } return false; }
if (subFunction == DGraphSubFunction.HEAD && !node.isRoot()) { address.setAddress(node.getHead()); } else if (subFunction == DGraphSubFunction.LDEP) { address.setAddress(node.getLeftmostDependent()); } else if (subFunction == DGraphSubFunction.RDEP) { address.setAddress(node.getRightmostDependent()); } else if (subFunction == DGraphSubFunction.RDEP2) { if (!node.isRoot()) { address.setAddress(node.getRightmostDependent()); } else { address.setAddress(null); address.setAddress(node.getSameSideLeftSibling()); } else if (subFunction == DGraphSubFunction.RSIB) { address.setAddress(node.getSameSideRightSibling()); } else if (subFunction == DGraphSubFunction.PRED && !node.isRoot()) { address.setAddress(node.getPredecessor()); } else if (subFunction == DGraphSubFunction.SUCC && !node.isRoot()) { address.setAddress(node.getSuccessor()); } else if (subFunction == DGraphSubFunction.ANC) { address.setAddress(node.getAncestor()); } else if (subFunction == DGraphSubFunction.PANC) { address.setAddress(node.getProperAncestor()); } else if (subFunction == DGraphSubFunction.LDESC) { address.setAddress(node.getLeftmostDescendant()); } else if (subFunction == DGraphSubFunction.PLDESC) { address.setAddress(node.getLeftmostProperDescendant()); } else if (subFunction == DGraphSubFunction.RDESC) {
DependencyNode child, possibleSyntacticHead; counter++; if (node.hasHead() && node.getHeadEdge().isLabeled() && nodeLifted.get(node.getIndex()) && nodePath.get(node.getIndex())) { possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.getHead(), node, synacticHeadDeprel.get(node .getIndex())); if (possibleSyntacticHead != null) { pdg.moveDependencyEdge(possibleSyntacticHead.getIndex(), node.getIndex()); nodeLifted.set(node.getIndex(), false); } else { success = false; if (node.hasHead() && node.getHeadEdge().isLabeled() && nodeLifted.get(node.getIndex())) { possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHeadAndPath(pdg, node.getHead(), node, synacticHeadDeprel.get(node .getIndex())); if (possibleSyntacticHead != null) { pdg.moveDependencyEdge(possibleSyntacticHead.getIndex(), node.getIndex()); nodeLifted.set(node.getIndex(), false); } else { success = false; Vector<DependencyNode> children = new Vector<DependencyNode>(); i = 0; while ((child = node.getLeftDependent(i)) != null) { children.add(child); i++; while ((child = node.getRightDependent(i)) != null) { children.add(child); i++;
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 isProjective() throws MaltChainedException { if (hasHead() && !getHead().isRoot()) { final DependencyNode head = getHead(); if (getHead().getIndex() < this.getIndex()) { DependencyNode terminals = head; DependencyNode tmp = null; while (true) { if (terminals == null || terminals.getSuccessor() == null) { return false; if (terminals.getSuccessor() == this) { break; tmp = terminals = terminals.getSuccessor(); while (tmp != this && tmp != head) { if (!tmp.hasHead()) { return false; tmp = tmp.getHead(); DependencyNode tmp = null; while (true) { if (terminals == null || terminals.getSuccessor() == null) { return false; if (terminals.getSuccessor() == head) { break; tmp = terminals = terminals.getSuccessor(); while (tmp != this && tmp != head) {
private void deattachCoveredRootsForDeprojectivization(DependencyStructure pdg) throws MaltChainedException { for (int index : pdg.getTokenIndices()) { if (pdg.getDependencyNode(index).getHeadEdge().hasLabel(deprelSymbolTable)) { if (pdg.getDependencyNode(index).getHeadEdge().hasLabel(ppcoveredRootSymbolTable) && ppcoveredRootSymbolTable.getSymbolCodeToString(pdg.getDependencyNode(index).getHeadEdge().getLabelCode(ppcoveredRootSymbolTable)).equals( "#true#")) { pdg.moveDependencyEdge(pdg.getDependencyRoot().getIndex(), pdg.getDependencyNode(index).getIndex()); } } } }
boolean foundCoveredRoot = false; DependencyNode coveredRootHead; for (i = Math.min(deepest.getIndex(), deepest.getHead().getIndex()) + 1; i < Math.max(deepest.getIndex(), deepest.getHead() .getIndex()); i++) { int leftMostIndex = pdg.getDependencyNode(i).getLeftmostProperDescendantIndex(); if (leftMostIndex == -1) { leftMostIndex = i; int rightMostIndex = pdg.getDependencyNode(i).getRightmostProperDescendantIndex(); if (rightMostIndex == -1) { rightMostIndex = i; if (!nodeLifted.get(i) && pdg.getDependencyNode(i).getHead().isRoot() && !deepest.getHead().isRoot() && Math.min(deepest.getIndex(), deepest.getHead().getIndex()) < leftMostIndex && rightMostIndex < Math.max(deepest.getIndex(), deepest.getHead().getIndex())) { if (rootAttachment == CoveredRootAttachment.LEFT) { if (deepest.getHead().getIndex() < deepest.getIndex()) { coveredRootHead = deepest.getHead(); } else { coveredRootHead = deepest; if (deepest.getIndex() < deepest.getHead().getIndex()) { coveredRootHead = deepest.getHead(); } else { coveredRootHead = deepest; coveredRootHead = deepest.getHead(); pdg.moveDependencyEdge(coveredRootHead.getIndex(), pdg.getDependencyNode(i).getIndex());
private int createSwapArray(DependencyNode n, int order) { int o = order; if (n != null) { for (int i=0; i < n.getLeftDependentCount(); i++) { o = createSwapArray(n.getLeftDependent(i), o); } swapArray.set(n.getIndex(), o++); for (int i=n.getRightDependentCount(); i >= 0; i--) { o = createSwapArray(n.getRightDependent(i), o); } } return o; } }
sb.append(tokens[index -1]); sb.append('\t'); sb.append(node.getHead().getIndex()); sb.append('\t'); if (node.getHeadEdge().hasLabel(deprelTable)) { sb.append(node.getHeadEdge().getLabelSymbol(deprelTable)); } else { sb.append(outputGraph.getDefaultRootEdgeLabelSymbol(deprelTable));
if (((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHead()) { writer.write(Integer.toString(((DependencyStructure)syntaxGraph).getDependencyNode(i).getHead().getIndex())); } else { writer.write(Integer.toString(0)); if (((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHead() && ((DependencyStructure)syntaxGraph).getDependencyNode(i).hasHeadEdgeLabel(symbolTables.getSymbolTable(column.getName()))) { output.append(((DependencyStructure)syntaxGraph).getDependencyNode(i).getHeadEdgeLabelSymbol(symbolTables.getSymbolTable(column.getName()))); } else { output.append(((DependencyStructure)syntaxGraph).getDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(column.getName())));
if (rc == right.getIndex()) { return false; if (gold.getDependencyNode(node.getIndex()).getHead().getIndex() == right.getIndex()) { return !leftComplete(gold, node); if (gold.getDependencyNode(right.getIndex()).getHead().getIndex() == node.getIndex()) { if (gold.getDependencyNode(right.getIndex()).hasRightDependent()) { rc = gold.getDependencyNode(right.getIndex()).getRightmostProperDescendantIndex();
String syntacticHeadDeprel; counter++; if (nodeLifted.get(node.getIndex())) { syntacticHeadDeprel = synacticHeadDeprel.get(node.getIndex()); possibleSyntacticHead = breadthFirstSearchSortedByDistanceForHead(pdg, node.getHead(), node, syntacticHeadDeprel); if (possibleSyntacticHead != null) { pdg.moveDependencyEdge(possibleSyntacticHead.getIndex(), node.getIndex()); nodeLifted.set(node.getIndex(), false); } else { success = false; Vector<DependencyNode> children = new Vector<DependencyNode>(); i = 0; while ((child = node.getLeftDependent(i)) != null) { children.add(child); i++; while ((child = node.getRightDependent(i)) != null) { children.add(child); i++;
if ( activeStackPeek.isRoot() ) return false; if ( activeStackPeek.hasHead() && singleHeadConstraint ) return false; if ( activeStackPeek.hasHead() && dg.getTokenNode(activeStackPeek.getIndex()).getHead().getIndex() == inputPeek.getIndex() ) return false; if ( acyclicityConstraint && activeStackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() ) return false; if ( inputPeek.hasHead() && singleHeadConstraint ) return false; if ( inputPeek.hasHead() && dg.getTokenNode(inputPeek.getIndex()).getHead().getIndex() == activeStackPeek.getIndex() ) return false; if ( acyclicityConstraint && activeStackPeek.findComponent().getIndex() == inputPeek.findComponent().getIndex() ) return false; if ( activeStackPeek.isRoot() ) return false; if ( !activeStackPeek.hasHead() && noCoveredRootsConstraint ) return false; if ( activeStackPeek.isRoot() || inactiveStackPeek.isRoot() ) return false;
private boolean projectiveInterval(DependencyStructure parse, DependencyNode left, DependencyNode right) throws MaltChainedException { final int l = swapArray.get(left.getIndex()); final int r = swapArray.get(right.getIndex()); DependencyNode node = null; if (l > r) { return false; } else { for (int i = l + 1; i < r; i++) { for (int j = 0; j < swapArray.size(); j++) { if (swapArray.get(j) == i) { node = parse.getDependencyNode(j); break; } } while (node.hasHead()) { node = node.getHead(); } if (!(node == left || node == right)) { return false; } } return true; } }