繁体   English   中英

耶拿框架中关于SWRL规则的Pellet推理

[英]Reasoning with Pellet on SWRL rules in Jena Framework

我正在尝试使用Jena框架来编辑使用Protoge 4.2构建的现有本体。 即改变属性值或添加个人或类,然后进行推理。 假设在本体中我们有一个规则:hasAge(?p,?age)^ swrlb:greaterThan(?age,18) - > Adult(?p)。 我希望能够在耶拿方面更改hasAge属性,看看是否有人是成人。 你能给我一些示例代码吗? 任何帮助表示赞赏。

假如说 :

  • 您知道如何通过阅读您构建的本体来填充模型
  • 你已经把Pellet放在了类路径上
  • 您将以下IRI替换为您域中的IRI
  • 您已启用断言

以下代码片段将为单个x-test://individual添加年龄,并断言将满足SWIRL引入的属性。

// create an empty ontology model using Pellet spec
final OntModel model = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );   

// read the file
model.read( ont );

// Grab a resource and and property, and then set the property on that individual
final Resource Adult = ResourceFactory.createResource("x-domain://Adult");
final Property hasAge = ResourceFactory.createProperty("x-domain://hasAge");
final Resource res = model.createResource("x-test://individual");
res.addLiteral(hasAge, 19);

// Test that the swirl rule has executed
assert( res.hasProperty(RDF.type, Adult) );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM