Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-1415

ConversionException for individuals

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: Jena 3.4.0
    • Fix Version/s: None
    • Component/s: ARQ, Jena
    • Labels:
      None
    • Environment:

      Linux, Maven, Openllet Reasoner

      Description

      Hey there,
      I'm getting a ConversionException when converting a resource to an individual by using as.

      [EDIT] Edited this report because I could reproduce this error in a little example.
      Jena throws a ConversionErrorException when trying to cast a Resource with as to an individual. The resource is received by a query as suggested here https://github.com/Galigator/openllet/blob/integration/examples/src/main/java/openllet/examples/SPARQLDLExample.java

      This is the test code:

      package bug;
      
      import openllet.jena.PelletReasonerFactory;
      import openllet.query.sparqldl.jena.SparqlDLExecutionFactory;
      import org.apache.jena.ontology.OntModel;
      import org.apache.jena.query.Query;
      import org.apache.jena.query.QueryExecution;
      import org.apache.jena.query.QueryFactory;
      import org.apache.jena.query.QuerySolution;
      import org.apache.jena.query.ResultSet;
      import org.apache.jena.query.ResultSetFormatter;
      import org.apache.jena.rdf.model.ModelFactory;
      import org.apache.jena.ontology.Individual;
      import org.apache.jena.ontology.OntClass;
      import org.apache.jena.util.iterator.ExtendedIterator;
      
      import java.util.ArrayList;
      
      public class SPARQLDLBug
      {
      
      	// The ontology loaded as dataset
      	private static final String ontology = "ontologies/simple.owl";
      
      	private static final String query = "query.sparql";
      	public void run()
      	{
      			// First create a Jena ontology model backed by the Pellet reasoner
      			// (note, the Pellet reasoner is required)
      			final OntModel m = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
      
      			// Then read the _data from the file into the ontology model
      			m.read(ontology);
      
      			// Now read the query file into a query object
      			final Query q = QueryFactory.read(query);
      
      			// Create a SPARQL-DL query execution for the given query and
      			// ontology model
      			final QueryExecution qe = SparqlDLExecutionFactory.create(q, m);
      
      			// We want to execute a SELECT query, do it, and return the result set
      			final ResultSet rs = qe.execSelect();
      
      			ArrayList<String> result = new ArrayList<String>();
      
      			while(rs.hasNext()){
      				QuerySolution qs = rs.next();
                                      // The Bug occurs in the next line
      				Individual in = qs.getResource("x").as(Individual.class);
      				ExtendedIterator<OntClass> it = in.listOntClasses(true);
      
      				String className = "";
      				while(it.hasNext()){
      					className = it.next().toString();
      				}
      				result.add(className);	
      			}
      
      			qe.close();
      	}
      
      	public static void main(final String[] args)
      	{
      		final SPARQLDLBug app = new SPARQLDLBug();
      		app.run();
      	}
      }
      

      The error message is:

      Exception in thread "main" org.apache.jena.ontology.ConversionException: Cannot convert node http://www8.cs.fau.de/research:cgm/schizophrenia#R_AcuteSchizophrenia to Individual
              at org.apache.jena.ontology.impl.IndividualImpl$1.wrap(IndividualImpl.java:61)
              at org.apache.jena.enhanced.EnhNode.convertTo(EnhNode.java:152)
              at org.apache.jena.enhanced.EnhNode.convertTo(EnhNode.java:31)
              at org.apache.jena.enhanced.Polymorphic.asInternal(Polymorphic.java:62)
              at org.apache.jena.enhanced.EnhNode.as(EnhNode.java:107)
              at bug.SPARQLDLBug.run(SPARQLDLBug.java:58)
              at bug.SPARQLDLBug.main(SPARQLDLBug.java:75)
      
      

      This Query is:

       PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       PREFIX owl: <http://www.w3.org/2002/07/owl#>
       PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
       PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
       PREFIX bio: <http://www8.cs.fau.de/research:cgm/schizophrenia#>
       SELECT ?x
       WHERE { ?x rdf:type bio:AcuteSchizophrenia }
      

      And the Ontology consist only of a class and one individual.

      <?xml version="1.0"?>
      <rdf:RDF xmlns="http://www8.cs.fau.de/research:cgm/schizophrenia#"
           xml:base="http://www8.cs.fau.de/research:cgm/schizophrenia"
           xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
           xmlns:owl="http://www.w3.org/2002/07/owl#"
           xmlns:xml="http://www.w3.org/XML/1998/namespace"
           xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
           xmlns:swrl="http://www.w3.org/2003/11/swrl#"
           xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
           xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
           xmlns:dc="http://purl.org/dc/elements/1.1/">
          <owl:Ontology rdf:about="http://www8.cs.fau.de/research:cgm/schizophrenia">
          </owl:Ontology>
      
          <!-- http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral -->
      
          <rdfs:Datatype rdf:about="http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral"/>
      
          <owl:Class rdf:about="http://www8.cs.fau.de/research:cgm/schizophrenia#AcuteSchizophrenia">
              <rdfs:label xml:lang="en">Acute schizophrenia</rdfs:label>
          </owl:Class>
      
      
              <owl:NamedIndividual rdf:about="http://www8.cs.fau.de/research:cgm/schizophrenia#R_AcuteSchizophrenia">
              <rdf:type rdf:resource="http://www8.cs.fau.de/research:cgm/schizophrenia#AcuteSchizophrenia"/>
          </owl:NamedIndividual>
      
      </rdf:RDF>
      
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              greenbourne Christian Bay
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: