在OWL API中检索OWL2DL违规报告中的URI

时间:2018-05-19 11:43:38

标签: owl owl-api

我需要在这个简化的本体中检查OWL2DL配置文件的违规行为:

@prefix : <http://www.onto.com/test#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@base <http://www.onto.com/test#> .

<http://www.onto.com/test#> rdf:type owl:Ontology ;
                             rdfs:label "Test"@en .

xsd:date rdf:type rdfs:Datatype .

<http://www.onto.com/test#hasPart2> rdf:type owl:ObjectProperty .

<http://www.onto.com/test#isPartOf> rdf:type owl:ObjectProperty ,
                                             owl:TransitiveProperty ;
                                    rdfs:domain <http://www.onto.com/test#TestRestriction> .

<http://www.onto.com/test#isPartOf2> rdf:type owl:ObjectProperty ;
                                     rdfs:subPropertyOf owl:topObjectProperty ;
                                     rdf:type owl:TransitiveProperty ;
                                     rdfs:domain <http://www.onto.com/test#A2PartOfClass> .

<http://www.onto.com/test#maxCardinality0> rdf:type owl:ObjectProperty .

<http://www.onto.com/test#A2PartOfClass> rdf:type owl:Class .

<http://www.onto.com/test#TestRestriction> rdf:type owl:Class ;
                                           rdfs:subClassOf [ rdf:type owl:Restriction ;
                                                             owl:onProperty <http://www.onto.com/test#isPartOf2> ;
                                                             owl:minQualifiedCardinality "0"^^xsd:nonNegativeInteger ;
                                                             owl:onClass <http://www.onto.com/test#A2PartOfClass>
                                                           ] ;
                                           rdfs:comment "A1 PartOf Class Comment"@en ;
                                           rdfs:label "A1PartOfClass"@en .


<http://www.onto.com/test#isPartOf2> rdf:type owl:Class .

为此,我在OWL API中有以下代码来检查对OWL2DL配置文件的给定本体的违反。

OWL2DLProfile profile = new OWL2DLProfile();
OWLProfileReport report = profile.checkOntology(ontology);
for(OWLProfileViolation v:report.getViolations()) {
   System.out.println(v);
}

在控制台中我得到了这个:

Use of non-simple property in a restriction: ObjectMinCardinality(0 <http://www.onto.com/test#isPartOf2> <http://www.onto.com/test#A2PartOfClass>) [SubClassOf(<http://www.onto.com/test#TestRestriction> ObjectMinCardinality(0 <http://www.onto.com/test#isPartOf2> <http://www.onto.com/test#A2PartOfClass>)) in OntologyID(OntologyIRI(<http://www.onto.com/test#>) VersionIRI(<null>))]

我想检索所涉及的URI,即http://www.onto.com/test#isPartOf2http://www.onto.com/test#A2PartOfClass 以及违规的信息,即在限制中使用非简单财产。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以按照以下方式获取违规所涉及的公理的签名:

violation.getAxiom()
  .signature()
  .forEach(System.out::println);

除了执行以下操作外,没有简单的方法来获取违规类型:

violation.getClass().getSimpleName()

将返回UseOfNonSimplePropertyInCardinalityRestriction