comparing an classes of ontologies to an xml document nodes

走远了吗. 提交于 2019-12-11 17:46:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!