首先,请注意,您已声明属性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>