owlcs / ont-api

ONT-API (OWL-API over Apache Jena)
44 stars 5 forks source link

SPARQL query doesn't update the ontology #52

Closed shuxianpan closed 10 months ago

shuxianpan commented 11 months ago

Hello, I was using the codes from example 8) in Wiki, but it seems that the ontology I got still has AnnotationProperty in it, and the ObjectProperty did not replace them. I used ontapi 3.0.4, owlapi-distribution 5.5.0, apache-jena 4.5.0 and jena-arq 4.5.0. The output I got is as follows:

Declaration(AnnotationProperty(<http://ex.com/test#prop1>))
Declaration(AnnotationProperty(<http://ex.com/test#prop2>))
Declaration(Class(<http://ex.com/test#class1>))
ClassAssertion(<http://ex.com/test#class1> <http://ex.com/test#indi1>)
AnnotationAssertion(<http://ex.com/test#prop1> _:7c02ddfe-45c2-48ee-8e23-558b6b2032d8 <http://ex.com/test#indi1>)
SubAnnotationPropertyOf(<http://ex.com/test#prop2> <http://ex.com/test#prop1>)
AnnotationPropertyDomain(<http://ex.com/test#prop1> <http://ex.com/test#class1>)
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

<http://ex.com/test#prop1>
        rdf:type     owl:AnnotationProperty ;
        rdfs:domain  <http://ex.com/test#class1> .

<http://ex.com/test#prop2>
        rdf:type            owl:AnnotationProperty ;
        rdfs:subPropertyOf  <http://ex.com/test#prop1> .

[ <http://ex.com/test#prop1>  <http://ex.com/test#indi1> ] .

<http://ex.com/test>  rdf:type  owl:Ontology .

<http://ex.com/test#class1>
        rdf:type  owl:Class .

<http://ex.com/test#indi1>
        rdf:type  <http://ex.com/test#class1> , owl:NamedIndividual .

I merely changed anything in the example except OWLDataFactory df = m.getOWLDataFactory(); as DataFactory df = m.getOWLDataFactory();. The classes I imported are:

import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.update.UpdateAction;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;

import com.github.owlcs.ontapi.DataFactory;
import com.github.owlcs.ontapi.OntManagers;
import com.github.owlcs.ontapi.Ontology;
import com.github.owlcs.ontapi.OntologyManager;

I also tried to remove the parts for updating / printing declaration and got a slightly different output. Removing updating or printing declaration printed [ <http://ex.com/test#prop1> <http://ex.com/test#indi1> ] . at the end of the output. Removing both printed [ <http://ex.com/test#prop1> <http://ex.com/test#indi1> ] . between prop1 and prop2.

Update: I used my local OWL ontology file, and it worked. Possibly, the issue is relevant to creat a new ontology, but I haven't tested that part.

sszuev commented 11 months ago

Hello,

Can't reproduce.

But found a bug #53 , old bug, nobody noticed = (

In the example 8 the ontology is printed to System.out twice: before and after update. Do you see the both outputs? If not, then the reason is that System.out is closed.

SPARQL support is provided by Jena itself, so this is unlikely to be an ONT-API bug.