将本体类与xml文档节点进行比较 [英] comparing an classes of ontologies to an xml document nodes

查看:105
本文介绍了将本体类与xml文档节点进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是通过从文档中搜索与本体类同名的节点来将本体与提供的XML文档进行比较.为此,我使用以下代码:

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();
        }
    }

如您所见,我给函数提供了一个OWLClass作为参数,然后我尝试使用此行从具有相同名称的XML文档返回节点:list = doc.getElementsByTagName(node.getIRI().getFragment()); 它适用于People Ontology,因为上一行将类的名称返回为String.但是我注意到,当我尝试返回此node.getIRI().getFragment()时,来自DBPedia的类得到的是 null ,而不是具有类名,仅针对某些类而不是全部.结果,只有具有正确名称的类才被计数并存储在列表中,其他类构成例外...

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 ...

下面的图片显示了结果..仅正确地返回了一个类 SpatialThing ,其他类为null,无法理解为什么...

The picture below shows the result.. just one classe SpatialThing is correctly returned for the others is null, can't understand why...

我想知道是否有一种方法可以将OWLClass视为节点,或者是否可以将OWLClass与xml文档节点进行比较?

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 ??

谢谢

推荐答案

某些IRI没有片段.这是设计使然,并在javadoc中进行了描述.

Some IRIs do not have fragments. This is by design and is described in the javadoc.

您将不得不找出一些无法解决的情况,然后找到您想要匹配的XML的示例.然后,您也许可以找到解决方案.

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.

这篇关于将本体类与xml文档节点进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆