使用 Turtle 之类的语法编写 RDF 比使用 RDF/XML 容易得多。您提供的数据不足以让我们使用(例如,基本 URI 未定义)。这是包含您的数据的完整 RDF/XML 文档(注意ex
命名空间):
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:person="http://rdf.pozitron.com/people/"
xmlns:organization="http://rdf.pozitron.com/organizations/"
xml:base="http://example.org/"
xmlns:ex="http://example.org/#">
<owl:ObjectProperty rdf:ID="employ">
<rdf:type rdf:resource="http://rdf.pozitron.com/organizations/" />
<rdfs:domain rdf:resource="http://rdf.pozitron.com/organizations/"/>
<rdfs:range rdf:resource="http://rdf.pozitron.com/people/"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:ID="employedBy">
<rdf:type rdf:resource="http://rdf.pozitron.com/people/" />
<owl:inverseOf rdf:resource="#Employ" />
<rdfs:domain rdf:resource="http://rdf.pozitron.com/people/"/>
<rdfs:range rdf:resource="http://rdf.pozitron.com/organizations/"/>
</owl:ObjectProperty>
<rdf:Description rdf:about="http://rdf.pozitron.com/people/john">
<rdf:type rdf:resource="http://rdf.pozitron.com/people/"/>
<person:personName>John</person:personName>
<organization:organizationName>Pozitron</organization:organizationName>
</rdf:Description>
</rdf:RDF>
在 Turtle 中,这是以下内容,并揭示了几个问题:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/#> .
@prefix person: <http://rdf.pozitron.com/people/> .
@prefix organization: <http://rdf.pozitron.com/organizations/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:employedBy
a person: , owl:ObjectProperty ;
rdfs:domain person: ;
rdfs:range organization: ;
owl:inverseOf ex:Employ .
person:john
a person: ;
organization:organizationName
"Pozitron" ;
person:personName "John" .
ex:employ
a owl:ObjectProperty , organization: ;
rdfs:domain organization: ;
rdfs:range person: .
这里的问题是:
employedBy
的倒数是Employ
,但没有该名称的属性,只有employ
;
- 该物业
employ
是organization
- 该物业
employedBy
是person
john
有一个organizationName
- 没有组织
Pozitron
。
这些在这种语法中很容易修复。我们还可以在我们这样做john employedBy Pozitron
的同时添加三元组。Pozitron employ john
我们最终得到:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/#> .
@prefix person: <http://rdf.pozitron.com/people/> .
@prefix organization: <http://rdf.pozitron.com/organizations/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:employedBy
a owl:ObjectProperty ;
rdfs:domain person: ;
rdfs:range organization: ;
owl:inverseOf ex:employ .
organization:Pozitron
a organization: ;
organization:organizationName
"Pozitron" ;
ex:employ person:john .
person:john
a person: ;
person:personName "John" ;
ex:employedBy organization:Pozitron .
ex:employ
a owl:ObjectProperty ;
rdfs:domain organization: ;
rdfs:range person: .
通过将其转换回来,我们也可以看到它在 RDF/XML 中的样子:
<rdf:RDF
xmlns:ex="http://example.org/#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:person="http://rdf.pozitron.com/people/"
xmlns:organization="http://rdf.pozitron.com/organizations/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://example.org/#employedBy">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
<rdfs:domain rdf:resource="http://rdf.pozitron.com/people/"/>
<rdfs:range rdf:resource="http://rdf.pozitron.com/organizations/"/>
<owl:inverseOf rdf:resource="http://example.org/#employ"/>
</rdf:Description>
<rdf:Description rdf:about="http://rdf.pozitron.com/organizations/Pozitron">
<rdf:type rdf:resource="http://rdf.pozitron.com/organizations/"/>
<organization:organizationName>Pozitron</organization:organizationName>
<ex:employ rdf:resource="http://rdf.pozitron.com/people/john"/>
</rdf:Description>
<rdf:Description rdf:about="http://rdf.pozitron.com/people/john">
<rdf:type rdf:resource="http://rdf.pozitron.com/people/"/>
<person:personName>John</person:personName>
<ex:employedBy rdf:resource="http://rdf.pozitron.com/organizations/Pozitron"/>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/#employ">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
<rdfs:domain rdf:resource="http://rdf.pozitron.com/organizations/"/>
<rdfs:range rdf:resource="http://rdf.pozitron.com/people/"/>
</rdf:Description>
</rdf:RDF>
如果您使用的是可以处理逆属性的 OWL 推理器,那么您真的不需要同时编写john employedBy Pozitron
and Pozitron employ john
; 你可以只写一个,推理者会推断出另一个。