耶拿本体论验证规则 [英] Jena Rule for Validation af a Ontology

查看:85
本文介绍了耶拿本体论验证规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证一个本体并在任何不正确的地方抛出一个错误.

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>

(有趣的部分是第二个subClassOf.) 在Protege中,这表示ExampleClass is subClass of myProperty exactly 1 OtherClass.

(The interesting part is the 2nd subClassOf.) In Protege this means ExampleClass is subClass of myProperty exactly 1 OtherClass.

因此,我想验证是否只有一个myProperty带有值:OtherClass类型的个体.

So I want to validate that there is exactly one myProperty with value: an individual of type OtherClass.

是否可以验证这样的规则?完美的做法是,如果有一个规则可以对所有使用此建模的类执行此操作(也许也至少要包含1个,正好是2个,...)

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, ...)

另一个问题是:是否有现成的封闭世界推理机正在为我做这些事情?

Another question is: Is there a ready closed world reasoner that is doing exactly that for me?

推荐答案

您的示例不依赖于封闭世界原理的利用.这取决于对owl:qualifiedCardinality的验证规则的引入.

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.

例如,让我们获取以下示例输入文件:

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
  .

请注意注释掉的行以及它们上方的引入的公理.该本体是owl-1兼容的,因此有验证规则.在以下测试中,没有验证错误,为什么?因为我们可以推断出,例如:o0 owl:sameAs :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. 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.

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() );

但是,在下一个示例中,我们演示了如果引入:o0 owl:differentFrom :o1,则会得出矛盾:

In the next example however, we demonstrate that if we introduce :o0 owl:differentFrom :o1, then we derive a contradiction:

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):

解决方案1:具有OWL 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.

解决方案2:具有OWL 2附加功能的开放世界

这并不容易.看一下jena-core中的etc/owl-fb.rules,您会注意到,对某些通用猫头鹰构造(最著名的是基数)的支持需要

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. I linked to another answer regarding builtins if that is the direction that you intend to go.

以下规则来自jena-coreetc/owl-fb.rules文件,用于描述基数.它们不是完整的基数规则.

The following rules come from jena-core's etc/owl-fb.rules file to describe cardinality. 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仅根据最小和最大基数定义基数(在此示例中,minmax是Functors). validationMaxN是特定规则(对于N> 1),显示了如何识别违规情况.它委托给

restriction5 simply defines cardinality in terms of min and max cardinality (min and max in this example are Functors). validationMaxN is the particular rule (for N > 1) that shows how a violation can be identified. It delegates to the CountLiteralValues builtin to identify the number of bindings that exist for the property.

如果您愿意引入CountQualifiedValues内置函数,则可以定义类似于以下内容的规则集以引入新的公理:

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:

[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)  ] ]

解决方案3:添加OWL 2的封闭世界

这实际上与解决方案2并没有什么不同.但是,您将尝试为OWL构造定义替代语义,这是一个不小的问题.您可以引入一些验证规则(请阅读etc/owl-fb.rules以获得示例),这些规则可以捕获您的特定封闭世界假设.如果您强制将它们限制为只能在(?v rb:validation on())时运行,那么可以确保在执行验证时仅假设自己是封闭世界.

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. 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. 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.

旁讨论

这里是猫头鹰1中表示的基数限制的示例.它与上面的输入文件中的基数限制相同.这用TURTLE语法表示,对于转换为RDF/XML或任何其他有效的RDF序列化而言,是微不足道的.

Here is an example of a cardinality restriction expressed in owl 1. It is the same as the one in the input file above. This is expressed in TURTLE syntax and is trivial to transform to RDF/XML or any of the other valid RDF serializations.

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

这对限制在语义上并不完全等同于owl:qualifiedCardinality,但是,如果您能够修改域模型,则通常可以解决它.

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非常适合说:People :haveBodyPart exactly 2 :Eyes之类的东西. OWL 1的解决方法是,例如,创建:haveEye rdfs:subPropertyOf :haveBodyPart然后说:People :haveEye exactly 2(没有合格的基数限制)

For example, owl:qualifiedCardinality is great to say things like :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)

这篇关于耶拿本体论验证规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆