2

私は多くの個人とのオントロジーを持っており、Jena 推論を使用してそれらに関する情報を取得しています。私の目標は、そのルール内の特定の情報に基づいて新しい個人を作成し、それらにプロパティを割り当てることです。個体に名前を付ける必要はありませんが、型が必要で、いくつかのプロパティの一部である必要があります。現時点では、(メーリング リストへの投稿の助けを借りて) 匿名の個人を作成できますが、指定できるのは 1 つの型または 1 つのプロパティのみです。

これが私の問題の小さな例です。私のルールは次のようになります (オントロジーと推論された結果は下部にあります):

[test2: (?X rdf:type NS:Test1) ->
    [(?Y rdf:type NS:Test2) <- makeSkolem(?Y, ?X)]]

これは、Test1 個体が見つかると、新しい空のノードが作成され、そのノードにタイプ Test2 が与えられることを意味します。正常に動作しますが、この新しい個体に分類と ?X (Test1 個体) へのポインター (プロパティ) を与えたいと考えています。

次のようなものは機能しません。「後方規則では先頭句が 1 つしか許可されない」ためです。ただし、その句のすべての句は完全に正常に機能します。

[test2: (?X rdf:type NS:Test1) ->
    [(?Y rdf:type NS:Test2), (?Y NS:hasClassification 'test'), <- makeSkolem(?Y, ?X)]]

これは私のオントロジーです:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns="file:/Test#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="file:/Test#hasClassification">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#TestProp">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#testInd">
    <rdf:type rdf:resource="file:/Test#Test1"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#testInd2">
    <rdf:type rdf:resource="file:/Test#Test1"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#Test1">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#Test2">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
</rdf:RDF>

これは最初のルールの結果です (IDA0を持つ空白のノードA1が新しい個体です)。

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns="file:/Test#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" > 
  <rdf:Description rdf:about="file:/Test#hasClassification">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A0">
    <rdf:type rdf:resource="file:/Test#Test2"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#TestProp">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#testInd">
    <rdf:type rdf:resource="file:/Test#Test1"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#testInd2">
    <rdf:type rdf:resource="file:/Test#Test1"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#Test1">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test#Test2">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A1">
    <rdf:type rdf:resource="file:/Test#Test2"/>
  </rdf:Description>
  <rdf:Description rdf:about="file:/Test">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
</rdf:RDF>
4

1 に答える 1

1

まず、あなたのルールは、あなたが言ったことを正確に実行しないことに注意してください。

[test2: (?X rdf:type NS:Test1) →
    [(?Y rdf:type NS:Test2) ← makeSkolem(?Y, ?X)]]

これは、Test1 個体が見つかると、新しい空のノードが作成され、そのノードにタイプ Test2 が与えられることを意味します。

この規則は、インスタンスの NS:Test1 が見つかったときに一致し、型が NS:Test2 であるかどうかを判断するときに使用できる新しい後方連鎖規則を追加します。要求しない限り、タイプ NS:Test2 は何も与えません。(もちろん、モデル全体を書くには、そのようなトリプルが必要です。)

そのタイプの動作が受け入れられるとわかった場合は、複数の後方連鎖ルールを追加する前方連鎖ルールを単純に使用できます。次に例を示します。

[test2:
  (?X rdf:type NS:Test1) →
    [(?Y rdf:type NS:Test2) ← makeSkolem(?Y, ?X)],
    [(?Y NS:hasClassification 'test') ← makeSkolem( ?Y, ?X)]
]

必要以上に複雑だと思います。Skolem オブジェクトは、他の値によって一意に決定される単純なオブジェクトであるため、ルールのヘッドだけでなく、ルールの前提条件でも makeSkolem を使用できます。これは、次のことができることを意味します。

[test2: (?X rdf:type NS:Test1), makeSkolem(?Y, ?X) →
    (?Y rdf:type NS:Test2), (?Y rdf:type NS:hasClassification 'test')]

makeSkolem は任意の数の引数を取ることに注意してください。複数の場所で同じ skolem オブジェクトを誤って取得しないように、何らかのインジケーターを追加する価値があるかもしれません。たとえば、次のようなものがあった場合

[(?child rdf:type :Child), makeSkolem(?mother, ?child) →
    (?mother rdf:type :Mother), (?child :hasMother ?mother)]

[(?child rdf:type :Child), makeSkolem(?father, ?child) →
    (?father rdf:type :Father), (?child :hasFather ?father)]

その場合、実際には子ごとに1 つのskolem オブジェクトを作成し、それを子の母と父と呼ぶことになりますが、これはおそらくあなたが望むものではありません。代わりに、次のようなことができます。

[(?child rdf:type :Child), makeSkolem(?mother, ?child, 'mother') →
    (?mother rdf:type :Mother), (?child :hasMother ?mother)]

[(?child rdf:type :Child), makeSkolem(?father, ?child, 'father') →
    (?father rdf:type :Father), (?child :hasFather ?father)]

( ?child, 'mother') と ( ?child, 'father') は常に異なるため、1 つではなく 2 つの skolem オブジェクトが得られます。ルールでこのようなものを使用して、たとえば、

[test2: (?X rdf:type NS:Test1), makeSkolem(?Y, ?X, 'test2') →
    (?Y rdf:type NS:Test2), (?Y NS:hasClassification 'test')]

于 2014-02-27T17:35:55.980 に答える