根据SWRL规则为属性赋值(使用Pellet作为推理者的Protege 4.3)

时间:2014-02-11 12:38:55

标签: owl protege pellet swrl

我的问题与SWRL规则有关,实际上已被其他用户询问(请参阅Ontology property definition in Protégé-OWL / SWRL)。仍然,按照如何使其工作的说明后,我没有成功。

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

  

人(?p)∧soldInYear(?p,?birthYear)∧减法(?年龄,2014年,?birthYear)    →年龄(?p,?年龄)

在创建了一个类 Person 的个体并断言他/她的 BirthYear 具有值"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>))))
)

2 个答案:

答案 0 :(得分:0)

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

  • age 数据属性,因此您不仅需要确保选中“复选框'对象属性断言',”而且还要'Data Property Assertions',因为它是您正在寻找的数据类型断言。

  • BornInYear 对象属性,因此?birthYear中的bornInYear(?p, ?birthYear)必须是个人。但是,swrlb:subtract的参数必须是数字文字。要使用swrlb:subtract,您需要获取规则中年份的整数值并对其执行算术运算。你应该能够毫不费力地做到这一点,虽然我不确定你是否仍然可以使用值"1977"^^xsd:gYear。 SWRL确实定义了一些使用日期和时间的函数(参见8.5. Built-Ins for Date, Time and Duration)。然而,并非所有的反对者都支持这一点(例如,我认为佩莱没有这样做)。但是,属性的值需要是 xsd:gYear

答案 1 :(得分:0)

以下是后续步骤:

  • 转到元数据标签
  • 导入时态本体,将其作为时间前缀。
  • 转到SWRL标签

编写规则如下:

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

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

相关问题