?this variable binding loses context within SPARQL "{...}" braces.

46 views
Skip to first unread message

Ahmed Shafei

unread,
May 24, 2016, 8:41:01 PM5/24/16
to TopBraid Suite Users
Hi,

I have the following SPIN template attached to spin:rule property of a class (Task):
INSERT {
    ?this taa:hasActivityChain ?activityChain .
    ?activityChain taa:belongsTo ?this .
    ?activityChain rdfs:label ?activityChainLabel .
    ?activityChain a taa:ActivityChain .
}
WHERE {
    {
        FILTER NOT EXISTS {
            ?this taa:hasActivityChain ?any .
        } .
    } .
    ?this taa:assembles ?furnitureType .
    BIND (afn:localname(?this) AS ?taskLocalName) .
    BIND (afn:localname(taa:ActivityChain) AS ?activityChainLocalName) .
    BIND (smf:buildURI("taa:{?taskLocalName}{?activityChainLocalName}") AS ?activityChain) .
    BIND (spif:generateLabel(?activityChain) AS ?activityChainLabel) .
}

As written, the FILTER checks if the Task class instance already has an ActivityChain or not before creating new triples and inserting them. I have the {...} around the FILTER to ensure its execution at the beginning of the query.

Now, if I run the reasoner while having 1 task (ex. Task_1), the ActivityChain for that task is generated and everything is fine. If I add a new instance (ex. Task_2) and run the reasoner again, nothing gets generated for that new instance. When I remove the {...} around the FILTER, the rule works fine for every new instance. It seems somehow that the ?this variable gets unbounded in the context of using SPARQL {...} braces, any explanation of that behavior?

Thanks in advance.

Holger Knublauch

unread,
May 24, 2016, 9:41:32 PM5/24/16
to topbrai...@googlegroups.com
Hi Ahmed,

I cannot explain this. Nested FILTERs in a { ... } should not have another scope for variables. You could try to debug this further, e.g. by inserting an BIND (smf:trace("?this = {?this}") AS ?dummy) in the FILTER.

HTH
Holger
--
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 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.

Ahmed Shafei

unread,
May 25, 2016, 12:49:58 AM5/25/16
to TopBraid Suite Users
Hi Holger,

Thanks for your reply. I ran the following on one instance of the Task class called Task_1:
  • When I place the BIND inside of the FILTER, the debug message is empty. I get the following error printed multiple times in the error log:
!MESSAGE May 24, 2016 9:36:43 PM org.topbraid.spin.functions.internal.string.insert.StringInsertions apply
INFO: String insertions with unknown variable: this
Initial input: ?this = {?this}
  • If I place the BIND outside the {...} that includes the FILTER (i.e. before the "this taa:assembles ?furnitureType ." triple), I get "Task_1" printed once. Which means that definitely ?this is bounded in the WHERE clause except of inside the FILTER {...} braces.
  • If I remove the {...} around the FILTER, and still place the BIND inside of the filter like that:
INSERT {
    ?this taa:hasActivityChain ?activityChain .
    ?activityChain taa:belongsTo ?this .
    ?activityChain rdfs:label ?activityChainLabel .
    ?activityChain a taa:ActivityChain .
}
WHERE {
    FILTER NOT EXISTS {
        BIND (smf:trace("?this = {?this}") AS ?dummy) .
        ?this taa:hasActivityChain ?any .
    } .
    ?this taa:assembles ?furnitureType .
    BIND (afn:localname(?this) AS ?taskLocalName) .
    BIND (afn:localname(taa:ActivityChain) AS ?activityChainLocalName) .
    BIND (smf:buildURI("taa:{?taskLocalName}{?activityChainLocalName}") AS ?activityChain) .
    BIND (spif:generateLabel(?activityChain) AS ?activityChainLabel) .
}

I get Task_1 printed 4 times which equals the total number of TopSPIN iterations.

So, the later example is what I need. But, sometimes there are time consuming bindings (ex. calling a JavaScript function) depending on the FILTER value, and that's why I always want the FILTER to be evaluated first by adding the {...} braces.

Any hints about that?

Thanks a lot.

What could be a reason for that?

Holger Knublauch

unread,
May 25, 2016, 9:30:09 PM5/25/16
to topbrai...@googlegroups.com
Hi Ahmed,

I noticed some difference between INSERT and SELECT queries here. Could you change your rule to CONSTRUCT? This may help you work around the issue, until we had time to investigate this deeper.

Holger
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.

Holger Knublauch

unread,
May 25, 2016, 9:38:51 PM5/25/16
to topbrai...@googlegroups.com
I tried again, but this time no longer see a difference between INSERT and SELECT - probably a test error. So I am at a loss what may be causing this behavior for you. What version are you on?

Holger

Ahmed Shafei

unread,
Jun 4, 2016, 2:08:04 AM6/4/16
to TopBraid Suite Users
Hi Holger,

I am running version 5.1.0.
Reply all
Reply to author
Forward
0 new messages