簡體   English   中英

從owl文件訪問數據屬性

[英]Accessing data properties from owl file

我是本體論的新手。 我正在使用protege 4.3創建一個.owl文件。 我通過使用SPARQL查詢訪問對象屬性,例如:

Prefix: <http://www.workingontologist.org/Examples/Chapter3/Product.owl#>

select ?x ?y where { 
  ?x :hasPizza ?y
}

這很好,並顯示與該成員相關的所有對象屬性。

當我從該owl文件訪問數據屬性時,我無法讀取或訪問數據屬性

請提供有關如何從該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 daml "http://www.daml.org/2001/03/daml+oil#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY mfg "http://www.workingontologist.org/Examples/Chapter3/Product.owl#" >
]>
<rdf:RDF xmlns="http://www.workingontologist.org/Examples/Chapter3/Product.owl#"
     xml:base="http://www.workingontologist.org/Examples/Chapter3/Product.owl"
     xmlns:mfg="http://www.workingontologist.org/Examples/Chapter3/Product.owl#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     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:daml="http://www.daml.org/2001/03/daml+oil#">
    <owl:Ontology rdf:about="http://www.workingontologist.org/Examples/Chapter3/Product.owl">
        <owl:versionInfo rdf:datatype="&xsd;string">Created with TopBraid Spreadsheet converter</owl:versionInfo>
    </owl:Ontology>

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




    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#hasPizza -->
    <owl:ObjectProperty rdf:about="&mfg;hasPizza"/>

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




    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_Available -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_Available">
        <rdfs:label rdf:datatype="&xsd;string">Available</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_Division -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_Division">
        <rdfs:label rdf:datatype="&xsd;string">Division</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_ID -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_ID">
        <rdfs:label rdf:datatype="&xsd;string">ID</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_Manufacture_Location -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_Manufacture_Location">
        <rdfs:label rdf:datatype="&xsd;string">Manufacture Location</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_ModelNo -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_ModelNo">
        <rdfs:label rdf:datatype="&xsd;string">ModelNo</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_Product_Line -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_Product_Line">
        <rdfs:label rdf:datatype="&xsd;string">Product Line</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_SKU -->

    <owl:DatatypeProperty rdf:about="&mfg;Product_SKU">
        <rdfs:label rdf:datatype="&xsd;string">SKU</rdfs:label>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:domain rdf:resource="&mfg;Product"/>
    </owl:DatatypeProperty>



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




    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product -->

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



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




    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product1 -->

    <owl:NamedIndividual rdf:about="&mfg;Product1">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 1</rdfs:label>
        <Product_ID rdf:datatype="&xsd;string">1</Product_ID>
        <Product_Available rdf:datatype="&xsd;string">23</Product_Available>
        <Product_SKU rdf:datatype="&xsd;string">FB3524</Product_SKU>
        <Product_Division rdf:datatype="&xsd;string">Manufacturing support</Product_Division>
        <Product_Product_Line rdf:datatype="&xsd;string">Papermachine</Product_Product_Line>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Sacramento</Product_Manufacture_Location>
        <Product_ModelNo rdf:datatype="&xsd;string">ZX-3</Product_ModelNo>
        <hasPizza rdf:resource="&mfg;Product1"/>
        <hasPizza rdf:resource="&mfg;Product2"/>
        <hasPizza rdf:resource="&mfg;Product3"/>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product2 -->

    <owl:NamedIndividual rdf:about="&mfg;Product2">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 2</rdfs:label>
        <Product_ID rdf:datatype="&xsd;string">2</Product_ID>
        <Product_Available rdf:datatype="&xsd;string">4</Product_Available>
        <Product_SKU rdf:datatype="&xsd;string">KD5243</Product_SKU>
        <Product_Division rdf:datatype="&xsd;string">Manufacturing support</Product_Division>
        <Product_Product_Line rdf:datatype="&xsd;string">Paper machine</Product_Product_Line>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Sacramento</Product_Manufacture_Location>
        <Product_ModelNo rdf:datatype="&xsd;string">ZX-3P</Product_ModelNo>
        <hasPizza rdf:resource="&mfg;Product2"/>
        <hasPizza rdf:resource="&mfg;Product7"/>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product3 -->

    <owl:NamedIndividual rdf:about="&mfg;Product3">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 3</rdfs:label>
        <Product_ID rdf:datatype="&xsd;string">3</Product_ID>
        <Product_Available rdf:datatype="&xsd;string">34</Product_Available>
        <Product_SKU rdf:datatype="&xsd;string">IL4028</Product_SKU>
        <Product_Division rdf:datatype="&xsd;string">Manufacturing support</Product_Division>
        <Product_Product_Line rdf:datatype="&xsd;string">Paper machine</Product_Product_Line>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Sacramento</Product_Manufacture_Location>
        <Product_ModelNo rdf:datatype="&xsd;string">ZX-3S</Product_ModelNo>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product4 -->

    <owl:NamedIndividual rdf:about="&mfg;Product4">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 4</rdfs:label>
        <Product_Available rdf:datatype="&xsd;string">23</Product_Available>
        <Product_ID rdf:datatype="&xsd;string">4</Product_ID>
        <Product_ModelNo rdf:datatype="&xsd;string">B-1430</Product_ModelNo>
        <Product_Division rdf:datatype="&xsd;string">Control Engineering</Product_Division>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Elizabeth</Product_Manufacture_Location>
        <Product_Product_Line rdf:datatype="&xsd;string">Feedback line</Product_Product_Line>
        <Product_SKU rdf:datatype="&xsd;string">KS4520</Product_SKU>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product5 -->

    <owl:NamedIndividual rdf:about="&mfg;Product5">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 5</rdfs:label>
        <Product_Available rdf:datatype="&xsd;string">14</Product_Available>
        <Product_ID rdf:datatype="&xsd;string">5</Product_ID>
        <Product_ModelNo rdf:datatype="&xsd;string">B-1430X</Product_ModelNo>
        <Product_SKU rdf:datatype="&xsd;string">CL5934</Product_SKU>
        <Product_Division rdf:datatype="&xsd;string">Control Engineering</Product_Division>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Elizabeth</Product_Manufacture_Location>
        <Product_Product_Line rdf:datatype="&xsd;string">Feedback line</Product_Product_Line>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product6 -->

    <owl:NamedIndividual rdf:about="&mfg;Product6">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 6</rdfs:label>
        <Product_Available rdf:datatype="&xsd;string">0</Product_Available>
        <Product_ID rdf:datatype="&xsd;string">6</Product_ID>
        <Product_Product_Line rdf:datatype="&xsd;string">Active sensor</Product_Product_Line>
        <Product_ModelNo rdf:datatype="&xsd;string">B-1431</Product_ModelNo>
        <Product_Division rdf:datatype="&xsd;string">Control Engineering</Product_Division>
        <Product_SKU rdf:datatype="&xsd;string">KK3945</Product_SKU>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Seoul</Product_Manufacture_Location>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product7 -->

    <owl:NamedIndividual rdf:about="&mfg;Product7">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 7</rdfs:label>
        <Product_Available rdf:datatype="&xsd;string">100</Product_Available>
        <Product_ID rdf:datatype="&xsd;string">7</Product_ID>
        <Product_Division rdf:datatype="&xsd;string">Accessories</Product_Division>
        <Product_ModelNo rdf:datatype="&xsd;string">DBB-12</Product_ModelNo>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">Hong Kong</Product_Manufacture_Location>
        <Product_Product_Line rdf:datatype="&xsd;string">Monitor</Product_Product_Line>
        <Product_SKU rdf:datatype="&xsd;string">ND5520</Product_SKU>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product8 -->

    <owl:NamedIndividual rdf:about="&mfg;Product8">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 8</rdfs:label>
        <Product_ID rdf:datatype="&xsd;string">8</Product_ID>
        <Product_SKU rdf:datatype="&xsd;string">Cleveland</Product_SKU>
        <Product_Available rdf:datatype="&xsd;string">HI4554</Product_Available>
        <Product_ModelNo rdf:datatype="&xsd;string">SP-1234</Product_ModelNo>
        <Product_Division rdf:datatype="&xsd;string">Safety</Product_Division>
        <Product_Product_Line rdf:datatype="&xsd;string">Safety</Product_Product_Line>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">valve</Product_Manufacture_Location>
    </owl:NamedIndividual>



    <!-- http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product9 -->

    <owl:NamedIndividual rdf:about="&mfg;Product9">
        <rdf:type rdf:resource="&mfg;Product"/>
        <rdfs:label rdf:datatype="&xsd;string">Product 9</rdfs:label>
        <Product_ID rdf:datatype="&xsd;string">9</Product_ID>
        <Product_SKU rdf:datatype="&xsd;string">Cleveland</Product_SKU>
        <Product_Available rdf:datatype="&xsd;string">OP5333</Product_Available>
        <Product_ModelNo rdf:datatype="&xsd;string">SPX-1234</Product_ModelNo>
        <Product_Product_Line rdf:datatype="&xsd;string">Safety</Product_Product_Line>
        <Product_Division rdf:datatype="&xsd;string">Safety</Product_Division>
        <Product_Manufacture_Location rdf:datatype="&xsd;string">valve</Product_Manufacture_Location>
    </owl:NamedIndividual>
    <rdf:Description>
        <Product_ID></Product_ID>
    </rdf:Description>
</rdf:RDF>

在您的數據中,IRI有一個數據類型屬性http://www.workingontologist.org/Examples/Chapter3/Product.owl#Product_SKU 您可以使用SPARQL查詢檢索該謂詞的主題和對象,如下所示:

prefix mfg:   <http://www.workingontologist.org/Examples/Chapter3/Product.owl#>

select ?x ?y where {
  ?x mfg:Product_SKU ?y
}
-------------------------------------------------------------------------
| x            | y                                                      |
=========================================================================
| mfg:Product9 | "Cleveland"^^<http://www.w3.org/2001/XMLSchema#string> |
| mfg:Product8 | "Cleveland"^^<http://www.w3.org/2001/XMLSchema#string> |
| mfg:Product7 | "ND5520"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product6 | "KK3945"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product5 | "CL5934"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product4 | "KS4520"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product3 | "IL4028"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product2 | "KD5243"^^<http://www.w3.org/2001/XMLSchema#string>    |
| mfg:Product1 | "FB3524"^^<http://www.w3.org/2001/XMLSchema#string>    |
-------------------------------------------------------------------------

問題似乎是關於數據類型與對象屬性。 在SPARQL中,沒有真正區分這些屬性的使用方式,因為數據類型和對象屬性都是可以在查詢中以完全相同的方式指定的URI。 唯一的區別是三重模式的對象將是數據類型屬性的文字。

如果需要在本體中查找所有數據類型屬性,請使用以下命令:

SELECT ?p
WHERE {
   ?p a owl:DatatypeProperty
}

然后使用?p的值來查詢數據。

或者,您也可以使用以下命令查找本體中的所有文字:

SELECT *
WHERE {
   ?s ?p ?o
   FILTER (isLiteral(?o))
}

這是一個計算量很大的查詢,因此您可能希望將其與第一個查詢結合使用以隔離屬性,然后檢查值是否為文字。 這對於檢查三元組的類型是否正確(對象與數據類型)非常有用。 此外,類型為rdf:Property允許對象(URI)或文字,並且此查詢可以找到那些文字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM