2016-09-07 11 views
1

私はProtege 4.3.0で作成され、OWLファイルに格納されたオントロジーを持っています。このオントロジーの一部のデータプロパティその範囲は次式のように定義している:私は彼らの範囲で指定した値を持つことができ、データのプロパティを検索しまうので、私は次のコードサンプルを書いたOWLDataRangeオブジェクトに指定された値が含まれているかどうかを確認する方法は?

({"absent"} or {"value1" , "value2" , "value3"}) 

が、 OWLDataRangeオブジェクトに照会して、指定された値(たとえば、文字列"value1")が含まれているかどうかを調べる方法はわかりません。

final OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); 
final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file); 
final OWLReasonerFactory rf = new StructuralReasonerFactory(); 
final OWLReasoner reasoner = rf.createReasoner(ontology); 

// ... 

// iterate over all data properties 
for (OWLDataProperty topDataProperty : reasoner.getTopDataPropertyNode()) { 
    for(OWLDataProperty property: reasoner.getSubDataProperties(topDataProperty, false).getFlattened()) { 

     // iterate over all data ranges for the current data property 
     for (OWLDataRange dataRange : property.getRanges(ontology)) { 

      // I would check if the current data property contains a specified value in their ranges. 
      // ... 

     } 
    } 
} 
+1

docs(http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/model/OWLDataRange.html)から見ることができるように、複数の種類のデータ範囲があります。あなたのケースでは、 2つの「DATA_ONE_OF」を​​含む「DATA_UNION_OF」。したがって、IF-ELSE(SWITCH-CASE)ブランチ、または対応するビジター(http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/model)の実装によって、これらのケースを処理する必要があります。 /OWLDataRangeVisitor.html) – AKSW

+0

'OWLDataRangeVisitor'インターフェースを実装した例はどこで読むことができますか? – enzom83

+0

これはインターフェイスを実装するのが簡単です。あなたの場合、ブール値のメソッドを実装するには十分だと思います。つまり、交差、結合、補完、そして最後に、値を含む構造体の1つの部分についてです。 – AKSW

答えて

0

このような問題の解決策は、推論(This Pellet fork)を使用することです。

考えられるのは、「確認する範囲のデータプロパティを持つ個体」と「プロパティ/リテラル​​を持つ個体」を表すクラスを作成することです。その後、推論を使用して、2つのクラスが交差していないかどうかをチェックします。

import java.util.function.BiFunction; 
import org.semanticweb.owlapi.model.*; 
import openllet.owlapi.*; 

public class RangeInclusionTest 
{ 
    public static void main(final String[] args) 
    { 
     try (final OWLManagerGroup group = new OWLManagerGroup()) 
     { 
      final OWLOntologyID ontId = OWLHelper.getVersion(IRI.create("http://test.org#entail-class-restrict-to-some-range"), 1.0); 
      final OWLHelper owl = new OWLGenericTools(group, ontId, true); 

      // This declaration is vital since this reasoner have problems with pure anonymous reasoning. 
      // You can remove this property after yours tests, (or better use one of your already existing properties). 
      final OWLDataProperty prop = OWL.DataProperty("http://test.org#dummyProp"); 
      owl.addAxiom(OWL.declaration(prop)); 

      final OWLLiteral un = OWL.constant(1); 
      final OWLLiteral deux = OWL.constant(2); 
      final OWLLiteral trois = OWL.constant(3); 
      final OWLLiteral quatre = OWL.constant(4); 
      final OWLDataRange dataRange = OWL.dataOr(OWL.oneOf(un), OWL.oneOf(deux), OWL.oneOf(trois)); 

      final BiFunction<OWLDataRange, OWLLiteral, Boolean> isIncludeInRange = // 
        (range, literal) -> owl.getReasoner().isSatisfiable(// 
          OWL.and(// You must be of all the following class 
            OWL.some(prop, OWL.oneOf(literal)), // The class of the 'literal' 
            OWL.some(prop, range), // The class of the range. 
            OWL.max(prop, 1))// But you can have the property only once. 
        ); 

      System.out.println("[A] " + (isIncludeInRange.apply(dataRange, un))); 
      System.out.println("[B] " + (isIncludeInRange.apply(dataRange, deux))); 
      System.out.println("[C] " + (isIncludeInRange.apply(dataRange, trois))); 
      System.out.println("[D] " + (isIncludeInRange.apply(dataRange, quatre))); 

     } catch (final Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

まず、あなたがあなたの範囲を定義する必要がありますいくつかのトリックが、それはここで正常に動作を取得することがあるので

は私の完全なソリューションです。次に、reasonerの 'isSatisfiable'メソッドを使用します。 1つのトリックは、交差クラスに「OWL.max(prop、1)」という制限を追加することによって、プロパティのインスタンスを1つだけ使用するように強制することです。

出力は

[A] true 
[B] true 
[C] true 
[D] false 

リテラル 'キャトルは' 'dataRange' 答え '[D]' が含まれていませんので

がfalseである必要があります。 この解決策を見ても分かるように、ある範囲の包含物を別のものに簡単に含めることができます。

オントロジで変更を要求しない解決策は、特別なswrlルールを作成し、オントロジ(空であっても)がルールを伴うかどうかを確認することでしたが、現在はswlに対してdl-reasonerサポートの含意はありません。

関連する問題