Hi Holger,
Thanks for the fast reply. Your example helped immensely. I've posted
the working solution below for posterity.
SELECT ?result
WHERE {
?arg1 prod:shortName ?name .
OPTIONAL {
?arg1 prod:hasParent ?parent .
} .
BIND (IF(bound(?parent), fn:concat(prod-instance:getLabel(?
parent), " - ", ?name), ?name) AS ?result) .
}
Regards,
Mark.
On Apr 3, 8:42 am, Holger Knublauch <[email protected]> wrote:
> Hi Mark,
>
> recursion in SPIN is no problem, assuming you put a guard clause (e.g.
> IF) around the recursive call to make sure it terminates. The following
> function :recurse starts at a given class (?arg1) and walks its
> superclasses hierarchy, concatenating all rdfs:labels.
>
> SELECT ?result
> WHERE {
> ?arg1 rdfs:label ?label .
> OPTIONAL {
> ?arg1 rdfs:subClassOf ?superClass .
> } .
> BIND (IF(bound(?superClass), fn:concat(?label, "-",
> :recurse(?superClass)), "") AS ?result) .
>
> }
>
> Note that this may run into infinite loops if you have cyclic class
> dependencies, and also assumes that each class has at most one superclass.
>
> Hope this makes sense
> Holger
>
> On 4/2/2012 22:44, Mark Colquhoun wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I have requirement where I need to create a string that is based on
> > the recursive parent relationship in a hierarchy. After looking
> > around, I was hopeful that I would be able to create a recursive SPIN
> > function to achieve this but although the function appears to be
> > called recursively, I am not able to bind to the results of the
> > recursive calls to produce a concatenated string. I think part of the
> > problem might be that the last function call returns a empty result
> > set but I'm not 100% sure.
>
> > The SPIN function I am using is as follows:
>
> > SELECT ?name
> > WHERE {
> > ?arg1 prod:hasParent ?parent .
> > ?arg1 prod:name ?name .
> > BIND (prod-instance:getLabel(?parent) AS ?temp) .
> > }
>
> > which returns "Pumps" (see what is essentially the call stack in the
> > SPIN statistics below).
>
> > Note that I know that this won't return a concatenated string but I
> > would just be happy to see the function return a binding for ?temp so
> > I can move forward. Not that in the statistics below, prod-instance:OE
> > does not have a statement for hasParent. (i.e. it is the root of the
> > hierarchy)
>
> > The results I am seeing using SPIN statistics are:
>
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:OE) : Empty result set for SPIN function ...
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:CSG) = "CSG"^^xsd:string
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:TALINGA) = "Talinga"^^xsd:string
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:4120-TGWT1) = "Water Treatment"^^xsd:string1
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:4120-Utilities) = "Utilities"^^xsd:string
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:4120-Hot-Warm-Water) = "Hot& Warm Water"^^xsd:string
> > prod-instance:getLabel SPIN Function prod-instance:getLabel(prod-
> > instance:4120-HW-PUMPS) = "Pumps"^^xsd:string
>
> > Anyone that has some experience solving this sort of problem or any
> > thoughts would be greatly appreciated.
>
> > Thanks,
> > Mark.
--
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 Ensemble, SPARQLMotion 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