简体   繁体   English

Jena的OWLMicroReasoner中对owl:hasValue和owl:oneOf支持的区别?

[英]Difference in owl:hasValue and owl:oneOf support in Jena's OWLMicroReasoner?

I'm playing with deriving instance type from its value information using value restrictions: 我正在使用值限制从其值信息派生实例类型:

:SpaceMission rdf:type owl:Class .

:shuttleUsed rdf:type owl:ObjectProperty ;         
             rdfs:domain :SpaceMission .

:Apollo11 rdf:type owl:NamedIndividual .

:Mission11 rdf:type :SpaceMission , owl:NamedIndividual ;           
           :shuttleUsed :Apollo11 .

:ApolloMission rdf:type owl:Class ;               
               owl:equivalentClass [ rdf:type owl:Class ;
                                     owl:intersectionOf ( :SpaceMission
                                                          [ rdf:type owl:Restriction ;
                                                            owl:onProperty :shuttleUsed ;
                                                            owl:hasValue :Apollo11
                                                          ]
                                                        )
                                   ] .

The single value restriction owl:hasValue works fine and the SPARQL for type of :Mission11 returns :SpaceMission and :ApolloMission as expected. 单个值限制owl:hasValue可以正常工作,并且:Mission11类型的SPARQL按预期返回:SpaceMission和:ApolloMission ApolloMission。 Then I add the second value restriction for definition of the class :ApolloMission : 然后,我为类的定义添加了第二个值限制:ApolloMission

:Apollo13 rdf:type owl:NamedIndividual .

:ApolloMission rdf:type owl:Class ;
               owl:equivalentClass [ rdf:type owl:Class ;
                                     owl:intersectionOf ( :SpaceMission
                                                          [ rdf:type owl:Restriction ;
                                                            owl:onProperty :shuttleUsed ;
                                                            owl:someValuesFrom [ rdf:type owl:Class ;
                                                                                 owl:oneOf ( :Apollo11
                                                                                             :Apollo13
                                                                                           )
                                                                               ]
                                                          ]
                                                        )
                                   ] .

(The restriction type has automatically changed from owl:hasValue to owl:someValuesFrom ). (限制类型已自动从owl:hasValue更改为owl:someValuesFrom )。 In this case the expected inference of type :ApolloMission for the individual :Mission11 is not returned, but only the :SpaceMission . 在这种情况下类型的预期推断:ApolloMission对个人:Mission11不返回,但只有:SpaceMission Do I have something wrong? 我有什么问题吗? Or the the type inference is only possible with value restriction of type owl:hasValue ? 还是仅在owl:hasValue类型的值限制下才可能进行类型推断?

I'm using Jena's OWLMicroReasoner and running the SPARQL query for {<:Mission11> a ?type} . 我正在使用耶拿的OWLMicroReasoner并为{<:Mission11> a ?type}运行SPARQL查询。 Maybe it is not able to infer from owl:someValuesFrom restriction. 也许它不能从owl:someValuesFrom限制中推断出来。 As I said the owl:hasValue restriction did work with Jena's micro reasoner. 就像我说的那样, owl:hasValue限制确实适用于耶拿的微推理器。 Does Jena's built-in reasoner support the owl:someValuesFrom restriction? Jena的内置推理机是否支持owl:someValuesFrom限制?

It's generally more helpful if you can provide an entire ontology that we can work with for testing. 如果您可以提供我们可以用来测试的整个本体,那么通常更有用。 This one isn't too big, so it wasn't too hard to recreate. 这不是太大,因此重新创建也不太困难。 At any rate, I've reproduced it, and it's included at the end of this answer. 无论如何,我已经复制了它,并且它包含在此答案的结尾。

The inference is valid in OWL 推论在OWL中有效

The inference you're looking for is valid in OWL, and we can see that by using a logically complete OWL reasoner, eg, Pellet. 您正在寻找的推论在OWL中是有效的,我们可以通过使用逻辑上完整的OWL推理程序(例如Pellet)来看到这一点。 We'll see this in Protégé (but you could have used Pellet with Jena, too.) Here's what the ontology, recreated in Protégé look like: 我们将在Protégé中看到这一点(但您也可以将Pellet与Jena一起使用。)这是在Protégé中重新创建的本体的样子:

Protege中的重要类公理

Protege中的重要对象属性公理

Then, when we enable the Pellet reasoner and ask for instances of ApolloMission , we get Mission11 , as expected: 然后,当我们启用Pellet推理程序并请求ApolloMission的实例时,将按预期获得Mission11

ApolloMission将Mission11作为实例

Since you said you were asking for the types of Mission11 , perhaps you used a query like asking for superclass of {Mission11} . 既然您说的是要询问Mission11的类型,也许您使用了类似查询{Mission11}的超类的查询。 This produces the expected classes, too: 这也会产生预期的类:

Mission11具有预期的类型

Reproduced Ontology 复制本体

@prefix :      <http://stackoverflow.com/q/21223545/1281433/space.owl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix space: <http://stackoverflow.com/q/21223545/1281433/space.owl#> .

<http://stackoverflow.com/q/21223545/1281433/space.owl>
        a       owl:Ontology .

space:Mission11  a         owl:NamedIndividual , space:SpaceMission ;
        space:shuttleUsed  space:Apollo11 .

space:shuttleUsed  a  owl:ObjectProperty ;
        rdfs:domain  space:SpaceMission .

space:Apollo13  a  owl:Thing , owl:NamedIndividual .

space:ApolloMission  a       owl:Class ;
        owl:equivalentClass  [ a                   owl:Class ;
                               owl:intersectionOf  ( space:SpaceMission [ a                   owl:Restriction ;
                                                                          owl:onProperty      space:shuttleUsed ;
                                                                          owl:someValuesFrom  [ a          owl:Class ;
                                                                                                owl:oneOf  ( space:Apollo13 space:Apollo11 )
                                                                                              ]
                                                                        ] )
                             ] .

space:SpaceMission  a  owl:Class .

space:Apollo11  a  owl:Thing , owl:NamedIndividual .

Why you don't get some results with Jena's reasoners 为什么您无法通过耶拿的推理机获得一些结果

Jena's reasoners are not complete . 耶拿的推理机还不完整 That doesn't mean that they're not finished; 这并不意味着他们还没有完成。 complete is a technical term in formal reasoning describing a reasoner (or algorithm, etc.) that means that there are correct inferences according to the semantics of the language that the reasoner won't produce. complete是形式化推理中的技术术语,用于描述推理器(或算法等),这意味着根据推理器不会产生的语言的语义,存在正确的推论。 The reason that Jena's reasoners are incomplete has to do with the implementation strategy (using a rule-based reasoner), and with efficiency considerations (we can accept a trade-off between speed and the inferences that we can get). Jena的推理程序不完整的原因与实施策略(使用基于规则的推理机)以及效率方面的考虑(我们可以接受速度和所获得的推理之间的权衡)有关。

For more about Jena's reasoners, you should look at Reasoners and rule engines: Jena inference support from the documentation. 有关Jena的推理程序的更多信息,您应该查看推理机和规则引擎:文档中的Jena推理支持 It's not entirely up to date though, as it says, for instance: 但是,它并不完全是最新的,例如,它说:

The critical constructs which go beyond OWL/lite and are not supported in the Jena OWL reasoner are complementOf and oneOf. Jena OWL推理程序中不支持OWL / lite以外的关键构造是complementOf和oneOf。 As noted above the support for unionOf is partial (due to limitations of the rule based approach) but is useful for traversing class hierarchies. 如上所述,对unionOf的支持是部分的(由于基于规则的方法的局限性),但对于遍历类层次结构很有用。

but as the following code shows, there is , in fact, support for owl:oneOf in some of the reasoners, and so some of the reasoners can make the ApolloMission inference that you want. 但如下面的代码显示,还有就是 ,事实上,支持owl:oneOf中的一些推理的,所以一些推理可以使您想要的ApolloMission推断。

Jena provides a number of reasoners, and the easiest way to get an OntModel that is connected to them is by using the static OntModelSpecs that are declared in OntModelSpec. 耶拿(Jena)提供了许多推理程序,而获取连接到它们的OntModel的最简单方法是使用在OntModelSpec中声明的静态OntModelSpecs。 The following Java code shows that with the final ontology that you provided, the different reasoners provide different results. 以下Java代码显示,使用您提供的最终本体,不同的推理程序将提供不同的结果。 (The reflective code for getting the different OntModelSpecs is a bit hackish, but for a quick example, it's fine.) The code constructs an OntModel for each of the declared specs starting with "OWL_", and runs the query against them. (用于获取不同OntModelSpecs的反射代码有点hacky,但是作为一个简单的示例,它很好。)该代码为每个声明的规范以“ OWL_”开头构造一个OntModel,并对它们运行查询。

import java.lang.reflect.Field;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class JenaReasonersSpaceExample {
    private final static String QUERY =
            "PREFIX : <http://stackoverflow.com/q/21223545/1281433/space.owl#>\n" +
            "select ?type where {\n" +
            "  :Mission11 a ?type .\n" + 
            "}\n";

    private final static Model base =
            ModelFactory.createDefaultModel()
            .read( "file:///home/taylorj/tmp/ontologies/space/space.owl" );

    public static void main(final String[] args) throws IllegalArgumentException, IllegalAccessException {
        // Iterate through the fields of OntModelSpec and for each one whose name
        // begins with "OWL_", assume that it's a static field (so that getField
        // can accept null), and that its value is an OntModelSpec (so that we 
        // can cast and create an OntModel with it and the base model).
        // that begin with "OWL_", and assume t
        for ( final Field field : OntModelSpec.class.getFields() ) {
            if ( field.getName().startsWith("OWL_") ) {
                final OntModelSpec spec = (OntModelSpec) field.get(null);
                final OntModel model = ModelFactory.createOntologyModel( spec, base );

                // Run the query against the model (that will use the specified reasoner)
                // and show the field that we used and the results that we get.
                System.out.println( "\n=== "+field.getName()+" ===" );
                ResultSetFormatter.out(QueryExecutionFactory.create(QUERY, model).execSelect());
            }
        }
    }
}

The output follows. 输出如下。 Some of the reasoners can infer that Mission11 is an ApolloMission. 一些推理者可以推断出Mission11是ApolloMission。 These are the ones used by the specs: OWL_MEM_RULE_INF , OWL_MEM_MINI_RULE_INF , OWL_DL_MEM_RULE_INF , and OWL_LITE_MEM_RULES_INF . 这些是规范所使用的: OWL_MEM_RULE_INFOWL_MEM_MINI_RULE_INFOWL_DL_MEM_RULE_INFOWL_LITE_MEM_RULES_INF It looks like you might want to stick to reasoners that have RULE in the name. 看来您可能想坚持使用名称为RULE推理机。

=== OWL_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_MEM_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| _:b1                                                                  |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
-------------------------------------------------------------------------

=== OWL_MEM_MICRO_RULE_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2002/07/owl#Thing>                                |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_MEM_MINI_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| _:b1                                                                  |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
-------------------------------------------------------------------------

=== OWL_DL_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_DL_MEM_RULE_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
| _:b1                                                                  |
-------------------------------------------------------------------------

=== OWL_LITE_MEM ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_TRANS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_RDFS_INF ===
------------------------------------------------------------------------
| type                                                                 |
========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission> |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                      |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                      |
------------------------------------------------------------------------

=== OWL_LITE_MEM_RULES_INF ===
-------------------------------------------------------------------------
| type                                                                  |
=========================================================================
| <http://stackoverflow.com/q/21223545/1281433/space.owl#SpaceMission>  |
| <http://www.w3.org/2002/07/owl#NamedIndividual>                       |
| <http://www.w3.org/2002/07/owl#Thing>                                 |
| _:b0                                                                  |
| <http://www.w3.org/2000/01/rdf-schema#Resource>                       |
| <http://stackoverflow.com/q/21223545/1281433/space.owl#ApolloMission> |
| _:b1                                                                  |
-------------------------------------------------------------------------

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

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