Force Priority on spin rules

33 views
Skip to first unread message

AndrewB

unread,
Feb 19, 2010, 2:46:30 PM2/19/10
to TopBraid Composer Users
I know this goes against how a ontology runs but is there a way to
force priorty on spin rules.


Example(Bad). I have 3 classes ABC A and B have a spin rule to
generate there label

C generates its label out of A's and B's Label.

So when I run i get a version of C's label with A and B having no
label
and version with A and B having a label.


Although both are correct, i really only care about the longer C
label. So either i say run these rules first somehow. Or I filter
out the shorter of 2 labels when their are 2. But then I would
probably hit a infinite loop.


I can do this with sparql motion but I'm trying to avoid it.

I know the inference engine loops over until there are no new triples.

Thanks for any help. you can provide

Scott Henninger

unread,
Feb 19, 2010, 5:37:30 PM2/19/10
to TopBraid Composer Users
Andrew; Rules in SPIN can be ordered by using spin:nextRuleProperty
with groups of rules. The steps to do this are as follows:
1. Create sub-properties of spin:rule (e.g. spin:rs1, spin:rs2)
2. Order spin:nextRuleProperty, e.g. the following would set rule to
run a rs1, rs2, rule:
spin:rs1 spin:nextRuleProperty spin:rs2
spin:rs2 spin:nextRuleProperty spin:rule
3. add rules to the properties as needed

This may do what you need. Are you saying that in the end you want
labels for A, B, and C. Or just C? If it's just C, then you can take
your rules for generating labels for A and B an place them in SPIN
functions. Then just create a rule for C that would look something
like:

CONSTRUCT
{ ?this rdfs:label ?label
}
WHERE
{ LET (?alabel := :getLabelForA())
LET (?blabel := :getLabelForB())
LET (?label := smf:buildString("{?alabel}--{?blabel}"))
}

or, in more compact form:
LET (?label := smf:buildString("{?1}--{?
2}", :getLabelForA(), :getLabelForB()))

<I know the inference engine loops over until there are no new
triples.>

You can set the engine to run a single pass only in Configure
Inferencing.
-- Scott

Tim Darr

unread,
Feb 22, 2010, 8:11:39 AM2/22/10
to topbraid-co...@googlegroups.com
What is the scope of the rule sequencing? Is it the class to which the rule is attached, or is it global?

For example, if I have two unrelated classes A and B, and two rules ruleA (attached to class A) and ruleB (attached to class B) and specify that ruleB is the nextRuleProperty of ruleA, will ruleA always precede ruleB?

I have implemented something like this and it appears that the sequencing is not working as expected ...

--
You received this message because you are subscribed to the Google Groups "TopBraid Composer Users" group.
To post to this group, send email to topbraid-co...@googlegroups.com.
To unsubscribe from this group, send email to topbraid-composer...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/topbraid-composer-users?hl=en.




--
Tim Darr
tdarr...@gmail.com

Scott Henninger

unread,
Feb 22, 2010, 9:28:07 AM2/22/10
to TopBraid Composer Users
Tim; SPIN applies rules to classes and their subclasses. If you need
to run rules defined in different classes in a sequence - one set of
rules after another - then create a SPARQLMotion script with an
ApplyTopSPIN module for each rule set. Specify the set with a sub-
property of spin:rule and use the sml:predicate property in
ApplyTopSPIN to state which rule set to run. E.g. the following would
run the same example rule set across all class definitions:
:ApplyTopSPIN_1 sml:predicate spin:rs1 .
:ApplyTopSPIN_1 sm:next :ApplyTopSPIN_2 .
...
:ApplyTopSPIN_2 sml:predicate spin:rs2 .

Rules would then be defined in spin:rs1 and spin:rs2 for class
definitions.

-- Scott

On Feb 22, 7:11 am, Tim Darr <tdarr.u...@gmail.com> wrote:
> What is the scope of the rule sequencing? Is it the class to which the rule
> is attached, or is it global?
>
> For example, if I have two unrelated classes A and B, and two rules ruleA
> (attached to class A) and ruleB (attached to class B) and specify that ruleB
> is the nextRuleProperty of ruleA, will ruleA always precede ruleB?
>
> I have implemented something like this and it appears that the sequencing is
> not working as expected ...
>

> On Fri, Feb 19, 2010 at 4:37 PM, Scott Henninger <shennin...@topquadrant.com

> > topbraid-composer...@googlegroups.com<topbraid-composer-users%2Bunsu...@googlegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/topbraid-composer-users?hl=en.
>
> --
> Tim Darr

> tdarr.u...@gmail.com

Tim Darr

unread,
Feb 22, 2010, 9:49:07 AM2/22/10
to topbraid-co...@googlegroups.com
Thanks for the confirmation.

To unsubscribe from this group, send email to topbraid-composer...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/topbraid-composer-users?hl=en.




--
Tim Darr
tdarr...@gmail.com

AndrewB

unread,
Feb 22, 2010, 11:02:58 AM2/22/10
to TopBraid Composer Users
Thank you all for the help.

I figured out how to do it but your not going to like it :)

DELETE {
?this :hasPreSQL ?result
}
WHERE {
LET (?query :=fn:concat("SELECT ?finalSQL WHERE{ :",smf:generateLabel(?
this)," :hasFinalSQL ?finalSQL .}")) .
LET (?query2 :=fn:concat("SELECT ?finalsql
WHERE{ :",smf:generateLabel(?this)," :hasFinalSQL ?finalsql LET (?
count :=fn:string-length(?finalsql)) . }ORDER BY ?count LIMIT 1")).
LET (?result := smf:if(smf:countResults(?
query)>=2,:ConCatResultSet("",?query2,""))) .
}

ConCatResultSet is just used to run the query and return "?finalsql"

so if there is only 1 hasFinalSQL, it returns null which removes
nothing, else it removes the shorter of the 2.

The only issue I have now is where to put this to run.

As far as I know if I put in on a class as a spin rule It has to have
a CONSTRUCT, so The only solution I can think of is, wrapping it up as
a sparql motion script. and calling if from a construct.

Any ideas?

AndrewB

unread,
Feb 22, 2010, 11:41:52 AM2/22/10
to TopBraid Composer Users
I ended up going with scotts solution and sparql motion because I
needed a script anyway for something else.

Thanks, that was a learning experience.

Scott Henninger

unread,
Feb 22, 2010, 11:54:25 AM2/22/10
to TopBraid Composer Users
Andrew; SPIN is designed as an inference engine. When rules create
triples they are applied to the inferred graph. Composer will then
display the union of inferred ans asserted (current model) graphs.
Note that the background of inferred triples is in violet to show that
they are not asserted.

INSERT and DELETE are applied directly to the model's asserted graph.
This is a different mechanism than used in inference engines, which
are monotonic - facts cannot be retracted.

A SPARQL MODIFY query can be applied either in the SPARQL view or a
SPARQLMotion script.
-- Scott

AndrewB

unread,
Feb 22, 2010, 12:02:09 PM2/22/10
to TopBraid Composer Users
my spin rules are declared on classes, how do I find them in the
ontology and apply 'rs1' to those in rule set 1?

when I bring up 'spin:rule' class, they do not show up as instances of
that class.

They are all constructs

AndrewB

unread,
Feb 22, 2010, 1:14:40 PM2/22/10
to TopBraid Composer Users
Ahh create sub properties of spin:rule, and then switch the code over
to those. I understand now.

Scott Henninger

unread,
Feb 22, 2010, 1:23:52 PM2/22/10
to topbraid-co...@googlegroups.com
Andrew; spin:rule is a property, so there are no instances.

The rules are defined on classes using the spin:rule property.  Attached is a screen image of the kennedysSPIN example, which is found in TopBraid/Examples.

Note there are three rules defined for the class kennedys:Person.  The grandFather/grandMother use paramrterized template, which I can explain further.

-- Scott
kennedysSPIN rules.PNG

Scott Henninger

unread,
Feb 22, 2010, 1:24:41 PM2/22/10
to TopBraid Composer Users
Not sure what is meant by "switch the code over". See the example I
sent and see if that helps.
-- Scott
Reply all
Reply to author
Forward
0 new messages