簡體   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