我正在尝试使用Jena框架编辑使用Protoge 4.2构建的现有本体。即改变财产价值或增加个人或类别,然后进行推理。假设在本体中我们有一个规则:hasAge(?p,?age)^ swrlb:greaterThan(?age,18) - > Adult(?p)。我希望能够在耶拿方面更改hasAge属性,看看是否有人是成人。你能给我一些示例代码吗?任何帮助表示赞赏。
答案 0 :(得分:0)
假设:
以下代码段将为个人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) );