On 18/02/12 11:48, Andy Seaborne wrote:
On 18/02/12 08:48, Holger Knublauch wrote:
On Feb 18, 2012, at 12:35 AM, Andy Seaborne wrote:
Another suggestion: put a marker pattern into the query and then
you can find it again.
Put in the triple <tq:holger> <tq:holger> <tq:holger> .
Thanks, Andy, for looking into this. Unfortunately those queries are
not written by myself, and they might be anything. So I cannot rely
on a marker triple. It's basically a feature of the SPIN framework in
which rules and constraints can be attached to classes. The variable
?this is then supposed to be (pre) bound to all instances of those
classes. My current solution was to insert this clause that iterates
over all instances where ?SOME_TYPE is pre-bound to the class using
initial bindings. This works fine in most cases, but if some query
only uses a function call (and BIND) then the ?this variable may not
already be bound and the function call fails.
Why not prebind it?
PS There is also BINDINGS in SPARQL 1.1
WHERE {
{
BIND (ex:fun(?this) AS ?result) .
}
FILTER (?result != 1)
}
BINDINGS ?this { (<foo>) }
static public void main(String ... args)
{
Model m = ModelFactory.createDefaultModel() ;
Query q = QueryFactory.create("SELECT * { BIND(?x+1 AS ?y) }") ;
QuerySolutionMap map = new QuerySolutionMap() ;
map.add("x", m.createTypedLiteral(1)) ;
QueryExecution qexec = QueryExecutionFactory.create(q, m, map) ;
ResultSetFormatter.out(qexec.execSelect());
}
Is there perhaps a way to control the table unit (if that's always
there), so that this could instead be a BGP?
Yes - write a algebra transform to replace (table unit) with what you want.
Subclass TransformCopy and override
public Op transform(OpTable opTable)
Maybe I could
pre-process the ops but I don't understand the algebra mechanism well
enough on a reliable pattern on what replacement I would need to do.
A syntactic insertion based on { sounds brittle, esp since there are
things like GRAPH etc that switch to a completely different query
graph.
Maybe I need to really do the iteration "outside" for certain rules
and constraints if there is no simple place for a ?this binding BGP.
This will be slower but at least correct. Do you have any other
ideas?
I think I understand you description but the details (of SPIN setup)
matter here so maybe it would be better to discuss real code. Do you
have a complete example?
Thanks a lot Holger
Andy