我的问题与 SWRL 规则有关,实际上已经被另一个用户问过(请参阅Protégé-OWL / SWRL 中的本体属性定义)。尽管如此,在按照如何让它工作的说明之后,我还是没有成功。
在我的本体中,我必须处理一些复杂的时间事实(与时间间隔等有关),因此我导入了Time Ontology。在解决实际问题之前,我先考虑一个简单的示例,测试如何根据 SWRL 规则为数据属性分配值。这个简单的例子处理一个类Person。还有一个BirthYear类(Time Ontology 中Instant类的子类)。对象属性BornInYear,域Person和范围BirthYear将Person与他/她的出生年份联系起来。我想计算这个人当年的年龄,因此我制定了这个 SWRL 规则:
人(?p) ∧bornInYear(?p, ?birthYear) ∧ 减法(?age, 2014, ?birthYear) → 年龄(?p, ?age)
在创建Person类的个人并断言他/她的BirthYear具有 value"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>))))
)