Would it work for you to just do a single iteration? You can control
this in the inference configuration.
If yes then you can introduce a property my:prepRule rdfs:subPropertyOf
spin:rule, and then state
my:prepRule spin:nextRuleProperty spin:rule
Make your rule a my:prepRule then. This will execute these rules before
the other spin:rules.
See http://spinrdf.org/spin.html#spin-rules-order
HTH
Holger
On 4/12/2012 15:25, Mark Colquhoun wrote:
Following on from my previous reply, I am now seeing problems with the
use of this function in a rule defined as:
CONSTRUCT {
?this rdfs:label ?label .
}
WHERE {
BIND (:getLabel(?this) AS ?label) .
}
The behaviour I am seeing is that I am getting two labels generated.
The reason for this is that the prod:hasParent predicate in the
function is an inverse property and is inferred by running the RDFS
Plus rule set. Therefore, in the first iteration of the inference
engine, a label is created for all the things the rule is associate
with with the value of prod:shortName. In a subsequent iteration (once
hasParent has been inferred), another label with the correct value is
inferred.
I have had a look to see if there is a way I can control the execution
order of the rules but none of the available options seem to be a
solution to my problem. I am using TBC Standard so I don't have access
to SPARQLMotion so that isn't an option either. The solution in my
mind is quite simple but I can think of a way to implement it. Any
help would be greatly appreciated.
Regards,
Mark.
On Apr 3, 10:00 am, Mark Colquhoun<[email protected]>
wrote:
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