use of javax.xml.stream.events.EndElement in project jvarkit by lindenb.
the class DiseaseOntoglogyTree method parseTerm.
private void parseTerm(StartElement root, XMLEventReader r) throws IOException, XMLStreamException {
Attribute aboutAtt = root.getAttributeByName(rdfAbout);
if (aboutAtt == null) {
throw new IOException("no rdf:about");
}
TermImpl term = uri2term.get(aboutAtt.getValue());
if (term == null) {
term = new TermImpl();
term.accession = aboutAtt.getValue();
if (term.accession.startsWith(OBO)) {
term.accession = term.accession.substring(OBO.length()).replace('_', ':');
}
term.name = term.accession;
uri2term.put(aboutAtt.getValue(), term);
}
while (r.hasNext()) {
XMLEvent evt = r.nextEvent();
if (evt.isStartElement()) {
StartElement E = evt.asStartElement();
QName qN = E.getName();
if (OBOINOWL.equals(qN.getNamespaceURI())) {
if (qN.getLocalPart().equals("id")) {
term.accession = r.getElementText();
}
} else if (RDFS.equals(qN.getNamespaceURI())) {
if (qN.getLocalPart().equals("label")) {
term.name = r.getElementText();
} else if (qN.getLocalPart().equals("subClassOf")) {
Attribute rsrc = E.getAttributeByName(rdfRsrc);
if (rsrc == null)
throw new IOException("att missing " + rdfRsrc + " for " + aboutAtt.getValue());
String parentUri = rsrc.getValue();
term.parents.add(parentUri);
TermImpl parentTerm = this.uri2term.get(parentUri);
if (parentTerm == null) {
parentTerm = new TermImpl();
parentTerm.accession = parentUri;
if (parentTerm.accession.startsWith(OBO)) {
parentTerm.accession = parentTerm.accession.substring(OBO.length()).replace('_', ':');
}
parentTerm.name = parentTerm.accession;
uri2term.put(parentUri, parentTerm);
}
parentTerm.children.add(aboutAtt.getValue());
}
}
} else if (evt.isEndElement()) {
EndElement E = evt.asEndElement();
QName qN = E.getName();
if (qN.getLocalPart().equals("Class") && OWL.equals(qN.getNamespaceURI())) {
break;
}
}
}
}
Aggregations