private void labelDependencyEdge(MappablePhraseStructureGraph graph, Edge e, PhraseStructureNode top) throws MaltChainedException {
if (e == null) {
return;
}
SymbolTableHandler symbolTables = graph.getSymbolTables();
deprel.setLength(0);
phrase.setLength(0);
headrel.setLength(0);
e.removeLabel(symbolTables.getSymbolTable(DEPREL));
e.removeLabel(symbolTables.getSymbolTable(HEADREL));
e.removeLabel(symbolTables.getSymbolTable(PHRASE));
e.removeLabel(symbolTables.getSymbolTable(ATTACH));
int i = 0;
SortedMap<String, SymbolTable> edgeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureEdgeLabelSymbolTables();
SortedMap<String, SymbolTable> nodeLabelSymbolTables = phraseStructuretDataFormatInstance.getPhraseStructureNodeLabelSymbolTables();
if (!top.isRoot()) {
for (String name : edgeLabelSymbolTables.keySet()) {
if (top.hasParentEdgeLabel(symbolTables.getSymbolTable(name))) {
deprel.append(top.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
} else {
deprel.append(EMPTY_LABEL);
}
i++;
if (i < edgeLabelSymbolTables.size()) {
deprel.append(LABEL_ELEMENT_SEPARATOR);
}
}
if (deprel.length() != 0) {
e.addLabel(symbolTables.getSymbolTable(DEPREL), deprel.toString());
}
} else {
String deprelDefaultRootLabel = graph.getDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(DEPREL));
if (deprelDefaultRootLabel != null) {
e.addLabel(symbolTables.getSymbolTable(DEPREL), deprelDefaultRootLabel);
} else {
e.addLabel(symbolTables.getSymbolTable(DEPREL), EMPTY_LABEL);
}
}
PhraseStructureNode tmp = (PhraseStructureNode)e.getTarget();
while (tmp != top && tmp.getParent() != null) { // && !tmp.getParent().isRoot()) {
i=0;
for (String name : edgeLabelSymbolTables.keySet()) {
if (tmp.hasParentEdgeLabel(symbolTables.getSymbolTable(name))) {
headrel.append(tmp.getParentEdgeLabelSymbol(symbolTables.getSymbolTable(name)));
} else {
headrel.append(EMPTY_LABEL);
}
i++;
if (i < edgeLabelSymbolTables.size()) {
headrel.append(LABEL_ELEMENT_SEPARATOR);
}
}
i=0;
headrel.append(SPINE_ELEMENT_SEPARATOR);
for (String name : nodeLabelSymbolTables.keySet()) {
if (tmp.getParent().hasLabel(symbolTables.getSymbolTable(name))) {
phrase.append(tmp.getParent().getLabelSymbol(symbolTables.getSymbolTable(name)));
} else {
if (tmp.getParent().isRoot()) {
String deprelDefaultRootLabel = graph.getDefaultRootEdgeLabelSymbol(symbolTables.getSymbolTable(PHRASE));
if (deprelDefaultRootLabel != null) {
phrase.append(deprelDefaultRootLabel);
} else {
phrase.append(EMPTY_LABEL);
}
} else {
phrase.append(EMPTY_LABEL);
}
}
i++;
if (i < nodeLabelSymbolTables.size()) {
phrase.append(LABEL_ELEMENT_SEPARATOR);
}
}
phrase.append(SPINE_ELEMENT_SEPARATOR);
tmp = tmp.getParent();
}
if (phrase.length() == 0) {
headrel.append(EMPTY_SPINE);
phrase.append(EMPTY_SPINE);
} else {
headrel.setLength(headrel.length()-1);
phrase.setLength(phrase.length()-1);
}
e.addLabel(symbolTables.getSymbolTable(HEADREL), headrel.toString());
e.addLabel(symbolTables.getSymbolTable(PHRASE), phrase.toString());
int a = 0;
tmp = (PhraseStructureNode)e.getSource();
while (top.getParent() != null && tmp.getParent() != null && tmp.getParent() != top.getParent()) {
a++;
tmp = tmp.getParent();
}
e.addLabel(symbolTables.getSymbolTable(ATTACH), Integer.toString(a));
}