【问题标题】:SPARQL query not displaying resultsSPARQL 查询不显示结果
【发布时间】:2015-03-12 16:55:04
【问题描述】:

我对语义 Web 编程非常陌生。我有一个 OWL 文件,我已在 URI http://myexample.com 处加载到 Virtuoso 服务器中。现在,当我打开 Virtuoso SPARQL 查询编辑器 (http://localhost:8890/sparql) 并运行以下查询时,我没有得到任何结果:

SELECT ?class FROM <myexample.com> WHERE{?class a owl:class} Order By ?class

这是我的 OWL 文件:

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl2xml "http://www.w3.org/2006/12/owl2-xml#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<!ENTITY Antibiotics "http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#" >
<!ENTITY Antibiotics2 "http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#2" >
<!ENTITY Antibiotics3 "http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#1" >
<!ENTITY Antibiotics4 "http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#3" >
<!ENTITY Traveler "http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Traveler&#39;" >
]>


<rdf:RDF xmlns="http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#"
     xml:base="http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#"
     xmlns:Antibiotics2="&Antibiotics;2"
     xmlns:Traveler="&Antibiotics;Traveler&#39;"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:Antibiotics="http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#"
     xmlns:Antibiotics3="&Antibiotics;1"
     xmlns:Antibiotics4="&Antibiotics;3">
    <owl:Ontology rdf:about=""/>



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




    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#cures_disease -->

    <owl:ObjectProperty rdf:about="#cures_disease">
        <rdfs:label>cures_disease</rdfs:label>
        <rdfs:domain rdf:resource="#Antibiotics"/>
        <rdfs:range rdf:resource="#Diseases"/>
    </owl:ObjectProperty>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#has_SideEffects -->

    <owl:ObjectProperty rdf:about="#has_SideEffects">
        <rdfs:label>has_SideEffects</rdfs:label>
        <rdfs:domain rdf:resource="#Antibiotics"/>
        <rdfs:range rdf:resource="#SideEffects"/>
    </owl:ObjectProperty>



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




    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#1st_Generation -->

    <owl:Class rdf:about="#1st_Generation">
        <rdfs:label>1st_Generation</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#2nd_Generation -->

    <owl:Class rdf:about="#2nd_Generation">
        <rdfs:label>2nd_Generation</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#3rd_Generation -->

    <owl:Class rdf:about="#3rd_Generation">
        <rdfs:label>3rd_Generation</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Aminopenicillins -->

    <owl:Class rdf:about="#Aminopenicillins">
        <rdfs:label
            >Aminopenicillins</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Antibiotics -->

    <owl:Class rdf:about="#Antibiotics">
        <rdfs:label>Antibiotics</rdfs:label>
        <rdfs:subClassOf rdf:resource="&owl;Thing"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Diseases -->

    <owl:Class rdf:about="#Diseases">
        <rdfs:label>Diseases</rdfs:label>
        <rdfs:subClassOf rdf:resource="&owl;Thing"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Lincosamide -->

    <owl:Class rdf:about="#Lincosamide">
        <rdfs:label>Lincosamide</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#SideEffects -->

    <owl:Class rdf:about="#SideEffects">
        <rdfs:label>SideEffects</rdfs:label>
        <rdfs:subClassOf rdf:resource="&owl;Thing"/>
    </owl:Class>



    <!-- http://www.w3.org/2002/07/owl#Thing -->

    <owl:Class rdf:about="&owl;Thing"/>



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




    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Acne -->

    <Diseases rdf:about="#Acne">
        <rdf:type rdf:resource="&owl;Thing"/>
        <rdfs:label>Acne</rdfs:label>
    </Diseases>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Allergic_Reactions -->

    <owl:Thing rdf:about="#Allergic_Reactions">
        <rdf:type rdf:resource="#SideEffects"/>
        <rdfs:label
            >Allergic_Reactions</rdfs:label>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Amoxicillin -->

    <owl:Thing rdf:about="#Amoxicillin">
        <rdf:type rdf:resource="#Aminopenicillins"/>
        <rdfs:label>Amoxicillin</rdfs:label>
        <has_SideEffects rdf:resource="#Diarrhea"/>
        <cures_disease rdf:resource="#Wide_Range_Of_Infections"/>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Cefalexin -->

    <owl:Thing rdf:about="#Cefalexin">
        <rdf:type rdf:resource="#1st_Generation"/>
        <rdfs:label>Cephalexin</rdfs:label>
        <cures_disease rdf:resource="#Gram_positive_infections"/>
        <has_SideEffects rdf:resource="#Nausea"/>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Cefazolin -->

    <Antibiotics3:st_Generation rdf:about="#Cefazolin">
        <rdf:type rdf:resource="&owl;Thing"/>
        <rdfs:label>Cefazolin</rdfs:label>
        <has_SideEffects rdf:resource="#Allergic_Reactions"/>
        <cures_disease rdf:resource="#Gram_positive_infections"/>
    </Antibiotics3:st_Generation>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Cefepime -->

    <owl:Thing rdf:about="#Cefepime">
        <rdf:type rdf:resource="#3rd_Generation"/>
        <rdfs:label>Cefepime</rdfs:label>
        <has_SideEffects rdf:resource="#Nausea"/>
        <cures_disease rdf:resource="#Pseudomonal_Infections"/>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Cefoxitin -->

    <Antibiotics2:nd_Generation rdf:about="#Cefoxitin">
        <rdf:type rdf:resource="&owl;Thing"/>
        <rdfs:label>Cefoxitin</rdfs:label>
        <has_SideEffects rdf:resource="#Allergic_Reactions"/>
        <cures_disease rdf:resource="#Gram_negative_cover"/>
    </Antibiotics2:nd_Generation>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Clindamycin -->

    <owl:Thing rdf:about="#Clindamycin">
        <rdf:type rdf:resource="#Lincosamide"/>
        <rdfs:label>Clindamycin</rdfs:label>
        <cures_disease rdf:resource="#Acne"/>
        <has_SideEffects rdf:resource="#Diarrhea"/>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Diarrhea -->

    <owl:Thing rdf:about="#Diarrhea">
        <rdf:type rdf:resource="#SideEffects"/>
        <rdfs:label>Diarrhea</rdfs:label>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Gastrointestinal_Upset -->

    <SideEffects rdf:about="#Gastrointestinal_Upset">
        <rdf:type rdf:resource="&owl;Thing"/>
        <rdfs:label
            >Gastrointestinal_Upset</rdfs:label>
    </SideEffects>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Gram_negative_cover -->

    <owl:Thing rdf:about="#Gram_negative_cover">
        <rdf:type rdf:resource="#Diseases"/>
        <rdfs:label
            >Gram_negative_cover</rdfs:label>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Gram_positive_infections -->

    <owl:Thing rdf:about="#Gram_positive_infections">
        <rdf:type rdf:resource="#Diseases"/>
        <rdfs:label
            >Gram_positive_infections</rdfs:label>
        <cures_disease rdf:resource="#Gram_positive_infections"/>
        <has_SideEffects rdf:resource="#Nausea"/>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Nausea -->

    <owl:Thing rdf:about="#Nausea">
        <rdf:type rdf:resource="#SideEffects"/>
        <rdfs:label>Nausea</rdfs:label>
    </owl:Thing>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Pseudomonal_Infections -->

    <Diseases rdf:about="#Pseudomonal_Infections">
        <rdf:type rdf:resource="&owl;Thing"/>
        <rdfs:label
            >Pseudomonal_Infections</rdfs:label>
    </Diseases>



    <!-- http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Wide_Range_Of_Infections -->

    <owl:Thing rdf:about="#Wide_Range_Of_Infections">
        <rdf:type rdf:resource="#Diseases"/>
        <rdfs:label
            >Wide_Range_Of_Infections</rdfs:label>
    </owl:Thing>



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

    <rdf:Description>
        <rdf:type rdf:resource="&owl;AllDisjointClasses"/>
        <owl:members rdf:parseType="Collection">
            <rdf:Description rdf:about="#Antibiotics"/>
            <rdf:Description rdf:about="#Diseases"/>
            <rdf:Description rdf:about="#SideEffects"/>
        </owl:members>
    </rdf:Description>
    <rdf:Description>
        <rdf:type rdf:resource="&owl;AllDisjointClasses"/>
        <owl:members rdf:parseType="Collection">
            <rdf:Description rdf:about="#1st_Generation"/>
            <rdf:Description rdf:about="#2nd_Generation"/>
            <rdf:Description rdf:about="#3rd_Generation"/>
            <rdf:Description rdf:about="#Aminopenicillins"/>
            <rdf:Description rdf:about="#Lincosamide"/>
        </owl:members>
    </rdf:Description>
</rdf:RDF>



<!-- Generated by the OWL API (version 2.2.1.1138) http://owlapi.sourceforge.net -->

【问题讨论】:

    标签: sparql owl virtuoso


    【解决方案1】:

    IRI 区分大小写。请注意,在您的本体中 owl:Class 使用了一个 majuscule C:

    <owl:Class rdf:about="#1st_Generation">
        <rdfs:label>1st_Generation</rdfs:label>
        <rdfs:subClassOf rdf:resource="#Antibiotics"/>
    </owl:Class>
    

    在您的 SPARQL 查询中也需要如此。而且,如果您在其他地方没有,则需要定义前缀。如果您将数据存储在名为 http://myexample.com 的图表中,那么您可能需要准确地使用 from 从中进行选择。不要删除 http:// 前缀。我下载了你的数据,这个查询产生了以下结果:

    prefix owl: <http://www.w3.org/2002/07/owl#>
    
    select ?class where {
      ?class a owl:Class
    }
    
    ---------------------------------------------------------------------------------------------
    | class                                                                                     |
    =============================================================================================
    | owl:Thing                                                                                 |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#SideEffects>      |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Lincosamide>      |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Diseases>         |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Antibiotics>      |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#Aminopenicillins> |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#3rd_Generation>   |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#2nd_Generation>   |
    | <http://www.semanticweb.org/uthejsree/ontologies/2014/8/Antibiotics.owl#1st_Generation>   |
    ---------------------------------------------------------------------------------------------
    

    【讨论】:

    • 它仍然没有给我任何结果。
    • 我保存了您的数据并针对它运行了 SPARQL 查询并得到了我所显示的结果。您查询中的 FROM &lt;myexample.com&gt; 是可疑的。如果您有一个名为http://myexample.com 的图表,那么您将使用FROM &lt;http://myexample.com&gt;。不要删除 http:// 前缀。
    • 非常感谢。现在可以了。我有什么理由不应该删除 http:// 前缀?我是语义 Web 编程的新手。我想知道这背后的原因。
    • @user2201650 "我有什么理由不应该去掉 http:// 前缀吗?"是的,非常重要的一个。 :) http://myexample.com 是一个 IRI,因此可用于命名您可以查询的图形。 myexample.com 不是(或者可能是相对的)。 IRI 有时以http:// 开头,但并非总是如此。例如,urn:ex:foo 是一个 IRI。 mailto:joe@example.com 也是如此。现在,SPARQL 语法确实允许你写FROM &lt;myexample.com&gt;,(IRIREF 定义为'&lt;' ([^&lt;&gt;"{}|^`\]-[#x00-#x20])* '&gt;'),但即便如此http://myexample.commyexample.com 是不同的。
    • @JoshuaTaylor 非常感谢您抽出时间向我解释:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多