问题
My objective is to compare an ontology to a provided XML document by searching nodes from the document having the same name as the ontology classes. To do so, I use the following code :
public void freqConcept(String xmldoc,OWLClass node){
try {
String filepath = xmldoc;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
doc.getDocumentElement().normalize();
list = doc.getElementsByTagName(node.getIRI().getFragment());
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException sae) {
sae.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
As you can see I give to the function an OWLClass as a parameter, then I try to return nodes from the XML document having the same name by using this line: list = doc.getElementsByTagName(node.getIRI().getFragment());
It works for People Ontology since the previous line returns the name of classes as String. But I notice that classes from DBPedia when I try to return this node.getIRI().getFragment()
I get null instead of having names of classes, just for some classes not all of them. As result only classes with correct names are counted and stored in the list the others constitute the exception ...
The picture below shows the result.. just one classe SpatialThing is correctly returned for the others is null, can't understand why...
I'm wondering if there is a way to treat an OWLClass as a node or other possibility to compare the OWLClass with the xml document nodes ??
Thank you
回答1:
Some IRIs do not have fragments. This is by design and is described in the javadoc.
You'll have to find a few cases where this does not work, then find an example of the XML you wish to match. Then you might be able to find a solution.
来源:https://stackoverflow.com/questions/51612722/comparing-an-classes-of-ontologies-to-an-xml-document-nodes