简体   繁体   English

耶拿在本体论上的验证规则

[英]Jena Rule for Validation af a Ontology

I want to validate an ontology and throw an error if anything is incorrect. 我想验证本体并在出现任何错误时抛出错误。

The most validation I have to do looks like this: I have a class like this: 我必须做的最多验证看起来像这样:我有一个这样的类:

   <owl:Class rdf:about="&schema;ExampleClass">
        <rdfs:subClassOf rdf:resource="&schema;SuperClass"/>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&schema;myProperty"/>
                <owl:onClass rdf:resource="&schema;OtherClass"/>
                <owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
            </owl:Restriction>
        </rdfs:subClassOf>
    </owl:Class>

(The interesting part is the 2nd subClassOf.) In Protege this means ExampleClass is subClass of myProperty exactly 1 OtherClass . (有趣的部分是第二个subClassOf。)在Protege中,这意味着ExampleClass is subClass of myProperty exactly 1 OtherClass

So I want to validate that there is exactly one myProperty with value: an individual of type OtherClass. 所以我想验证只有一个myProperty值:一个类型为OtherClass的个体。

Is it possible to validate rules like this? 是否可以验证这样的规则? Perfect would be if there would be a rule to do this for all classes with this modeling (and maybe with also at least 1, exactly 2, ...) 如果有一个规则可以为所有类使用此建模执行此操作(并且可能还至少为1,正好为2,...),那将是完美的。

Another question is: Is there a ready closed world reasoner that is doing exactly that for me? 另一个问题是:是否有一个现成的封闭世界推理器正在为我做这个?

Your example doesn't depend on the utilization of a closed-world principle. 您的示例不依赖于封闭世界原则的使用。 It depends on the introduction of a validation rule for owl:qualifiedCardinality . 这取决于owl:qualifiedCardinality的验证规则的引入。

For example, let us take the sample input file that follows: 例如,让我们获取以下示例输入文件:

@prefix xsd:  <http://www.w3.org/2001/XMLSchema#>.
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl:  <http://www.w3.org/2002/07/owl#>.
@prefix : <urn:x-so:ex#>.

:OtherClass a owl:Class .
:SuperClass a owl:Class .

:myProperty a rdf:Property
          ; rdfs:range  :OtherClass
          .

:ExampleClass rdfs:subClassOf :SuperClass
            ; rdfs:subClassOf [ a owl:Restriction
                              ; owl:onProperty :myProperty
                              ; owl:cardinality 1
#                             ; owl:onClass :OtherClass
#                             ; owl:qualifiedCardinality 1
                              ]
            .


:o0 a :OtherClass .
:o1 a :OtherClass .

:s0 rdf:type    :ExampleClass
  ; :myProperty :o0
  ; :myProperty :o1
  .

Note the commented-out lines and the introduced axiom above them. 注意注释掉的线和它们上面引入的公理。 This ontology is owl-1 compliant, so there are validation rules for it. 这个本体是符合owl-1的,所以它有验证规则。 In the following test there is no validation error, why? 在以下测试中没有验证错误,为什么? because we can infer that, for example, :o0 owl:sameAs :o1 which results in no contradiction. 因为我们可以推断出,例如:o0 owl:sameAs :o1导致没有矛盾。

final Model baseModel = ModelFactory.createDefaultModel();
try( final InputStream in = this.getClass().getResourceAsStream("/so.ttl") ){
    baseModel.read(in, null, "TTL");
}
final OntModel model  = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF, baseModel);

assertTrue(model.contains(s0, myProperty, o0));
assertTrue(model.contains(s0, myProperty, o1));

final ValidityReport report = model.validate();
assertTrue( report.isValid() );

In the next example however, we demonstrate that if we introduce :o0 owl:differentFrom :o1 , then we derive a contradiction: 然而,在下一个例子中,我们证明如果我们引入:o0 owl:differentFrom :o1 ,那么我们得出一个矛盾:

final Model baseModel = ModelFactory.createDefaultModel();
try( final InputStream in = this.getClass().getResourceAsStream("/so.ttl") ){
    baseModel.read(in, null, "TTL");
}
final OntModel model  = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF, baseModel);
model.add(o1, OWL.differentFrom, o0); // NOTE!!
assertTrue(model.contains(s0, myProperty, o0));
assertTrue(model.contains(s0, myProperty, o1));

final ValidityReport report = model.validate();
assertFalse( report.isValid() );

Given the demonstrated scenario, I'd propose the following solutions (in order of ascending difficulty): 鉴于已演示的场景,我建议采用以下解决方案(按难度递增的顺序):

Solution 1: Open-World with OWL 1 Constraints 解决方案1:具有OWL 1约束的开放世界

Express your ontology in terms of owl-1 constraints if possible, and then you can utilize the existing rule sets for validation. 如果可能,根据owl-1约束表达您的本体,然后您可以利用现有规则集进行验证。

Solution 2: Open-World with OWL 2 Additions 解决方案2:使用OWL 2添加的开放世界

This is not going to be easy. 这并不容易。 Take a look at etc/owl-fb.rules in jena-core and you'll note that support of some generic owl constructs (most notably, cardinality) required the development of Jena Builtin to make the rule expression simple. 看看etc/owl-fb.rules jena-core中的etc/owl-fb.rules你会注意到一些通用owl结构(最值得注意的是基数)的支持需要开发Jena Builtin来使规则表达式变得简单。 I linked to another answer regarding builtins if that is the direction that you intend to go. 我链接到另一个关于内置的答案,如果这是你打算去的方向。

The following rules come from jena-core 's etc/owl-fb.rules file to describe cardinality. 以下规则来自jena-coreetc/owl-fb.rules文件来描述基数。 They are not the complete set of cardinality rules. 它们不是完整的基数规则集。

[restriction5: (?C owl:onProperty ?P), (?C owl:cardinality ?X)
  -> (?C owl:equivalentClass card(?P, ?X)),
     (?C rdfs:subClassOf min(?P, ?X)),
     (?C rdfs:subClassOf max(?P, ?X)) ]

[restriction4: (?C owl:onProperty ?P), (?C owl:maxCardinality ?X)
  -> (?C owl:equivalentClass max(?P, ?X)) ]

[validationMaxN: (?v rb:validation on()), (?C rdfs:subClassOf max(?P, ?N)) greaterThan(?N, 1) (?P rdf:type owl:DatatypeProperty) ->
    [max2b: (?X rb:violation error('too many values', 'Too many values on max-N property (prop, class)', ?P, ?C))
          <- (?X rdf:type ?C), countLiteralValues(?X, ?P, ?M), lessThan(?N, ?M)  ] ]

restriction5 simply defines cardinality in terms of min and max cardinality ( min and max in this example are Functors). restriction5只根据最小和最大基数定义基数(本例中的minmax为Functors)。 validationMaxN is the particular rule (for N > 1) that shows how a violation can be identified. validationMaxN是特定规则(对于N> 1),显示如何识别违规。 It delegates to the CountLiteralValues builtin to identify the number of bindings that exist for the property. 它委托内置的CountLiteralValues来识别属性存在的绑定数。

If you are willing to introduce a CountQualifiedValues Builtin, then you could define a set of rules similar to the following to introduce the new axioms: 如果您愿意引入CountQualifiedValues Builtin,那么您可以定义一组类似于以下的规则来介绍新的公理:

[restriction4: (?C owl:onProperty ?P), (?C owl:maxQualifiedCardinality ?X), (?C owl:onClass ?Y)
  -> (?C owl:equivalentClass max(?P, ?X, ?Y)) ]

[validationMaxN: (?v rb:validation on()), (?C rdfs:subClassOf max(?P, ?N, ?Y)) greaterThan(?N, 1) (?P rdf:type owl:ObjectProperty) ->
    [max2b: (?X rb:violation error('too many values', 'Too many values on max-QN property (prop, class, qclass)', ?P, ?C, ?Y))
          <- (?X rdf:type ?C), countQualifiedValues(?X, ?P, ?Y, ?M), lessThan(?N, ?M)  ] ]

Solution 3: Closed-World with OWL 2 Additions 解决方案3:封闭世界,增加了OWL 2

This is actually not all that different from Solution 2. You will, however, be trying to define alternative semantics for OWL constructs, which is a nontrivial problem. 这实际上与解决方案2并没有什么不同。但是,您将尝试为OWL构造定义替代语义,这是一个非常重要的问题。 You can introduce a few rules for validation (take a read of etc/owl-fb.rules to get examples) that capture your particular closed-world assumptions. 您可以引入一些用于验证的规则(读取etc/owl-fb.rules以获取示例),捕获您特定的封闭世界假设。 If you enforce that they are restricted to only operate when (?v rb:validation on()) , then you can ensure that you are only assuming a closed-world when you are performing validation. 如果强制它们仅限于(?v rb:validation on()) ,那么您可以确保在执行验证时只假设一个封闭世界。

Side Discussion 侧面讨论

Here is an example of a cardinality restriction expressed in owl 1. It is the same as the one in the input file above. 以下是owl 1中表示的基数限制的示例。它与上面输入文件中的基数限制相同。 This is expressed in TURTLE syntax and is trivial to transform to RDF/XML or any of the other valid RDF serializations. 这用TURTLE语法表示,并且很容易转换为RDF/XML或任何其他有效的RDF序列化。

:ExampleClass rdfs:subClassOf :SuperClass
            ; rdfs:subClassOf [ a owl:Restriction
                              ; owl:onProperty :myProperty
                              ; owl:cardinality 1
                              ]
            .

This pair of restrictions is not exactly semantically equivalent to owl:qualifiedCardinality , but, if you have the ability to modify your domain model, you can often work around it. 这对限制在语义上并不等同于owl:qualifiedCardinality ,但是,如果您能够修改域模型,则通常可以解决它。

For example, owl:qualifiedCardinality is great to say things like :People :haveBodyPart exactly 2 :Eyes . 例如, owl:qualifiedCardinality非常适合说:People :haveBodyPart exactly 2 :Eyes The OWL 1 workaround could be, for example, to create a :haveEye rdfs:subPropertyOf :haveBodyPart and then say :People :haveEye exactly 2 (without qualified cardinality restriction) 例如,OWL 1解决方法可能是创建一个:haveEye rdfs:subPropertyOf :haveBodyPart然后说:People :haveEye exactly 2 (没有合格的基数限制)

It sounds like you're trying to check some integrity constraints based on some OWL axioms, but it's important to note that OWL is based on the open-world assumption. 听起来你正试图根据一些OWL公理检查一些完整性约束,但重要的是要注意OWL是基于开放世界的假设。 That means that even if you have: 这意味着,即使你有:

Person ⊑ ∃hasParent.Person 人⊑⊑hasParent.Person

which says that every person has (at least) one value of the hasParent property with a value that is another Person individual, you can still have a consistent ontology that doesn't include any hasParent assertions at all! 这表示每个人都有(至少)hasParent属性的一个值,其值是另一个Person个体,你仍然可以拥有一个不包含任何hasParent断言的一致本体! So the kind of "validation" that you're looking for is really more about a closed world and complete interpretation. 因此,您正在寻找的那种“验证”更多地是关于一个封闭的世界和完整的解释。

Rather than using a rules based approach, I'd probably attack this problem using some SPARQL queries to check for individuals that don't satisfy the things we expect them to satisfy. 我可能会使用一些SPARQL查询来检查那些不满足我们期望它们满足的事物的个体,而不是使用基于规则的方法。 For instance, in this case, you could write a general rule that looks individuals that are instances of restrictions, and then you can check whether you can find triples in the data that "match" the restriction. 例如,在这种情况下,您可以编写一个查看作为限制实例的个人的一般规则,然后您可以检查是否可以在“匹配”限制的数据中找到三元组。

For this particular case, you can find (some) instances of (myProperty exactly 1 OtherClass) (and qualified cardinalities in general) with: 对于这种特殊情况,您可以找到(某些) (myProperty恰好1个OtherClass) (以及一般的合格基数)的实例:

?instance a [ owl:onProperty ?property ;
              owl:onClass ?class ;
              owl:qualifiedCardinality ?cardinality ] .

Of course, if some individual can only be inferred to be an instance of the class, that pattern won't find it, but we're assuming that you're working with a closed-world and complete data, so something like that should work. 当然,如果某个人只能被推断为该类的一个实例,那么该模式将无法找到它,但我们假设您正在使用封闭世界和完整数据,所以这样的事情应该是工作。 ("Something like" could include ?instance a/rdfs:subClassOf* [ ... ] .) Once you've got that, you can write a subquery that checks whether the data "matches": (“类似的东西”可以包括?instance a/rdfs:subClassOf* [ ... ] 。)一旦你有了,你可以编写一个子查询来检查数据是否“匹配”:

select ?instance ?property ?class (count(?value) as ?actualCardinality) where {
  ?instance ?property ?value .
  ?value a ?class
}
group by ?instance ?property ?class 

Then you can combine these to identify individuals where the ?actualCardinality doesn't match ?cardinality: 那么你可以将这些结合起来来识别那些?actualCardinality不匹配的个体?基数:

select ?instance
       ?property
       ?class
       ?cardinality
       (count(?value) as ?actualCardinality)
where {
  ?instance a [ owl:onProperty ?property ;
                owl:onClass ?class ;
                owl:qualifiedCardinality ?cardinality ] .

  ?instance ?property ?value .
  ?value a ?class
}
group by ?instance ?property ?class ?cardinality
having ( ?cardinality != ?actualCardinality )

I haven't tested any of this yet, so there may be typos, and you haven't provided complete data, so I can't test on that either, but something in this general line should be workable. 我还没有测试过任何这个,所以可能有拼写错误,而且你还没有提供完整的数据,所以我也无法对它进行测试,但是这条通用的东西应该是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM