I was testing a simple conditional in SPARQL and it wasn't working. So I 
went to the documentation and wrote the test conditional and it worked, but 
do not understand why mine isn't working. The test conditional compares 2 
integers and displays 2 strings. I augmented that test to have another 
nested IF and it still works.

My query is based on a BIND of 2 expressions to strings. Here is what it 
looks like:

SELECT ?res
WHERE {
    BIND ("foo" AS ?f) .
    BIND ("bar" AS ?b) .
    BIND ((IF(?f, ?f, IF(?b, ?b, "NA"))) AS ?res) .
}

This returns "foo". If I remove the first BIND statement there is no 
result. I tried changing this test to:

SELECT ?res
WHERE {
    BIND ("foo" AS ?f) .
    BIND ("bar" AS ?b) .
    BIND ((IF(fn:string-length(?f) > 0, ?f, IF(fn:string-length(?b) > 0, 
?b, "NA"))) AS ?res) .
}

and it returns "foo". If I change the first size to 3, then it returns 
"bar". If I change the second size to 3 it returns "NA".

But in 'my' query this doesn't work. Here is the query:

SELECT DISTINCT *
WHERE {
    BIND 
(act:commonSubclassLabel("http://developer.runkeeper.com/healthgraph#Spinning";) 
AS ?res1) .
    BIND 
(act:commonSuperclassLabel("http://developer.runkeeper.com/healthgraph#Spinning";)
 
AS ?res2) .
    BIND ((IF(fn:string-length(?res2) > 0, 
?res2,  IF(fn:string-length(?res1) > 0, ?res1, "NA"))) AS ?res) .
}

The function calls to 'commonSubclassLabel' and 'commonSuperclassLabel" 
work fine on their own (both return strings), and the result returned is 
?res2 if its length exceeds 0. If not, there is a value for ?res1 but it 
doesn't ever get bound to ?res. If I swap ?res2 and ?res1 in the last BIND 
the same query works for ?res1 but not ?res2, so there is something in my 
IF statements 'THEN' block that doesn't work. If I replace the THEN block 
with just ?res1 (or ?res2 as the case may be), nothing changes in the 
result.

As you can see, I have worked myself into a lather over this by making it 
more complex than it should have to be, but as is normal in such cases when 
the simple logic didn't work I began more and more convoluted things.

Any pointers would be greatly appreciated!

These queries are being executed in TBCME v4.2.

Jack

-- 
You received this message because you are subscribed to the Google Group 
"TopBraid Suite Users", the topics of which include Enterprise Vocabulary 
Network (EVN), Reference Data Manager (RDM), TopBraid Composer, TopBraid Live, 
TopBraid Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbraid-users@googlegroups.com
--- 
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.

Reply via email to