if (syntaxGraph == null || !(syntaxGraph instanceof PhraseStructure)) {
return false;
}
syntaxGraph.clear();
final PhraseStructure phraseStructure = (PhraseStructure)syntaxGraph;
PhraseStructureNode parent = null;
PhraseStructureNode child = null;
// if (header == null) {
// header = new TigerXMLHeader(syntaxGraph.getSymbolTables());
// }
try {
while (true) {
int event = reader.next();
if (event == XMLStreamConstants.START_ELEMENT) {
if (reader.getLocalName().length() == 0) {
continue;
}
if (reader.getLocalName().charAt(0) == 'e') {
// e -> edge, edgelabel
if (reader.getLocalName().length() == 4) { //edge
int childid = -1;
int indexSep = reader.getAttributeValue(null, "idref").indexOf('_');
try {
if (indexSep != -1) {
childid = Integer.parseInt(reader.getAttributeValue(null, "idref").substring(indexSep+1));
} else {
childid = Integer.parseInt(reader.getAttributeValue(null, "idref"));
}
if (childid == -1) {
throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '"+reader.getAttributeValue(null, "idref")+"' of the edge element. ");
}
} catch (NumberFormatException e) {
throw new SyntaxGraphException("The tiger reader couldn't recognize the idref attribute '"+reader.getAttributeValue(null, "idref")+"' of the edge element. ");
}
if (childid < START_ID_OF_NONTERMINALS) {
child = phraseStructure.getTokenNode(childid);
} else {
child = phraseStructure.getNonTerminalNode(childid-START_ID_OF_NONTERMINALS+1);
}
Edge e = phraseStructure.addPhraseStructureEdge(parent, child);
SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureEdgeLabelSymbolTables();
for (String name : inputTables.keySet()) {
e.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
}
} else if (reader.getLocalName().equals("edgelabel")) { // edgelabel
// domain = Domain.EL;
}
} else if (reader.getLocalName().charAt(0) == 'n') {
// n -> nt, nonterminals, name
if (reader.getLocalName().length() == 2) { // nt
final String id = reader.getAttributeValue(null, "id");
if (graphRootID.length() == id.length() && graphRootID.toString().equals(id)) {
parent = phraseStructure.getPhraseStructureRoot();
} else {
int index = id.indexOf('_');
if (index != -1) {
parent = phraseStructure.addNonTerminalNode(Integer.parseInt(id.substring(index+1))-START_ID_OF_NONTERMINALS+1);
}
}
SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getPhraseStructureNodeLabelSymbolTables();
for (String name : inputTables.keySet()) {
parent.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
}
} else if (reader.getLocalName().equals("name")) { // name
// elementContent.setLength(0);
// collectChar = true;
}
} else if (reader.getLocalName().charAt(0) == 't') {
// t -> t, terminals
if (reader.getLocalName().length() == 1) { // t
SortedMap<String, SymbolTable> inputTables = dataFormatInstance.getInputSymbolTables();
child = syntaxGraph.addTokenNode();
for (String name : inputTables.keySet()) {
child.addLabel(inputTables.get(name), reader.getAttributeValue(null, name.toLowerCase()));
}
}
} else if (reader.getLocalName().charAt(0) == 's') {
// s -> subcorpus, secedge, s, secedgelabel
if (reader.getLocalName().length() == 1) { // s