This looks like some system wide initialisation isn’t happening correctly in 
your runtime environment.

You can first try adding a JenaSystem.init() call as the first line in your 
main() method

Also, if you are building a fat/uber JAR via your build toolchain please be 
aware that Jena uses ServiceLoader for auto-discovery of system initialisation. 
 Please refer to https://jena.apache.org/documentation/notes/jena-repack.html 
for notes on how to ensure that doing so doesn’t break things like this.

Rob

From: Anna P <[email protected]>
Date: Monday, 11 March 2024 at 13:45
To: [email protected] <[email protected]>
Subject: Problems when querying the SPARQL with Jena
Dear Jena support team,

Currently I just started to work on a SPARQL project using Jena and I could
not get a solution when I query a model.
I imported a turtle file and ran a simple query, and the snippet code is
shown below. However, I got the error.

public class App {
    public static void main(String[] args) {
        try {
            Model model = RDFDataMgr.loadModel('data.ttl', Lang.TURTLE);
            RDFDataMgr.write(System.out, model, Lang.TURTLE);
            String queryString = "SELECT * { ?s ?p ?o }";
            Query query = QueryFactory.create(queryString);
            QueryExecution qe = QueryExecutionFactory.create(query, model);
            ResultSet results = qe.execSelect();
            ResultSetFormatter.out(System.out, results, query);
            qe.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Here is the error message:

org.apache.jena.riot.RiotException: Not registered as a SPARQL result set
output syntax: Lang:SPARQL-Results-JSON
        at
org.apache.jena.sparql.resultset.ResultsWriter.write(ResultsWriter.java:179)
        at
org.apache.jena.sparql.resultset.ResultsWriter.write(ResultsWriter.java:156)
        at
org.apache.jena.sparql.resultset.ResultsWriter.write(ResultsWriter.java:149)
        at
org.apache.jena.sparql.resultset.ResultsWriter$Builder.write(ResultsWriter.java:96)
        at
org.apache.jena.query.ResultSetFormatter.output(ResultSetFormatter.java:308)
        at
org.apache.jena.query.ResultSetFormatter.outputAsJSON(ResultSetFormatter.java:516)
        at de.unistuttgart.ki.esparql.App.main(App.java:46)


Thank you for your time and help!

Best regards,

Pan

Reply via email to