1

The problem I got is com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_LN> "rdfs:domain. Here is what I did. I use OWL API to read xml/owl document and use Pellet to reason. As I want to do some SPARQL queries in addition to reason, I use Jena 2.10.0 to work with Pellet 2.3.0. I can not change the version of Jena because of the compatibility. Here is the code:

package loadOnto;
import java.io.File;

import org.mindswap.pellet.KnowledgeBase;
import org.mindswap.pellet.jena.PelletInfGraph;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class load {
public static void main(String[] args) throws OWLOntologyCreationException {
    // Get hold of an ontology manager
            OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

            // We can also load ontologies from files. Create a file object that points to the local copy
            File file = new File("G:/Protege/owlfiles/Before_Gather.owl");

            // Load the local copy
            OWLOntology loadMODIS = manager.loadOntologyFromOntologyDocument(file);

            PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner( loadMODIS );

            //System.out.println("CheckParsing.should() " + reasoner.isConsistent());

            KnowledgeBase kb = reasoner.getKB();
            PelletInfGraph graph = new org.mindswap.pellet.jena.PelletReasoner().bind( kb );
            InfModel model = ModelFactory.createInfModel( graph );

            String PREFIX = "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 seaice: <http://www.semanticweb.org/SeaIceOntology#>" +
                    "PREFIX repr: <http://sweet.jpl.nasa.gov/2.3/reprDataFormat.owl#>" +
                    "PREFIX realmCryo: <http://sweet.jpl.nasa.gov/2.3/realmCryo.owl#>" +
                    "PREFIX relaMath: <http://sweet.jpl.nasa.gov/2.3/relaMath.owl#>";
            String SELECT = "select ?domain ";
            String WHERE = "where {" +
                    "?dataset seaice:hasSpatialResolution" + "\"4.0\"^^xsd:float." +
                    "?dataset seaice:hasDataFormat repr:GeoTIFF."+
                    "?dataset seaice:recordedDuring seaice:Day."+
                    "seaice:describe rdfs:domain ?domain."+
                    //"seaice:describe rdfs:range realmCryo:SeaIce."+
                    //"?dataset rdf:type ?domain." +
                    "}" ;

            Query queryStr = QueryFactory.create(PREFIX + SELECT + WHERE);
            QueryExecution qe = QueryExecutionFactory.create(queryStr, model);
            ResultSet rs = qe.execSelect();

            ResultSetFormatter.out(System.out,rs);
            rs = null;  qe.close();
            reasoner.dispose();

            //System.out.println("Loaded ontology: " + loadMODIS);
    }
}

The code works well with first 3 queries, but after adding "seaice:describe rdfs:domain ?domain.", the problem immediately occurred. The code also works well with "seaice:describe rdfs:domain ?domain." alone. The Error is as follow:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_LN> "rdfs:domain "" at line 1, column 582.
Was expecting one of:
"values" ...
"graph" ...
"optional" ...
"minus" ...
"bind" ...
"service" ...
"filter" ...
"{" ...
"}" ...
";" ...
"," ...
"." ...

at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53)
at com.hp.hpl.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:37)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:156)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:79)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:52)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at loadOnto.load.main(load.java:65)
Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • 1
    Can you please print the query string and post it as separate query here again? Reading some concatenated Java strings is weird. Btw, isn't there a missing space in the first triple pattern before the literal? – UninformedUser Jan 26 '16 at 12:21
  • 1
    You know, the string concatenation is giving you one big line. If you add newlines, you will avoid common potential problems like `"select ?a"+"where"`, but even more useful in this case, you'll get a **line number** in your error message. I would not try debugging this until you've done that first. – Joshua Taylor Jan 26 '16 at 13:27
  • What do you mean by line number? Did you mean the "102, 53,37", etc?@Joshua Taylor – Julyana Lin Jan 28 '16 at 06:55
  • @user We're not going to try reading code in comments. Please post it as an update to you question (use the **edit** link under your question). – Joshua Taylor Jan 28 '16 at 13:35
  • By line number, I mean that if you put newlines in your query, e.g., `"prefix : <...> \n" + "select ?x where { \n" + " ...`, (see the `\n` newlines), then Jena will complain with messages like "Error on line n`, and you'd be able to figure out exactly what line the problem is on, which would make it much easier to see that the problem was on a "line" containing something like `seaice:Day.seaice:describe`. – Joshua Taylor Jan 28 '16 at 13:36
  • Thank you for your suggestion. It is "new line" problem that caused this error. Now it is solved! Thank you so much :) – Julyana Lin Feb 01 '16 at 10:54

1 Answers1

4

The one long line has introduced a bug. Your query has a single term: "seaice:Day.seaice:describe" in it. DOT (.) is legal inside prefix local-names, so adding letters after the DOT puts it inside the local part.

  1. Always use newlines in the query string.
  2. Write space-dot at the end of triple patterns :  . not .
TallTed
  • 9,069
  • 2
  • 22
  • 37
AndyS
  • 16,345
  • 17
  • 21