Hello Heiner,
this option seems to work:
CONSTRUCT {
?this base:_result ?result .
}
WHERE {
{
SELECT ((SUM(?value)) AS ?result) ?this
WHERE {
?this base:has/base:_property ?value .
}
GROUP BY ?this
} .
}
Note the GROUP BY.
But in general, as you state, SPARQL is executed from the inside out and
pre-bound variables may not be visible in sub-selects. I usually avoid
such cases by turning the sub-select into a SPIN function. The query
would then be something like
CONSTRUCT {
?this base:_result ?result .
}
WHERE {
BIND (ex:computeResult(?this) AS ?result) .
}
and the spin:body of ex:computeResult would be
SELECT ((SUM(?value)) AS ?result)
WHERE {
?arg1 base:has/base:_property ?value .
}
HTH
Holger
On 5/24/2013 23:26, Heiner Reinhardt wrote:
Hello,
I am trying to create a spin rule that allows for the aggregation of
values.
Let's think of a simple basis ontology (
a1 has b1 .
a1 has b2 .
a2 has b1 .
b1 _property 5 .
b2 _property 2 .
a1 rdf:type A .
a2 rdf:type B .
I would like to create the triples saying:
a1 _result 7 .
a2 _result 5 .
which then provide the result of (5+2) and (5) (aggregation as a SUM)
I tried to work with two different queries:
Query A
CONSTRUCT {
?this base:_result ?result
}
WHERE {
{
SELECT ( SUM( ?value ) AS ?result )
WHERE { ?this rdf:type base:A . ?this base:has ?b . ?b
base:_property ?value }
}
}
It seems that it does not get executed at all.
Query B
CONSTRUCT {
?this base:_result ?result
}
WHERE {
?this rdf:type base:A
{
SELECT ( SUM( ?value ) AS ?result )
WHERE { ?this rdf:type base:A . ?this base:has ?b . ?b
base:_property ?value }
}
}
This query seems to get executed, but ?result is bound to 12 instead
of 7 or 5. It seems that ?this within the SUB-SELECT is not bound to
the respective instance in the SUB-Query.
The w3c specification for SPARQL-subqueries says that bound variables
should not be forwarded to sub queries in order to allow for parallel
execution of the queries.
What is the specification for SPIN?
How would I aggregate some values with SPIN and create a new triple
with this aggregated value based on a specific "?this" ?
--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise
Vocabulary Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google
Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary
Network (EVN), TopBraid Composer, TopBraid Live,
TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.