es = j = j + 1;
}
}
// Recursively attach the dependent spines to target node.
DependencyNode target = (DependencyNode)depEdge.getTarget();
for (int i = 0; i < target.getLeftDependentCount(); i++) {
updatePhraseStructureGraph(graph, target.getLeftDependent(i).getHeadEdge(), attachHeadSpineToRoot);
}
for (int i = target.getRightDependentCount()-1; i >= 0 ; i--) {
updatePhraseStructureGraph(graph, target.getRightDependent(i).getHeadEdge(), attachHeadSpineToRoot);
}
} else {
// If dependent spine already exist, then set dependentSpine to the highest nonterminal
// of the dependent spine.
while (dependentSpine.getParent() != null && !dependentSpine.getParent().isRoot()) {
dependentSpine = dependentSpine.getParent();
}
}
PhraseStructureNode headSpine = null;
if (((PhraseStructureNode)depEdge.getSource()).getParent() != null) {
// If head spine exist, then attach dependent spine to the head spine at the attachment level a.
int a = 0;
headSpine = ((PhraseStructureNode)depEdge.getSource()).getParent();
if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(ATTACH))) {
try {
a = Integer.parseInt((depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(ATTACH))));
} catch (NumberFormatException e) {
throw new MaltChainedException(e.getMessage());
}
}
for (int i = 0; i < a && headSpine != null; i++) {
headSpine = headSpine.getParent();
}
if ((headSpine == null || headSpine == dependentSpine) && attachHeadSpineToRoot) {
headSpine = graph.getPhraseStructureRoot();
}
if (headSpine != null) {
lockUpdate = true;
Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)).equals(EMPTY_LABEL) & e != null) {
e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
}
lockUpdate = false;
}
}
else if (depEdge.getSource().isRoot() && !depEdge.isLabeled()) {
headSpine = graph.getPhraseStructureRoot();
lockUpdate = true;
Edge e = graph.addPhraseStructureEdge(headSpine, dependentSpine);
if (depEdge.hasLabel(graph.getSymbolTables().getSymbolTable(DEPREL)) && !depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)).equals(EMPTY_LABEL) & e != null) {
e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), depEdge.getLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
} else {
e.addLabel(graph.getSymbolTables().addSymbolTable(EDGELABEL), graph.getDefaultRootEdgeLabelSymbol(graph.getSymbolTables().getSymbolTable(DEPREL)));
}
lockUpdate = false;
// Recursively attach the dependent spines to target node.
DependencyNode target = (DependencyNode)depEdge.getTarget();
for (int i = 0; i < target.getLeftDependentCount(); i++) {
updatePhraseStructureGraph(graph, target.getLeftDependent(i).getHeadEdge(), attachHeadSpineToRoot);
}
for (int i = target.getRightDependentCount()-1; i >= 0 ; i--) {
updatePhraseStructureGraph(graph, target.getRightDependent(i).getHeadEdge(), attachHeadSpineToRoot);
}
}
}