2014-04-01 195 views
1

我需要一些帮助RDF/XML属性

我使用RDF/XML来表示一些数据。

首先我想说明,一个人知道其他人的,我申报的财产,我使用下面的代码来指定标记知道卡特琳和卡特琳知道约翰

PART 1 
<rdf:Property rdf:about="Know"> 
    <rdfs:domain rdf:resource="#Person"/> 
    <rdfs:range rdf:resource="#Person"/> 
</rdf:Property> 


PART2 
<rdf:Description rdf:about="#Mark"> 
    <dc:Knows rdf:resource="#Katrin"/> 
</rdf:Description> 


<rdf:Description rdf:about="#Katrin"> 
    <dc:Knows rdf:resource="#John"/> 
</rdf:Description> 

现在我想声明属性和代表更多的东西。我的意思是。我想说的是,例如卡特林拥有一只ID为10的狗,这只狗的颜色为黑色,名字叫彼得。以上我只有资源的属性和对象。现在我必须说更多我怎样才能使它成为第2部分?

PART 1 

<rdf:Property rdf:ID="Own"> 
    <rdfs:domain rdf:resource="#Person"/> 
    <rdfs:range rdf:resource="#Dog"/> 
</rdf:Property> 

PART 2 ????? 

非常感谢您的帮助。

回答

5

首先,请注意,您已声明属性Know<rdf:Property rdf:about="Know">…</rdf:Property>,但您在其余代码中使用Knows

如果您需要手工编写RDF,则使用人类可读和可写语法之一(例如Turtle(您的上一个问题的as suggested by Michael in an answer))要容易得多。在龟,我们能为您有什么至今写:

@prefix : <https://stackoverflow.com/q/22782748/1281433/> 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

:Knows a rdfs:Property ; 
     rdfs:domain :Person ; 
     rdfs:range :Person . 

:Mark :Knows :Katrin . 

:Katrin :Knows :John . 

如果你真的需要这在RDF/XML出于某种原因,你可以像使用耶拿的rdfcat转换器来获得输出,如:

<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns="https://stackoverflow.com/q/22782748/1281433/" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
    <rdfs:Property rdf:about="https://stackoverflow.com/q/22782748/1281433/Knows"> 
    <rdfs:domain rdf:resource="https://stackoverflow.com/q/22782748/1281433/Person"/> 
    <rdfs:range rdf:resource="https://stackoverflow.com/q/22782748/1281433/Person"/> 
    </rdfs:Property> 
    <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Mark"> 
    <Knows> 
     <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin"> 
     <Knows rdf:resource="https://stackoverflow.com/q/22782748/1281433/John"/> 
     </rdf:Description> 
    </Knows> 
    </rdf:Description> 
</rdf:RDF> 

现在,说类似

卡特琳拥有ID为10一只狗在那里这狗有黑色,它的名字是彼得。

声明新属性(拥有,hasColor,hasId等)与上面完全相同。你不需要声明一个属性来使用它,所以我不会在这里包含新属性的声明。 )如果你有狗的IRI,并且“它的名字是彼得”,你的意思是它的IRI是<…Peter>,那么你可以做这样的事情:

@prefix : <https://stackoverflow.com/q/22782748/1281433/> 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

:Katrin :owns :Peter . 

:Peter a :Dog ; 
     :hasId 10 ; 
     :hasColor "black" . 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns="https://stackoverflow.com/q/22782748/1281433/" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
    <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin"> 
    <owns> 
     <Dog rdf:about="https://stackoverflow.com/q/22782748/1281433/Peter"> 
     <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer" 
     >10</hasId> 
     <hasColor>black</hasColor> 
     </Dog> 
    </owns> 
    </rdf:Description> 
</rdf:RDF> 

如果你没有一个IRI的狗,那么你可以使用空白节点:

@prefix : <https://stackoverflow.com/q/22782748/1281433/> 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

:Katrin :owns _:dog . 

_:dog a :Dog ; 
     :hasName "Peter" ; 
     :hasId 10 ; 
     :hasColor "black" . 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns="https://stackoverflow.com/q/22782748/1281433/" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
    <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin"> 
    <owns> 
     <Dog> 
     <hasName>Peter</hasName> 
     <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer" 
     >10</hasId> 
     <hasColor>black</hasColor> 
     </Dog> 
    </owns> 
    </rdf:Description> 
</rdf:RDF> 

相反,_:dog符号的空白节点,我通常使用这里的更紧凑的缩写符号:

@prefix : <https://stackoverflow.com/q/22782748/1281433/> 
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> 

:Katrin :owns [ a :Dog ; 
       :hasName "Peter" ; 
       :hasId 10 ; 
       :hasColor "black" ] . 
<rdf:RDF 
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns="https://stackoverflow.com/q/22782748/1281433/" 
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
    <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin"> 
    <owns> 
     <Dog> 
     <hasName>Peter</hasName> 
     <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer" 
     >10</hasId> 
     <hasColor>black</hasColor> 
     </Dog> 
    </owns> 
    </rdf:Description> 
</rdf:RDF>