Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Remove rule at runtime
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jake Dempsey  
View profile  
 More options Oct 27, 4:21 pm
From: Jake Dempsey <angelo0...@gmail.com>
Date: Tue, 27 Oct 2009 13:21:36 -0700 (PDT)
Local: Tues, Oct 27 2009 4:21 pm
Subject: Remove rule at runtime
Is there a way to remove a rule from the rulebase at runtime?

I want to create a rules engine that is exposed as a webservice.
Clients will post to /facts/assert to put a new fact into the working
memory and will post to /facts/retract to remove a fact from the
working memory.  I currently start my environment by creating a single
engine and single rulebook:

//happens on start:
RULER_ENGINE = Ruleby::Core::Engine.new
RULE_BOOK = SimpleRulebook.new(RULER_ENGINE)
RULE_BOOK.rules //loads rules from external source

In my facts controller I have something like this:

  def assert
    RULER_ENGINE.assert CoolObj.new(params[:obj])
    RULER_ENGINE.match
    render :nothing => true
  end

  def retract
    GarbageManRules.new(RULER_ENGINE) do |rb|
      rb.rule [CoolObj, :c, m.pk == params[:pk], m.type == params
[:type]] do |v|
        rb.retract(v[:c])
      end
    end
    RULER_ENGINE.match
    render :nothing => true
  end

My understanding is that when I add the rule to the rulebase..its
there forever.  In my case its really a transient rule just used to
remove something from the working memory and should be removed after
that action. Am I maybe approaching this wrong?  Is there a way to
remove this rule from the rulebase once I am done with it?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Kutner  
View profile  
 More options Oct 27, 9:32 pm
From: Joe Kutner <jpkut...@gmail.com>
Date: Tue, 27 Oct 2009 20:32:49 -0500
Local: Tues, Oct 27 2009 9:32 pm
Subject: Re: [ruleby] Remove rule at runtime
Ruleby does not support retracting rules at this time.

In your case, I think you would be better served by creating a new
class that you can write rules for retracting facts around.  Something
like this:

class Retractor
  attr :class_to_retract
end

rule [CoolObj, :c, m.pk == params[:pk], m.type == params[:type]],
           [Retractor, :r, m.class_to_retract = CoolObj] do |v|
       retract(v[:c])
       retract(v[:r])
end

The Retractor class could even contain the patterns you use to select
the CoolObjs.  I hope this helps, please let me know if its not clear.

Joe


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jake Dempsey  
View profile  
 More options Oct 29, 9:57 am
From: Jake Dempsey <angelo0...@gmail.com>
Date: Thu, 29 Oct 2009 06:57:50 -0700 (PDT)
Local: Thurs, Oct 29 2009 9:57 am
Subject: Re: Remove rule at runtime
Yeah I have something like this now...It works well if its a one to
one of retractor obj to cool obj.  If you have 3 CoolObjs in working
memory and then send one retractor in..you will only remove one
CoolObj.

On Oct 27, 8:32 pm, Joe Kutner <jpkut...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google