OWL
OWL可以被视为是RDFS的拓展,用于对描述网络上资源的相互关系的RDF进行高层概念的定义,它有更全面的词汇表,为用户构建本体,标注数据提供了更强有力的工具,比如对称性,反射属性,属性链,自约束等。
OWL语言包括:
1. OWLLite:是OWL DL的子集,表达能力最弱,它降低了OWL DL中的公理约束,推理高效,支持的基数约束只有0或1.
2. OWLDL:将可判定推理能力和较强表达能力作为首要目标,包含OWL语言所有成分,但使用时有一定的约束。
3. OWLFull:包含OWL的全部语言成分,并取消了OWL DL的约束,它将RDFS扩展为一个完备的本体语言,适合不需要可计算性保证但需要最强表达能力和完全自由的用户。
以下是OWL本体头部声明:
<owl:Ontologyrdf:about=""> //关于owl本体的声明,为空表示使用owl:Ontology的基准URI <rdfs:comment>An example OWLontology</rdfs:comment> //注释 <owl:priorVersion //版本控制 rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031215/wine"/> <owl:imports //其他本体的嵌入,接受rdf:resource的参数 rdf:resource="http://www.w3.org/TR/2004/REC-owl-guide-20040210/food"/> <rdfs:label>WineOntology</rdfs:label> //对自然语言进行标注 ... </owl:Ontology>
OWL中所有个体都是owl:Thing的成员,各个类都是owl:Thing的子类,可以通过声明ID来定义一个类:
<owl:Classrdf:ID="Winery"/> <owl:Classrdf:ID="Region"/> <owl:Classrdf:ID="ConsumableThing"/>
定义子类:
<owl:Classrdf:ID="PotableLiquid"> <rdfs:subClassofrdf:resource="#ConsumableThing" /> ... </owl:Class>
定义类的子体:
首先定义类:
<owl:Class rdf:ID="WineGrape">
定义一个个体:
<owl:thing rdf:ID="CabernetSauvignonGrape">
定义上述类的个体:
<owl:thingrdf:ID="#CabernetSauvignonGrape"> <rdf:type rdf:resource="#WineGrape"> </owl:thing>
也等价于:
<WineGraperdf:ID="CabernetSauvignonGrape">
定义属性:
定义对象属性:
<owl:ObjectPropertyrdf:ID="madeFromGrape"> <rdfs:domain rdf:resource="#Wine"/> <rdfs:range rdf:resource="#WineGrape"/> </owl:ObjectProperty>
定义数据类型属性:
<owl:Classrdf:ID="VintageYear" /> <owl:DatatypePropertyrdf:ID="yearValue"> <rdfs:domain rdf:resource="#VintageYear" /> <rdfs:range rdf:resource="&xsd;positiveInteger"/> </owl:DatatypeProperty>
属性也可以像类一样定义层次结构:rdfs:subPropertyOf
属性特性:
1.传递属性:如果一个属性 P 被声明为传递属性,那么对于任意的 x,y 和 z: P(x,y) 与 P(y,z) 蕴含 P(x,z)
<owl:ObjectPropertyrdf:ID="locatedIn"> <rdf:type rdf:resource="&owl;TransitiveProperty" /> <rdfs:domain rdf:resource="&owl;Thing" /> <rdfs:range rdf:resource="#Region" /> </owl:ObjectProperty> <Regionrdf:ID="SantaCruzMountainsRegion"> <locatedIn rdf:resource="#CaliforniaRegion" /> </Region> <Regionrdf:ID="CaliforniaRegion"> <locatedIn rdf:resource="#USRegion" /> </Region>
2.对称属性:如果一个属性 P 被声明为对称属性,那么对于任意的 x 和 y:P(x,y)当且仅当 P(y,x)
<owl:ObjectProperty rdf:ID="adjacentRegion"> <rdf:type rdf:resource="&owl;SymmetricProperty"/> <rdfs:domain rdf:resource="#Region" /> <rdfs:range rdf:resource="#Region" /> </owl:ObjectProperty> <Regionrdf:ID="MendocinoRegion"> <locatedIn rdf:resource="#CaliforniaRegion" /> <adjancentRegion rdf:resource="#SonomaRegion /> </Region>
3.函数属性:如果一个属性 P 被标记为函数型属性,那么对于所有的 x, y, 和 z: P(x,y) 与 P(x,z) 蕴含 y = z
<owl:Classrdf:ID="VintageYear" /> <owl:ObjectPropertyrdf:ID="hasVintageYear"> <rdf:type rdf:resource="&owl;FunctionalProperty" /> <rdfs:domain rdf:resource="#Vintage" /> <rdfs:range rdf:resource="#VintageYear" /> </owl:ObjectProperty>
4.逆属性:如果一个属性 P1 被标记为属性 P2 的逆(owl:inverseOf), 那么对于所有的 x 和 y: P1(x,y) 当且仅当 P2(y,x)
请注意 owl:inverseOf 的语法,它仅仅使用一个属性名作为参数。A 当且仅当 B 意思是 (A 蕴含 B)并且(B 蕴含 A).
<owl:ObjectPropertyrdf:ID="hasMaker"> <rdf:type rdf:resource="&owl;FunctionalProperty" /> </owl:ObjectProperty> <owl:ObjectPropertyrdf:ID="producesWine"> <owl:inverseOf rdf:resource="#hasMaker" /> </owl:ObjectProperty>
5.反函数属性:如果一个属性 P 被标记为反函数型的(InverseFunctional),那么对于所有 的 x, y 和 z: P(y,x) 与 P(z,x) 蕴含 y = z
<owl:ObjectPropertyrdf:ID="hasMaker" /> <owl:ObjectPropertyrdf:ID="producesWine"> <rdf:type rdf:resource="&owl;InverseFunctionalProperty"/> <owl:inverseOf rdf:resource="#hasMaker" /> </owl:ObjectProperty>
属性限制:
在owl:Restriction的上下文中,我们还能对属性的值域(range)进行进一步的限制
1.allValueFrom someValueFrom
注意这两个属于的限制是局部的,而之前domain,range的限制是全局的——也就是说对于这个属性的所有实例都必须满足range的限制。而allValueFrom和someValueFrom则要求:对于每一个有指定属性实例的类实例,该属性的值必须是由 owl:allValuesFrom 从句指定的类的成员.
<owl:Class rdf:ID="Wine"> <rdfs:subClassOf rdf:resource="&food;PotableLiquid"/> ... <rdfs:subClassOf> <owl:Restriction> <owl:onPropertyrdf:resource="#hasMaker" /> //对"hasMaker"属性进行限制 <owl:allValuesFromrdf:resource="#Winery" /> //所有的wine类实例的hasMaker属性的值都必须是Winery的实例 </owl:Restriction> </rdfs:subClassOf> ... </owl:Class>
如果把上述的allValueFrom 换成 someValueFrom则表明: 至少有一个wine类实例的hasMaker属性的值是Winery类的实例
可以把allValueFrom 和someValueFrom 的差别理解为全称量词和存在量词的差别
2.基数限制:这一约束允许对一个关系中的元素数目作出精确的限制
<owl:Classrdf:ID="Vintage"> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resource="#hasVintageYear"/> <owl:cardinalityrdf:datatype="&xsd;nonNegativeInteger">1</owl:cardinality> </owl:Restriction> </rdfs:subClassOf> </owl:Class>
上述owl:cardinality限制使hasVintageYear属性只有一个值,即每个Vintage类实例只有一个VintageYear
另外,类似的两个限制:
owl:maxCardinality
owl:minCardinality
则分别用来限定值个数的上界和下界
3.hasValue:hasValue 使得我们能够根据“特定的”属性值的存在来标识类。因此,一个个体只要至少有“一个”属性值等于hasValue的资源,这一个体就是该类的成员。
<owl:Classrdf:ID="Burgundy"> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resource="#hasSugar" /> <owl:hasValue rdf:resource="#Dry" /> </owl:Restriction> </rdfs:subClassOf> </owl:Class>
只有实例的hasSugar属性等于"Dry",那么它就是类BurGundy的成员
本体映射:
1.类和属性之间的等价关系:equivalentClass,equivalentProperty
<owl:Class rdf:ID="Wine"> <owl:equivalentClass rdf:resource="&vin;Wine"/> </owl:Class> <owl:Classrdf:ID="TexasThings"> <owl:equivalentClass> <owl:Restriction> <owl:onPropertyrdf:resource="#locatedIn" /> <owl:someValuesFromrdf:resource="#TexasRegion" /> </owl:Restriction> </owl:equivalentClass> </owl:Class>
2.相同的个体:
<Winerdf:ID="MikesFavoriteWine"> <owl:sameAs rdf:resource="#StGenevieveTexasWhite" /> </Wine>
3.不同的个体:
<WineSugar rdf:ID="Dry" /> <WineSugar rdf:ID="Sweet"> <owl:differentFrom rdf:resource="#Dry"/> </WineSugar> <WineSugar rdf:ID="OffDry"> <owl:differentFrom rdf:resource="#Dry"/> <owl:differentFromrdf:resource="#Sweet"/> </WineSugar>
集合运算符:
交运算符IntersectionOf, 并运算符unionOf, 补运算符complementOf