[英]Reasoning with Pellet on SWRL rules in Jena Framework
我正在嘗試使用Jena框架來編輯使用Protoge 4.2構建的現有本體。 即改變屬性值或添加個人或類,然后進行推理。 假設在本體中我們有一個規則:hasAge(?p,?age)^ swrlb:greaterThan(?age,18) - > Adult(?p)。 我希望能夠在耶拿方面更改hasAge屬性,看看是否有人是成人。 你能給我一些示例代碼嗎? 任何幫助表示贊賞。
假如說 :
以下代碼片段將為單個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.