【问题标题】:why rdf:type doesn't work with father classes?为什么 rdf:type 不适用于父类?
【发布时间】:2016-02-04 15:35:10
【问题描述】:

在我的门徒中,我明确声明 Symphony 类是 Recommendable 类的子类,如下所示: Classes Hierarchy

我还向 Symphony 类添加了一些实例,当我查询 Symphony 实例时,我得到了结果。但是,当我查询 Recommendable 实例时,我什么也得不到。

这是 Symphony 类的查询:

SELECT DISTINCT  ?subject   WHERE {
  ?subject rdf:type owbes:Symphony
}

结果如下: Symphony instances query result

这是 Recommendable 类的查询。

SELECT DISTINCT  ?subject   WHERE {
  ?subject rdf:type owbes:Recommendable
}

如您在此处看到的,此结果为空 [推荐实例查询结果][3]

两者都来自相同的前缀。我做错了什么?

这是 owl 文件中生成的内容:

<owl:Class rdf:about="bla bla bla/recommendation-systems#Symphony">
    <rdfs:subClassOf rdf:resource="bla bla bla/recommendation-systems#Recommendable"/>
</owl:Class>

如您所见,我正确地将 Symphony 设为 Recommendable 的子类

我找到了解决方案: 进行此查询可以解决问题

SELECT   ?subject   WHERE {
  ?subject rdf:type ?type.
  ?type rdfs:subClassOf owbes:Recommendable
}

但是,我不知道为什么 rdf:type 不起作用

<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/welovethesemanticweb#"
     xml:base="http://www.semanticweb.org/welovethesemanticweb"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:recommendation-systems="http://www.welovethesemanticweb.com/recommendation-systems#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/welovethesemanticweb"/>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Annotation properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.welovethesemanticweb.com/recommendation-systems#hasSimilarityValue -->

    <owl:AnnotationProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#hasSimilarityValue"/>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Object Properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.welovethesemanticweb.com/recommendation-systems#composedBy -->

    <owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#composedBy">
        <rdfs:subPropertyOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#hasArtist"/>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
        <rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
        <rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Composed By</rdfs:label>
    </owl:ObjectProperty>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#fromEra -->

    <owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#fromEra">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
        <rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Describes the musical era that music is from</rdfs:label>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">From Era</rdfs:label>
        <recommendation-systems:hasSimilarityValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.1</recommendation-systems:hasSimilarityValue>
    </owl:ObjectProperty>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#hasArtist -->

    <owl:ObjectProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#hasArtist">
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#IrreflexiveProperty"/>
        <rdfs:domain rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <rdfs:range rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <rdfs:comment>Describes the arties of the music</rdfs:comment>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Has Artist</rdfs:label>
        <recommendation-systems:hasSimilarityValue rdf:datatype="http://www.w3.org/2001/XMLSchema#double">0.4</recommendation-systems:hasSimilarityValue>
    </owl:ObjectProperty>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Data properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.welovethesemanticweb.com/recommendation-systems#contributeToSimilarities -->

    <owl:DatatypeProperty rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#contributeToSimilarities">
        <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    </owl:DatatypeProperty>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Artist -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Artist">
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Composer -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Composer">
        <rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra">
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Recommendable -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable">
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Singer -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Singer">
        <rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Song"/>
        <owl:disjointWith rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Song -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Song">
        <rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
    </owl:Class>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Symphony -->

    <owl:Class rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Symphony">
        <rdfs:subClassOf rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
    </owl:Class>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Individuals
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Adele -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Adele">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Singer"/>
        <recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#current"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Beethoven -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
        <recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Dies_Irae -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Dies_Irae">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
        <recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Dies Irae</rdfs:label>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Le_nozze_di_Figaro -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Le_nozze_di_Figaro">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
        <recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Le Nozze Di Digaro</rdfs:label>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Mozart -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Mozart">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Artist"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Composer"/>
        <recommendation-systems:fromEra rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#baroque -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#baroque">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#classical -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#classical">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#current -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#current">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#romantic -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#romantic">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#MusicalEra"/>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#5th_Symphony -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#5th_Symphony">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
        <recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven"/>
        <recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Beethoven"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">5th Symphony</rdfs:label>
    </owl:NamedIndividual>



    <!-- http://www.welovethesemanticweb.com/recommendation-systems#Requiem:_Sequentia -->

    <owl:NamedIndividual rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#Requiem:_Sequentia">
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Recommendable"/>
        <rdf:type rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Symphony"/>
        <recommendation-systems:composedBy rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <recommendation-systems:hasArtist rdf:resource="http://www.welovethesemanticweb.com/recommendation-systems#Mozart"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Requiem Sequentia</rdfs:label>
    </owl:NamedIndividual>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // General axioms
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->

    <rdf:Description>
        <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AllDifferent"/>
        <owl:distinctMembers rdf:parseType="Collection">
            <rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#baroque"/>
            <rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#classical"/>
            <rdf:Description rdf:about="http://www.welovethesemanticweb.com/recommendation-systems#romantic"/>
        </owl:distinctMembers>
    </rdf:Description>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.1.3.20151118-2017) https://github.com/owlcs/owlapi -->

【问题讨论】:

  • 这是推荐实例查询结果的结果([3]:i.stack.imgur.com/griJp.png)我无法在问题中发布它,因为我没有足够的点来发布两个以上的图像
  • 图片没有出现,因为我没有足够的积分。但是,如果您单击它们,您会看到它们。感谢您的帮助!

标签: rdf semantic-web owl ontology protege4


【解决方案1】:

当类 C 被声明为类 D 的子类时,您可以推断 C 的实例也是 D 的实例。但是,推断过程是您需要的推理者。如果您不使用推理器,则不会自动获得该结果。简而言之,您要求的是三倍的形式

?subject rdf:type owbes:Recommendable

但这不在数据中。数据中有两个三元组:

?subject rdf:type owbes:Symphony  
owbes:Symphony rdfs:subClassOf owbes:Recommendable

在这种情况下,您实际上可以通过使用带有属性路径的 SPARQL 查询来获取;你不需要一个完整的推理者。您可以使用这样的查询:

select ?subject where {
    ?subject rdf:type/rdfs:subClassOf* owbes:Recommendable
}

这表示要查找类型与 owbes: 相关的主题:可通过 rdfs:subClassOf 属性链(可能长度为零)推荐。在实践中,这意味着要找到属于 owbes:Recommendable 或其子类之一的 ?subjects。

有关更多信息,请参阅:

【讨论】:

  • 好吧,谢谢,但是我该如何使用推理器呢?我所做的是:在我的原型中,我创建了本体,然后单击启动推理器(并选择推理器),然后以 OWL 格式保存(提取)本体。然后我打开 fuseki 并将那个 owl 文件上传到它。请问我应该怎么做才能提取推断数据?还是我必须启用 Fuseki 中的某些功能?
  • @AniaDavid “因为它是一个 sparql 端点,所以它应该支持推理,你怎么看?” 一点也不。 SPARQL 是一种RDF 查询语言。 RDF 只是一堆三元组。 SPARQL 端点所要做的就是让您搜索三元组。不需要任何推理。
  • @AniaDavid 也就是说,您可以配置 Fuseki 使用推理器,但这是一个完全不同的问题。最好的参考是文档。
  • 您好,现在可以使用了。我的错误是,当我在 protoge 中更改 Ontology 的 URI 时,我没有在 Fuseki 中这样做。对不起。现在它正在工作。我将尝试研究如何在 Fuseki 上启用推理器。感谢您的帮助和支持。我非常重视这一点。
猜你喜欢
  • 1970-01-01
  • 2014-10-04
  • 2020-03-09
  • 2015-04-23
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 2021-12-24
相关资源
最近更新 更多