我需要些帮助
我使用RDF/XML来表示一些数据。
首先,我想证明一个人认识另一个人,我声明这个属性,并使用下面的代码来指定mark知道katrin和katrin知道john
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>现在我想声明一个属性并表示更多的东西。我的意思是。例如,我想说,katrin拥有一只ID为10的狗,它的颜色是黑色,它的名字是Peter。上面我只有资源、属性和对象。既然我要说的更多了,我怎样才能把它变成第二部分呢?
PART 1
<rdf:Property rdf:ID="Own">
<rdfs:domain rdf:resource="#Person"/>
<rdfs:range rdf:resource="#Dog"/>
</rdf:Property>
PART 2 ?????提前谢谢你的帮助。
发布于 2014-04-01 13:34:37
首先,请注意,您已经用<rdf:Property rdf:about="Know">…</rdf:Property>声明了属性<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中确实需要这样做,可以使用像Jena的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等)和上面完全一样。不过,您不需要声明一个属性就可以使用它,所以这里不包括新属性的声明。另外,对前面问题When i declare property how to use it的回答显示了如何声明属性。)如果您为狗设置了一个IRI,而“它的名字是Peter”,您的意思是它的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>https://stackoverflow.com/questions/22782748
复制相似问题