3

Jenaフレームワークを使用して、Protoge4.2で構築された既存のオントロジーを編集しようとしています。つまり、プロパティ値を変更するか、個人またはクラスを追加してから推論を行います。オントロジーで、hasAge(?p、?age)^ swrlb:greaterThan(?age、18)-> Adult(?p)のようなルールがあると仮定します。イエナ側のhasAgeプロパティを変更して、誰かが大人かどうかを確認できるようにしたいと思います。これに関するサンプルコードを教えてください。どんな助けでも大歓迎です。

4

1 に答える 1

0

仮定して :

  • 構築したオントロジーを読み込んで、モデルに入力する方法を知っている
  • クラスパスにペレットを配置しました
  • 以下の IRI をドメインのものに置き換えます。
  • アサーションが有効になっています

次のコード スニペットは、個体に年齢を追加し、x-test://individualSWIRL によって導入されるプロパティが満たされていることをアサートします。

// 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 に答える