2

我正在使用 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);
    }
}
4

1 回答 1

1

终于找到问题了。配置没问题,错误出在本体上。OWL2RL 不支持(X 或 Y)形式的超类,因此 OWLIM 没有推理它。由于 Pellet 是 DL 并且具有此功能,因此它按预期进行推理。

我认为 owlim 会检查一致性,但事实并非如此。因此,如果您遇到类似问题,请先尝试此配置文件验证器

于 2012-08-27T14:57:45.743 回答