Question

I am using OWLIM-lite (5.2) for owl2rl ontology reasoning. Storing of axioms seems to work, repository initialized, but the system does not infer any implicit statements (when I query number of implicit statements, the system returns 0).

I also tried to query the repository, the system returned only explicit knowledge. When I serialized the ontology into RDF/XML and reasoned it in Protege using Pellet, the it successfully returned expected (implicit+explicit) values.

Thanks for any suggestions.

Config:

[] 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"

      ]
   ].

Repository initialization:

    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);

}

How am I loading the ontology:

    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);
    }
}

New knowledge storing:

private void addStatement(URI subject, URI property, URI object) {
    try {
        repositoryConnection.add(subject, property, object);
        repositoryConnection.commit();
    } catch (RepositoryException ex) {
        throw new RuntimeException(ex);
    }
}
Was it helpful?

Solution

Finally found the issue. The config is OK, mistake was in the ontology. OWL2RL does not support superclass in a form of (X or Y), hence OWLIM did not reason it. Since Pellet is DL and has this feature, it reasoned as expected.

I thought that owlim will check the conformance, but it does not. So if you run into simillar issue try first this profile validator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top