简体   繁体   English

耶拿; 属性的域和范围因所选推理器而异

[英]Jena; Domains and Ranges for a property differs upon selected Reasoner

Using Jena, I am trying to get domains and ranges for a property. 使用Jena,我试图获取属性的域和范围。

Let's consider the following ontology 让我们考虑以下本体论

 @prefix : <http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#> .
 @prefix owl: <http://www.w3.org/2002/07/owl#> .
 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 @prefix xml: <http://www.w3.org/XML/1998/namespace> .
 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 @base <http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82> .

<http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82> rdf:type owl:Ontology .

:P rdf:type owl:ObjectProperty ;   
   rdfs:domain :A1 ;   
   rdfs:range :B1 .

:A rdf:type owl:Class .

:A1 rdf:type owl:Class ;    
    rdfs:subClassOf :A .

:A2 rdf:type owl:Class ;    
    rdfs:subClassOf :A1 .

:B rdf:type owl:Class .

:B1 rdf:type owl:Class ;
    rdfs:subClassOf :B .

:B2 rdf:type owl:Class ;    
    rdfs:subClassOf :B1 .

As we can see, A1 is the domain of P and B1 is its range. 我们可以看到,A1是P的域,B1是它的范围。 According to OWL semantics we can infer that A is also a domain for P and B is also a range for it see here . 据OWL语义我们可以推断,A也是对于P域和B也是一个范围,它在这里看到

However, using Jena with a reasoner don't always give the expected behavior. 但是,使用带有推理器的Jena并不总能给出预期的行为。 Let's differentiate two situations, the first is using Pellet reasoner, and the second is using OWL_DL_MEM_RULE_INF 让我们区分两种情况,第一种是使用Pellet推理器,第二种是使用OWL_DL_MEM_RULE_INF

Code

import org.mindswap.pellet.jena.PelletReasonerFactory;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class Test{
    public static void main (String [] args)
{                       

    OntModel ontModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
    /*OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);*/
    ontModel.read("path_to_ontology",  "RDF/XML");                              
    ontModel.setStrictMode(false); 


    String myNS = ontModel.getNsPrefixURI("");              

Resource r = ontModel.getResource(myNS + "P" );     
    OntProperty prop = (OntProperty) r.as( OntProperty.class);
    ExtendedIterator <OntClass> opDomains = (ExtendedIterator <OntClass>) prop.listDomain();                        
    while(opDomains.hasNext()){
        OntClass domain = opDomains.next();
        System.out.println("DOMAIN: " + domain.getURI());
    }       

    ExtendedIterator <OntClass> opRanges = (ExtendedIterator <OntClass>) prop.listRange();
    while(opRanges.hasNext()){
        OntClass ran = opRanges.next();
        System.out.println("RANGE: " + ran.getURI());
    }
}
}

Using Pellet: this gives the following output: 使用Pellet:这给出了以下输出:

DOMAIN: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#A1
RANGE: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#B1

Using OWL_DL_MEM_RULE_INF: this gives the following output: 使用OWL_DL_MEM_RULE_INF:这给出了以下输出:

DOMAIN: http://www.w3.org/2002/07/owl#Thing
DOMAIN: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#A1
DOMAIN: http://www.w3.org/2000/01/rdf-schema#Resource
DOMAIN: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#A
RANGE: http://www.w3.org/2002/07/owl#Thing
RANGE: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#B1
RANGE: http://www.w3.org/2000/01/rdf-schema#Resource
RANGE: http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#B   

Question: 题:

1- Why is this difference happenning? 1-为什么会出现这种差异?

2- What are the correct conclusions? 2-正确的结论是什么?

3- Is there some way to enforce Pellet to give results similar to OWL_DL_MEM_RULE_INF? 3-是否有某种方法可以强制Pellet提供类似于OWL_DL_MEM_RULE_INF的结果?

Rather than enumerating domain and range try asking whether a property has a given domain or range: 而不是枚举域和范围尝试询问属性是否具有给定的域或范围:

import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
...
Collection<Resource> classes = Arrays.asList(
    createResource("http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#A"),
    createResource("http://www.semanticweb.org/eng.medianhilal/ontologies/2015/2/untitled-ontology-82#B")
);
...
for (Resource theClass: classes) {
    if (prop.hasRange(theClass) System.out.printf("RANGE: %s\n", theClass);
    if (prop.hasDomain(theClass) System.out.printf("DOMAIN: %s\n", theClass);
}

What I think you'll find is that pellet will report ranges and domains as expected. 我认为你会发现,pellet将按预期报告范围和域。 This is a difference in the way reasoners work: jena's built in reasoner is a hybrid rule engine working over rdf, whereas pellet is an OWL reasoner. 这是reasoners工作方式的不同之处:jena的内置推理器是一个在rdf上工作的混合规则引擎,而pellet是一个OWL推理器。 In practice what this means is that the inferred triples are not obviously present. 在实践中,这意味着推断的三元组显然不存在。

Pellet has an FAQ which explains some of the differences, and how to extract all inferences. Pellet有一个常见问题解答 ,解释了一些差异,以及如何提取所有推论。

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

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