On 3/7/2014 1:55, Nikolaos Beredimas wrote:
So I've been playing around with TBC trial (v 4.1) to find out more about SPIN.

My problem came about when trying to create a constraint to validate that a given property's object is an xsd:string exactly 11 characters long

So I wrote this constraint:

# aString Length must be 11
ASK WHERE {
    ?this :aStringValue ?val1 .
    BIND (fn:string-length(?val1) AS ?aStringLength) .
    FILTER (?aStringLength != 11) .
}

Weird, this should work. In general through if you are experiencing unexpected behavior with ordering of BIND and FILTER, keep in mind that the SPARQL engine may execute things in a different order than you assume. The SPARQL Debugger can shed some insights into what's happening under the hood. To force the query order above (BIND before FILTER, wrap the stuff that shall be executed "first" with a { ... } block such as in

ASK WHERE {
    {
        ?this :aStringValue ?val1 .
        BIND (fn:string-length(?val1) AS ?aStringLength) .
    }
    FILTER (?aStringLength != 11) .
}


PS. Any way to define a kind of priority for evaluation of different constraints??? Say for example I have one constraint that checks string length, and one that validates a string's checksum. How should I implement if I only want to attempt to validate the checksum only if the string length is valid?

The only way to bypass a constraint check is to duplicate the logic of the the previous constraint, e.g. turn the constraint above into a SPIN function that returns true or false, called ex:isStringLengthNot11. Then put a "guard clause" into the beginning of your other constraint, e.g.

ASK WHERE {
    {
        FILTER !ex:isStringLengthNot11(?this) .
    }
... do the real tests - will only be executed if the first constraint was not checked
}

The role of the SPIN function is to encapsulate the logic so that you don't need to write it over and over again.

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), TopBraid Composer, TopBraid Live, TopBraid Insight, 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.

Reply via email to