我正在使用OWLIM-lite(5.2)进行owl2rl本体推理。存储公理似乎有效,存储库已初始化,但系统不会推断任何隐式语句(当我查询隐式语句的数量时,系统返回0)。
我也尝试查询存储库,系统只返回显式知识。当我将本体序列化为RDF / XML并使用Pellet在Protege中对其进行推理时,它成功返回了预期的(隐式+显式)值。感谢您的任何建议。
配置:
[] a rep:Repository ;
rep:repositoryID "example" ;
rdfs:label "OWLIM Getting Started" ;
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository" ;
sr:sailImpl [
sail:sailType "swiftowlim:Sail" ;
owlim:repository-type "in-memory-repository" ;
owlim:ruleset "owl2-rl-reduced-optimized" ;
# owlim:storage-folder "storage" ;
# OWLIM-SE parameters
owlim:cache-memory "180m" ;
# OWLIM-Lite parameters
owlim:noPersist "true" ;
owlim:jobsize "1000" ;
owlim:new-triples-file "new"
]
].
存储库初始化:
private OwlimRepository() throws RepositoryException, RepositoryConfigException, RDFParseException, RDFHandlerException, IOException {
repositoryManager = new LocalRepositoryManager(new File("."));
repositoryManager.initialize();
Graph repositoryRdfDescription = parseFile(new File(this.getClass().getClassLoader().getResource("owlim.ttl").getFile()), RDFFormat.TURTLE, "http://example.org#");
Iterator<Statement> iter = repositoryRdfDescription.match(null, RDF.TYPE, new URIImpl(
"http://www.openrdf.org/config/repository#Repository"));
Resource repositoryNode = null;
if (iter.hasNext()) {
Statement st = iter.next();
repositoryNode = st.getSubject();
}
RepositoryConfig repositoryConfig = RepositoryConfig.create(repositoryRdfDescription,
repositoryNode);
repositoryManager.addRepositoryConfig(repositoryConfig);
repository = repositoryManager.getRepository("example");
repository.initialize();
valueFactory = repository.getValueFactory();
repositoryConnection = repository.getConnection();
repositoryConnection.setAutoCommit(false);
}
我如何加载本体:
public void setRepository(OwlimRepository repository) {
try {
this.repository = repository;
final RDFInserter inserter = new RDFInserter(repository.getRepository().getConnection());
RDFParser parser = Rio.createParser(RDFFormat.RDFXML);
parser.setRDFHandler(new RDFHandler() {
public void startRDF() throws RDFHandlerException {
inserter.startRDF();
}
public void endRDF() throws RDFHandlerException {
inserter.endRDF();
}
public void handleNamespace(String string, String string1) throws RDFHandlerException {
inserter.handleNamespace(string, string1);
}
public void handleStatement(Statement stmnt) throws RDFHandlerException {
try {
System.out.println("inserting: " + stmnt);
inserter.handleStatement(stmnt);
OwlimSparqlProcessor.this.repository.getRepositoryConnection().commit();
} catch (RepositoryException ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
public void handleComment(String string) throws RDFHandlerException {
inserter.handleComment(string);
}
});
parser.parse(new BufferedInputStream(new FileInputStream(OwlimSparqlProcessor.class.getClassLoader().getResource("odra-ontology.owl").getFile())), OntologyConstants.ODRA_ONTOLOGY_BASE);
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
新知识存储:
private void addStatement(URI subject, URI property, URI object) {
try {
repositoryConnection.add(subject, property, object);
repositoryConnection.commit();
} catch (RepositoryException ex) {
throw new RuntimeException(ex);
}
}
答案 0 :(得分:1)
终于找到了问题。配置没问题,错误在本体中。 OWL2RL不支持(X或Y)形式的超类,因此OWLIM没有推理它。由于Pellet是DL并具有此功能,因此可以按预期进行推理。
我认为owlim会检查一致性,但事实并非如此。因此,如果您遇到simillar问题,请先尝试this profile validator。