根据SWRL规则为属性赋值(Protege 4.3,Pellet作为推理器)



我的问题与SWRL规则有关,实际上已经被另一个用户提出了(请参阅Proté;gé;-OWL/SWRL中的本体属性定义)。尽管如此,在遵循了如何让它发挥作用的指示后,我并没有成功。

在我的本体中,我必须处理一些复杂的时间事实(与时间间隔等有关),因此我导入了时间本体。在解决真正的问题之前,我考虑一个简单的例子,测试如何根据SWRL规则为数据属性赋值。这个简单的例子处理一个类Person。还有一个类BirthYear(来自时间本体的Instant类的子类)。对象属性bornInYear,域Person和范围BirthYearPerson与其出生年份关联起来。我想计算一个人当年的年龄,因此我制定了这个SWRL规则:

个人(?p)&和;bornInYear(?p,?birthYear)和;减法(?年龄,2014,?出生年份)&右箭头;年龄(?p,?年龄)

在创建一个Person类的个人并断言他/她的出生年份具有值"1977"之后,我希望Pellet计算出这个人的年龄是37。这种情况不会发生。知道为什么吗?SWRL规则正确吗?(为了知道值37是否被断言到数据属性age,我查看了单个p的"属性断言"视图。我还确保在推理器首选项中选中了"对象属性断言"复选框。)我的示例本体如下所示:

Prefix(SWRLexample:=<http://www.semanticweb.org/ontologies/2014/1/SWRLexample#>)
Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
Prefix(swrlb:=<http://www.w3.org/2003/11/swrlb#>)
Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
Prefix(:=<http://www.semanticweb.org/ontologies/2014/1/untitled-ontology-101#>)
Prefix(time:=<http://www.w3.org/2006/time#>)
Prefix(xml:=<http://www.w3.org/XML/1998/namespace>)
Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
Prefix(swrl:=<http://www.w3.org/2003/11/swrl#>)
Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)

Ontology(<http://www.semanticweb.org/ontologies/2014/1/SWRLexample>
Import(<http://www.w3.org/2006/time>)
Declaration(Class(SWRLexample:BirthYear))
SubClassOf(SWRLexample:BirthYear time:Instant)
Declaration(Class(SWRLexample:Person))
Declaration(ObjectProperty(SWRLexample:bornInYear))
ObjectPropertyDomain(SWRLexample:bornInYear SWRLexample:Person)
ObjectPropertyRange(SWRLexample:bornInYear SWRLexample:BirthYear)
Declaration(DataProperty(SWRLexample:age))
AnnotationAssertion(rdfs:comment SWRLexample:age "Age of a person in years")
DataPropertyDomain(SWRLexample:age SWRLexample:Person)
DataPropertyRange(SWRLexample:age xsd:int)
Declaration(NamedIndividual(SWRLexample:birthYear1))
ClassAssertion(SWRLexample:BirthYear SWRLexample:birthYear1)
DataPropertyAssertion(time:year SWRLexample:birthYear1 "1977"^^xsd:gYear)
Declaration(NamedIndividual(SWRLexample:p1))
ClassAssertion(SWRLexample:Person SWRLexample:p1)
ObjectPropertyAssertion(SWRLexample:bornInYear SWRLexample:p1 SWRLexample:birthYear1)
DLSafeRule(Body(ClassAtom(SWRLexample:Person Variable(<urn:swrl#p>)) ObjectPropertyAtom(SWRLexample:bornInYear Variable(<urn:swrl#p>) Variable(<urn:swrl#birthYear>)) BuiltInAtom(swrlb:subtract Variable(<urn:swrl#age>) "2014"^^xsd:integer Variable(<urn:swrl#birthYear>)))Head(DataPropertyAtom(SWRLexample:age Variable(<urn:swrl#p>) Variable(<urn:swrl#age>))))
)

有一些问题(但我很高兴其他答案是一个有用的起点):

  • age数据属性,因此您不仅需要确保"选中了‘对象属性断言’复选框",还需要确保"数据属性断言",因为它是您要查找的数据类型断言。

  • BornYear对象属性,因此bornInYear(?p, ?birthYear)中的?birthYear必须是一个个体。但是,swrlb:减法的参数必须是数字文字。要使用swrlb:减法,您需要在规则中获得年份的整数值,并对其执行算术运算。您应该能够在没有太多麻烦的情况下做到这一点,尽管我不确定您是否仍然能够使用值"1977"^^xsd:gYear。SWRL确实定义了一些使用日期和时间的函数(参见8.5。内置日期、时间和持续时间)。并不是所有的推理者都支持这一点(例如,我不认为佩莱支持)。但是,year属性的值确实需要是xsd:gYear

以下是连续的步骤:

  • 转到元数据选项卡
  • 导入时态本体,前缀为时态
  • 转到SWRL选项卡

写入规则如下:

Person(?x) ^ hasDOB(?x, ?dob) ^ temporal:duration(?age, "now", ?dob, temporal:Years) -> hasAge(?x,  ?age)

其中Person是一个类hasDOBhasAge是对象属性

最新更新