OWL
owl用owl:Ontology来声明一个本体。rdf:about属性为本体提供一个名称或引用。根据标准,当rdf:about属性的值为""时,本体的名称是owl: Ontology元素的基准URI。
<owl:Ontology rdf:about=""> <rdfs:comment>An example OWL ontology</rdfs:comment> <owl:priorVersion rdf:resource="http://www.w3.org/TR/2003/PR-owl-guide-20031215/wine"/> <owl:imports rdf:resource="http://www.w3.org/TR/2004/REC-owl-guide-20040210/food"/> <rdfs:label>Wine Ontology</rdfs:label> </owl:Ontology>
rdfs:comment 提供了显然必须的为本体添加注解的能力。
owl:priorVersion 是一个为用于本体的版本控制系统提供相关信息(hook)的标准标签。
owl:imports 提供了一种嵌入机制,接受一个用rdf:resource属性标识的参数。导入另一个本体将把那个本体中的全部声引入到当前本体中.
rdfs:label对本体进行自然语言标注。
OWL中的所有个体都是类owl:Thing的成员。
<owl:Class rdf:ID="PotableLiquid"> <rdfs:subClassOf rdf:resource="#ConsumableThing" /> </owl:Class>
上例中PotableLiquid被定义为ConsumableThing的子类。
一个类的定义由两部分组成:引入或引用一个名称,以及一个限制列表。被直接包含在类定义中的各个表达式进一步限制了该类的实例,该类的实例属于所有这些限制的交集。(这里描述的是成为某个类的必要条件,关于描述成为某个类的充分必要条件,请参见owl:equivalentClass部分。
类的成员就是类的个体。
先定义类。
<owl:Class rdf:ID="Grape"> </owl:Class>
在定义本体
<owl:Class rdf:ID="WineGrape"> <rdfs:subClassOf rdf:resource="&food;Grape" /> </owl:Class>
然后就可以定义个体了
<WineGrape rdf:ID="CabernetSauvignonGrape" />
这里WineGrape为类名,rdf:ID为个体名。
一个属性是一个二元关系。有两种类型的属性:
数据类型属性(datatype properties),类实例与RDF文字或XML Schema数据类型间的关系。
对象属性(object properties),两个类的实例间的关系。
<owl:ObjectProperty rdf:ID="madeFromGrape"> <rdfs:domain rdf:resource="#Wine"/> <rdfs:range rdf:resource="#WineGrape"/> </owl:ObjectProperty> <owl:ObjectProperty rdf:ID="course"> <rdfs:domain rdf:resource="#Meal" /> <rdfs:range rdf:resource="#MealCourse" /> </owl:ObjectProperty>
上面例子可以看出,定义域为Wine,值域为WineGrape,也就是说,属性描述可以将两个类相关联,使得属性取值的key在Wine中,value在WineGrape中。
实体如何拥有定义的属性呢?
<owl:Thing rdf:ID="LindemansBin65Chardonnay"> <madeFromGrape rdf:resource="#ChardonnayGrape" /> </owl:Thing>
上面这个例子可以看出,LindemansBin65Chardonnay拥有属性madeFromGrape。并且可以根据其定义域知道他一定是葡萄酒。
例如,我们可以通过定义一个locateIn属性来将事物和他所在的地区相关联。
<owl:ObjectProperty rdf:ID="locatedIn"> <rdfs:domain rdf:resource="http://www.w3.org/2002/07/owl#Thing" /> <rdfs:range rdf:resource="#Region" /> </owl:ObjectProperty>
数据类型属性定义
<owl:Class rdf:ID="VintageYear" /> <owl:DatatypeProperty rdf:ID="yearValue"> <rdfs:domain rdf:resource="#VintageYear" /> <rdfs:range rdf:resource="&xsd;positiveInteger"/> </owl:DatatypeProperty>
数据类型的属性定义更像是类的属性,而对象的属性更像是实例的属性。
可以使用owl:Restriction来对属性的值域进行进一步的限制。
<owl:Class rdf:ID="Wine"> <rdfs:subClassOf rdf:resource="&food;PotableLiquid" /> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resource="#hasMaker" /> <owl:allValuesFrom rdf:resource="#Winery" /> </owl:Restriction> </rdfs:subClassOf> </owl:Class>
上面例子使用了owl:Restriction来对Wine类进行限制owl:onProperty表明对哪个属性进行限制,而owl:allValuesForm则表明限制的取值范围。所以上面的例子可以解释为,所有Wine实例的hasMaker属性值必须为Winery的实例。
数量限制:
<owl:Class rdf:ID="Vintage"> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resource="#hasVintageYear"/> <owl:cardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:cardinality> </owl:Restriction> </rdfs:subClassOf> </owl:Class>
使用owl:cardinality可以限制实例属性的取值数量,这里onProperty表明对hasVintageYear属性限制,owl:cardinality则限制了该属性取值为1。
其他限制还有:
owl:maxCardinality 限制数值上界
owl:minCardinality 限制数值下界
owl:hasValue 限制属性值的实例必须有hasValue的资源
<owl:Class rdf: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为的实例。
表明两个类等价等价。equivalentClass两个类等价。
<owl:Class rdf:ID="TexasThings"> <owl:equivalentClass> <owl:Restriction> <owl:onProperty rdf:resource="#locatedIn" /> <owl:someValuesFrom rdf:resource="#TexasRegion" /> </owl:Restriction> </owl:equivalentClass> </owl:Class>
上例表明,TexasThings类等价于一个无名类,而这个无名类加了locatedIn限制。
来源:博客园
作者:aoru45
链接:https://www.cnblogs.com/aoru45/p/11483870.html