Run SPARQL/SPIN templates using TopBraid SPIN API

391 Views Asked by At

I'm trying to run templates using the SPIN API. For simple templates, this works well but I have trouble with templates that include FILTERs.

For verification purposes, I print the templates' bodies before running them and what I see is not what I expect to see:

Template t = SPINModuleRegistry.get().getTemplate("TheTemplatesURI", myModel);
System.out.printLn(t.getBody().toString());

It prints the query but the FILTER clause, which contains 4 lines, looks like this:

FILTER <http://spinrdf.org/sp#notExists>([]) .

Because of this, the query fails when I try to run it.

Does anyone have an idea how I can retrieve the full spin:body from my model?

1

There are 1 best solutions below

0
On

I now use a workaround.

The problem is that SPIN API only reads the FILTER queries properly (i.e. complete) if I put them as

NOT EXISTS {
    ?s ?p ?o .
    ...
}

instead of

FILTER NOT EXISTS {
    ?s ?p ?o .
    ...
}

If I manually run the templates that way, SPARQL will throw an exception because the proper way is to have FILTER. I now saved all my templates as NOT EXISTS in Topbraid Composer and add the FILTER bit via String.replace(...) after loading them via SPIN API. It may be ugly but at least it works.