Hi K.J.,
the iteration in your second example would not work because CONSTRUCTs
can only ever add new triples, never overwrite previous iterations.
In general SPARQL you could use a nested SELECT and the SUM aggregator:
CONSTRUCT {
?A ns:HasFinalScore ?FS .
}
WHERE {
SELECT (SUM(?IS) AS ?FS)
WHERE {
?this ns:KRIPredictsRiskFactor ?A .
?this ns:InstanceHasInstanceScore ?IS .
}
}
However this is not working as a SPIN rule, because the binding of ?this
will not be passed into the nested WHERE, and you would get a "wildcard"
matching for ?this instead. So SPIN's trick to pre-bind ?this cannot be
used here, and you need to push the iteration logic into the nested
WHERE clause. Try the following spin:rule:
CONSTRUCT {
?A ns:HasFinalScore ?FS .
}
WHERE {
SELECT ?A (SUM(?IS) AS ?FS)
WHERE {
?x ns:KRIPredictsRiskFactor ?A .
?x ns:InstanceHasInstanceScore ?IS .
}
}
(As an advanced solution, if you want to use ?this, you could factor the
nested sub-select into a SPIN function that takes the value of ?this as
its argument. This is the mechanism that I am typically using for such
nested selects).
HTH
Holger
On 9/20/2014 22:39, K. J. Toad wrote:
Hello everyone
I am a beginner with SPARQL and SPIN and am currently trying to build
my first ontology. I was able to figure out all problems with the help
of online research, but don't know how to fix my current one:
I want to iterate through various sub-concepts with 1 to 6 instances
each. While iterating I want to add up the instance values and bind
them to (another concept's) instance's final value. The following code
specifying a sub-concept with 3 instances works smoothly.
*CONSTRUCT*{
?A ns:HasFinalScore ?FS .
}
*WHERE*{
ns:1 ns:InstancePredicts ?A ;
ns:InstanceHasInstanceScore ?IS1 .
ns:2 ns:InstancePredictsRiskFactor ?A ;
ns:InstanceHasInstanceScore ?IS2 .
ns:3 ns:InstancePredictsRiskFactor ?A ;
ns:InstanceHasInstanceScore ?IS3 .
*BIND* (((?IS1 + ?IS2) + ?IS3) *AS* ?FS) .
}
When I try to run a template on the cub-concept that has those three
instances (as indicated with the following code), it won't work anymore.
*CONSTRUCT*{
?A ns:HasFinalScore ?FS .
}
*WHERE*{
*?this* ns:KRIPredictsRiskFactor ?A .
*?this* ns:InstanceHasInstanceScore ?IS .
?A ns:HasFinalScore ?FSold .
*BIND* ((?FSold + ?IS) *AS* ?FS) .
}
Can you guys please help me figure out what the problem is?
--
-- 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
Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
topbraid-users@googlegroups.com
To unsubscribe from this group, send email to
topbraid-users+unsubscr...@googlegroups.com
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 topbraid-users+unsubscr...@googlegroups.com
<mailto:topbraid-users+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.
--
-- 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 Insight, SPARQLMotion, SPARQL
Web Pages and SPIN.
To post to this group, send email to
topbraid-users@googlegroups.com
To unsubscribe from this group, send email to
topbraid-users+unsubscr...@googlegroups.com
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 topbraid-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.