List difference - nope

29 views
Skip to first unread message

Jack Hodges

unread,
Apr 6, 2017, 7:46:29 PM4/6/17
to TopBraid Suite Users
I have 2 problems that I think might be related.

First, if I write a SPIN function countEnumItems to count the number of items in an enumeration:

SELECT COUNT(?known_dim)

WHERE {

    ?known_dim a ?dtype .

}


where ?dtype is an argument to the function, and I call this in a SPARQL window, it works fine (answer for the test enumeration was 8). If I call like this:


SELECT ?cnt

WHERE {

    BIND (fonm:DimensionType AS ?dtype) .

    BIND (behaviorspin:countEnumItems(?dtype) AS ?cnt) .

}


I get some bizarrely huge number., like 20000. There are no hidden subclasses on this type so the answer really is 8, so the variable ?dtype is not getting bound. Why is that?


The second problem is that I have 2 'lists': a number of dimensions defined as instances of an enumeration (there are 8, as described above), and a number of dimensions associated with a specific instance of connection (in my example, 4). I want to see which dimensions in the full list are NOT members of the connection 'list'. I wrote some magic properties to get me the 2 lists from instances, and then ran into a wall that there was no way to do a simple list difference.

My next attempt was to write a function, dimMemberOf which takes two arguments: a dimension, and a 'list' of dimensions, and checks the given dimension against the 'list' of connection dimensions. Of course, there was no such list of connection dimensions and dimMemberOf was individually comparing the target dimension against each of the connection dimensions. But this was ok because I thought I could then count the number of trues and falses for these comparisons. So I wrote some counting functions and tested them, but when I called the counting functions as SPIN functions instead of getting a count of the number of falses (3) I got a count of 1 three times.

So I thought that since the SPIN function has an embedded magic property in it perhaps that required that the SPIN function be converted to a magic property as well. So I did that, but then I got an error that I cannot count items in a magic property.

So I thought that I'd remove the COUNT and wrap the whole thing into another SPIN function, but my SPIN function has 2 arguments and I cannot use 2 arguments in a magic property (or can I?)

Long and short of this question is that doing something that would have cost me about 5 minutes in Java or some other language is taking a long time in SPARQL.

Here is some sample code that works fine:

SELECT COUNT(?result)

WHERE {

    BIND (emech:SandTable_DW01Axle_M01Axle_FixedConnection-Restrain AS ?arg1) .

    BIND (fonm:AlongLength AS ?dim) .

    ?arg1 behaviorswa:allRestrainRestrainedDimensions ?restDims .

    BIND (behaviorspin:dimMemberOf(?dim, ?restDims) AS ?result) .

    FILTER (?result = false) .}


The resulting value is 3. Here is the function call that doesn't work:


SELECT ?cnt

WHERE {

    BIND (emech:SandTable_DW01Axle_M01Axle_FixedConnection-Restrain AS ?arg1) .

    BIND (fonm:AlongLength AS ?dim) .

    ?arg1 behaviorswa:allRestrainRestrainedDimensions ?restDims .

    BIND (behaviorspin:countMatchingDimInRestDims(?dim, ?restDims) AS ?cnt) .

}


In this case I get 3 results (each with the value 1). The content of the SPIN function is just the 2 lines in the first example, and a COUNT(?result).


I do not understand either of these situations, and suspect that the root is a basic misunderstanding of how SPIN is working. Any clarification would be appreciated.


Jack

Irene Polikoff

unread,
Apr 6, 2017, 10:11:39 PM4/6/17
to topbrai...@googlegroups.com
Jack,

For your first question, this is what worked for me


-- 
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to topbrai...@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-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jack Hodges

unread,
Apr 8, 2017, 12:14:54 PM4/8/17
to TopBraid Suite Users
Thanks Irene. That is exactly what mine looks like, and it is indeed very simple, and it returns nothing. But I figured this problem out. The super class of the test had no instances but the subclasses did. If I ran the function on the subclasses it worked fine, so I change the wrapper to do ?cls refs:subClassOf* ?arg1 . and then ran the counter on that, and then added a FILTER (?cls = ?arg1) . then I get the right result.

Here is the modified wrapper:

SELECT *

WHERE {

    BIND (fonm:DimensionType AS ?arg1) .

    ?cls rdfs:subClassOf* ?arg1 .

    BIND (behaviorspin:countEnumItems(?cls) AS ?cnt) .

    FILTER (?cls = fonm:DimensionType) .

}


Thanks again. Now back to my list differences problem...


Jack

Holger Knublauch

unread,
Apr 9, 2017, 6:47:49 PM4/9/17
to topbrai...@googlegroups.com
Hi Jack,
Magic properties *can* take multiple arguments (left hand side) and also return multiple results (right hand side). The arguments must be called sp:arg1, sh:arg2 etc.



Long and short of this question is that doing something that would have cost me about 5 minutes in Java or some other language is taking a long time in SPARQL.

FWIW 5.3 has greatly improved JavaScript support in case that is an option to formulate your query logic.



Here is some sample code that works fine:

SELECT COUNT(?result)
WHERE {
    BIND (emech:SandTable_DW01Axle_M01Axle_FixedConnection-Restrain AS ?arg1) .
    BIND (fonm:AlongLength AS ?dim) .
    ?arg1 behaviorswa:allRestrainRestrainedDimensions ?restDims .
    BIND (behaviorspin:dimMemberOf(?dim, ?restDims) AS ?result) .
    FILTER (?result = false) .}

The resulting value is 3. Here is the function call that doesn't work:

SELECT ?cnt
WHERE {
    BIND (emech:SandTable_DW01Axle_M01Axle_FixedConnection-Restrain AS ?arg1) .
    BIND (fonm:AlongLength AS ?dim) .
    ?arg1 behaviorswa:allRestrainRestrainedDimensions ?restDims .
    BIND (behaviorspin:countMatchingDimInRestDims(?dim, ?restDims) AS ?cnt) .
}

It's a bit tricky for me to understand without more knowledge of the data. But if the lower query returns multiple results then it means that the magic property must return multiple results and it is looping over these results (3 times?).

Holger

Jack Hodges

unread,
Apr 15, 2017, 12:36:52 PM4/15/17
to TopBraid Suite Users
Holger,

I had tried multiple arguments on the LHS before posting my original question, but TBC didn't like it and didn't provide much guidance. It looked like it was expecting (as expected) a triple and got something else. To explain further. If I gave this property two arguments like: ?arg1 = Fish, and ?arg2 = Goat Dog Snake Porpoise Fish Cat, and I called it as follows: ?arg1 ?arg2 prefix:itemMemberOf ?result I would expect a result of true. I do not get any complaints when I define the magic property with multiple LHS arguments so it must be the way that I invoke it to test that is incorrect. I looked at the magic property documentation and found no examples of invoking the magic property with multiple arguments or results. I don't suppose you have one, or a link to some examples...

Jack

Jack Hodges

unread,
Apr 15, 2017, 12:43:25 PM4/15/17
to TopBraid Suite Users
Hello Holger,

Inside the TBC documentation I found some syntax examples, such as:

(?list ?subList ?element ?rest) tops:constructRDFList (?s ?p ?o) .

and

(?cls ?property) tops:localRanges ?range

I'll try to test these out and see how they work. Maybe I can apply them to my problem. So far it hasn't worked.

Jack

On Thursday, April 6, 2017 at 4:46:29 PM UTC-7, Jack Hodges wrote:

Jack Hodges

unread,
Apr 15, 2017, 1:34:50 PM4/15/17
to TopBraid Suite Users
OK, i've got them working with multiple arguments. Thanks Holger and Irene!

Jack
Reply all
Reply to author
Forward
0 new messages