[英]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.