3

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

4

1 回答 1

0

假如说 :

  • 你知道如何通过阅读你构建的本体来填充你的模型
  • 您已将 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) );
于 2014-04-10T14:00:09.280 回答