为什么需要联合类的实例?
虽然我的其余答案将解决如何创建联合类的实例,但我认为您应该考虑这样做的原因。如果这与您之前的问题 uml Composition relationships to RDF and OWL 相关,这似乎很可能,并且您试图说属性的范围是联合类,例如,
hasComponent rdfs:range (TypeA 或 TypeB)
您不需要为了将它用作 hasComponent 语句的对象,需要声明某个单独的 x 是类型(TypeA 或 TypeB)。相反。所有 rdfs:range 声明在这里所做的就是让您能够观察语句
y hasComponent x
并从中推断
x rdf:type (TypeA 或 TypeB)
您不需要提前在 x 上声明任何类型。域和范围声明允许您根据它们在断言中的使用方式推断事物的类型;它们不提供任何形式的一致性强制或完整性约束。
如何创建它们
我不确定您到底在问什么(您是在尝试生成某些公理的 RDF/XML 序列化,还是什么),但我认为我们可以找到解决方案。 Wsing Protégé,很容易创建一个个体并声明它具有某个联合类的类型。例如,我们可以断言
x : A 或 B 或 C
在门生中:
我们可以看一下这个OWL本体的RDF序列化。如果出于某种原因需要手动编写,Turtle 序列化是最容易阅读和最容易编写的:
@prefix : <http://www.example.org/unionof-example#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
## Ontology declaration
<http://www.example.org/unionof-example>
a owl:Ontology .
## Three classes
:A a owl:Class .
:B a owl:Class .
:C a owl:Class .
## x is a thing, a named individual, and
## an (A or B or C).
:x a owl:Thing , owl:NamedIndividual ;
a [ a owl:Class ;
owl:unionOf ( :A :B :C )
] .
如果您真的需要在 RDF/XML 中使用它,那只是 RDF 图的另一个序列化:
<rdf:RDF
xmlns="http://www.example.org/unionof-example#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.example.org/unionof-example"/>
<owl:Class rdf:about="http://www.example.org/unionof-example#A"/>
<owl:Class rdf:about="http://www.example.org/unionof-example#B"/>
<owl:Class rdf:about="http://www.example.org/unionof-example#C"/>
<owl:Thing rdf:about="http://www.example.org/unionof-example#x">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<rdf:type>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="http://www.example.org/unionof-example#A"/>
<owl:Class rdf:about="http://www.example.org/unionof-example#B"/>
<owl:Class rdf:about="http://www.example.org/unionof-example#C"/>
</owl:unionOf>
</owl:Class>
</rdf:type>
</owl:Thing>
</rdf:RDF>
您可能还对它的非缩写序列化感兴趣。它更冗长,可读性更差,但如果你正在这样做,手写可能会更容易一些:
<rdf:RDF
xmlns="http://www.example.org/unionof-example#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="http://www.example.org/unionof-example#A">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A0">
<rdf:first rdf:resource="http://www.example.org/unionof-example#B"/>
<rdf:rest rdf:nodeID="A1"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.org/unionof-example#B">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A2">
<rdf:first rdf:resource="http://www.example.org/unionof-example#A"/>
<rdf:rest rdf:nodeID="A0"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.org/unionof-example#C">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A3">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
<owl:unionOf rdf:nodeID="A2"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A1">
<rdf:first rdf:resource="http://www.example.org/unionof-example#C"/>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.org/unionof-example">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
</rdf:Description>
<rdf:Description rdf:about="http://www.example.org/unionof-example#x">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<rdf:type rdf:nodeID="A3"/>
</rdf:Description>
</rdf:RDF>