2

owl2rl オントロジー推論に OWLIM-lite (5.2) を使用しています。公理の保存は機能しているようで、リポジトリは初期化されていますが、システムは暗黙的なステートメントを推論しません (暗黙的なステートメントの数を照会すると、システムは 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 に答える