You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Christian Bay (JIRA)" <ji...@apache.org> on 2017/11/02 12:09:00 UTC
[jira] [Resolved] (JENA-1415) ConversionException for individuals
[ https://issues.apache.org/jira/browse/JENA-1415?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Christian Bay resolved JENA-1415.
---------------------------------
Resolution: Fixed
> ConversionException for individuals
> -----------------------------------
>
> Key: JENA-1415
> URL: https://issues.apache.org/jira/browse/JENA-1415
> Project: Apache Jena
> Issue Type: Bug
> Components: ARQ, Jena
> Affects Versions: Jena 3.4.0
> Environment: Linux, Maven, Openllet Reasoner
> Reporter: Christian Bay
> Priority: Minor
>
> 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:
> {code:java}
> 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();
> }
> }
> {code}
> The error message is:
> {code}
> 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)
> {code}
> This Query is:
> {code:xml}
> 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 }
> {code}
> And the Ontology consist only of a class and one individual.
> {code:xml}
> <?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>
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)