[英]Difference in owl:hasValue and owl:oneOf support in Jena's OWLMicroReasoner?
我正在使用值限制从其值信息派生实例类型:
: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
]
)
] .
单个值限制owl:hasValue
可以正常工作,并且:Mission11
类型的SPARQL按预期返回:SpaceMission和:ApolloMission
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
)
]
]
)
] .
(限制类型已自动从owl:hasValue
更改为owl:someValuesFrom
)。 在这种情况下类型的预期推断:ApolloMission
对个人:Mission11
不返回,但只有:SpaceMission
。 我有什么问题吗? 还是仅在owl:hasValue
类型的值限制下才可能进行类型推断?
我正在使用耶拿的OWLMicroReasoner并为{<:Mission11> a ?type}
运行SPARQL查询。 也许它不能从owl:someValuesFrom
限制中推断出来。 就像我说的那样, owl:hasValue
限制确实适用于耶拿的微推理器。 Jena的内置推理机是否支持owl:someValuesFrom
限制?
如果您可以提供我们可以用来测试的整个本体,那么通常更有用。 这不是太大,因此重新创建也不太困难。 无论如何,我已经复制了它,并且它包含在此答案的结尾。
您正在寻找的推论在OWL中是有效的,我们可以通过使用逻辑上完整的OWL推理程序(例如Pellet)来看到这一点。 我们将在Protégé中看到这一点(但您也可以将Pellet与Jena一起使用。)这是在Protégé中重新创建的本体的样子:
然后,当我们启用Pellet推理程序并请求ApolloMission的实例时,将按预期获得Mission11 :
既然您说的是要询问Mission11的类型,也许您使用了类似查询{Mission11}的超类的查询。 这也会产生预期的类:
@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 .
耶拿的推理机还不完整 。 这并不意味着他们还没有完成。 complete是形式化推理中的技术术语,用于描述推理器(或算法等),这意味着根据推理器不会产生的语言的语义,存在正确的推论。 Jena的推理程序不完整的原因与实施策略(使用基于规则的推理机)以及效率方面的考虑(我们可以接受速度和所获得的推理之间的权衡)有关。
有关Jena的推理程序的更多信息,您应该查看推理机和规则引擎:文档中的Jena推理支持 。 但是,它并不完全是最新的,例如,它说:
Jena OWL推理程序中不支持OWL / lite以外的关键构造是complementOf和oneOf。 如上所述,对unionOf的支持是部分的(由于基于规则的方法的局限性),但对于遍历类层次结构很有用。
但如下面的代码显示,还有就是 ,事实上,支持owl:oneOf
中的一些推理的,所以一些推理可以使您想要的ApolloMission推断。
耶拿(Jena)提供了许多推理程序,而获取连接到它们的OntModel的最简单方法是使用在OntModelSpec中声明的静态OntModelSpecs。 以下Java代码显示,使用您提供的最终本体,不同的推理程序将提供不同的结果。 (用于获取不同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());
}
}
}
}
输出如下。 一些推理者可以推断出Mission11是ApolloMission。 这些是规范所使用的: OWL_MEM_RULE_INF
, OWL_MEM_MINI_RULE_INF
, OWL_DL_MEM_RULE_INF
和OWL_LITE_MEM_RULES_INF
。 看来您可能想坚持使用名称为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.