Re: getting the query from an SXP expression

Hi Andy,

Andy Seaborne <andy@seaborne.org> writes:
> Jena tries to - it's quite pragmatic:
>
> https://github.com/apache/jena/blob/main/jena-arq/src/main/java/org/apache/jena/sparql/algebra/OpAsQuery.java
>
>     Andy

When I was reviewing the OpAsQuery implementaion in Jena, and I had a
problem: It works with some S-expressions, but fails with others.  My
testing code includes the following files:

File 1:

package cl.degu.sparql;

import org.apache.jena.query.Query;
import org.apache.jena.sparql.algebra.OpAsQuery;
import org.apache.jena.sparql.algebra.Algebra;

public class SSEtoSPARQL {
    public static Query translate(String sse) {
        return OpAsQuery.asQuery(Algebra.parse(sse));
    }
}

FILE 2:

package cl.degu.sparql;

public class App
{
    public static void main( String[] args )
    {
        String sse;

        // First example
        sse = "(project ?s (bgp (triple ?s ?p ?c)))";
        System.out.println(SSEtoSPARQL.translate(sse));

        // Second example
        sse = "(project ?s (bgp (triple ?s <http://example.org> ?c)))";
        System.out.println(SSEtoSPARQL.translate(sse));
    }
}

The first example works, but the second example produces an error. The
output of the main function is the following:

SELECT  ?s
WHERE
  { ?s  ?p  ?c }

Exception in thread "main" java.lang.ExceptionInInitializerError
	at org.apache.jena.sparql.sse.lang.ParseHandlerPlain.emitIRI(ParseHandlerPlain.java:165)
	at org.apache.jena.sparql.sse.lang.ParseHandlerResolver.emitIRI(ParseHandlerResolver.java:150)
	at org.apache.jena.sparql.sse.lang.ParserSSEBase.emitIRI(ParserSSEBase.java:46)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.IRIref(SSE_ParserCore.java:277)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.RDFTerm(SSE_ParserCore.java:230)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.Term(SSE_ParserCore.java:217)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.TermOrList(SSE_ParserCore.java:62)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.BareList(SSE_ParserCore.java:194)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.List(SSE_ParserCore.java:108)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.TermOrList(SSE_ParserCore.java:80)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.BareList(SSE_ParserCore.java:194)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.List(SSE_ParserCore.java:108)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.TermOrList(SSE_ParserCore.java:80)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.BareList(SSE_ParserCore.java:194)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.List(SSE_ParserCore.java:108)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.TermOrList(SSE_ParserCore.java:80)
	at org.apache.jena.sparql.sse.lang.parser.SSE_ParserCore.parse(SSE_ParserCore.java:34)
	at org.apache.jena.sparql.sse.lang.SSE_Parser.parse$(SSE_Parser.java:47)
	at org.apache.jena.sparql.sse.lang.SSE_Parser.parse(SSE_Parser.java:40)
	at org.apache.jena.sparql.sse.SSE.parse(SSE.java:452)
	at org.apache.jena.sparql.sse.SSE.parse(SSE.java:373)
	at org.apache.jena.sparql.sse.SSE.parse(SSE.java:368)
	at org.apache.jena.sparql.algebra.Algebra.parse(Algebra.java:107)
	at cl.degu.sparql.SSEtoSPARQL.translate(SSEtoSPARQL.java:9)
	at cl.degu.sparql.App.main(App.java:16)
Caused by: java.lang.NullPointerException
	at org.apache.jena.query.ARQ.isTrueOrUndef(ARQ.java:654)
	at org.apache.jena.riot.system.RiotLib.<clinit>(RiotLib.java:59)
	... 25 more

I included Jena into the project with the following dependency:

    <dependency>
      <groupId>org.apache.jena</groupId>
      <artifactId>apache-jena-libs</artifactId>
      <version>4.2.0</version>
      <type>pom</type>
    </dependency>


Daniel

Received on Sunday, 5 December 2021 19:39:52 UTC