Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the engine with OpenStruct object #13

Open
rrepen opened this issue Apr 19, 2013 · 4 comments
Open

How to use the engine with OpenStruct object #13

rrepen opened this issue Apr 19, 2013 · 4 comments

Comments

@rrepen
Copy link

rrepen commented Apr 19, 2013

I would like to try wongi-engine but I get some problems to set it.
I am used to ruleby where I can easily access fields in the OpenStruct objects I want to put in the facts base and do some comparison on them to trigger rules.
I want to be able to see if a node has already recorded an error , and from there trigger an action, and depending on the type of error, remove the facts.

I wonder how I can write the "has" or other matchers.

Each object has a box method so I would like to do obj1.box == obj2.box
and also some other comparisons on other fields too

Thanks
René

@kwerle
Copy link
Collaborator

kwerle commented Apr 19, 2013

The way I've been doing this sort of thing is like:

object_list.each do |one_object|
    engine << [one_object, 'is', OBJECT_TYPE]
    engine << [one_object, ATTRIBUTE1 << one_object.ATTRIBUTE1]
    engine << [one_object, ATTRIBUTE2 << one_object.ATTRIBUTE2]
    ...
end

and then rules something like

rule "object1 box == object2 box" do
  forall {
    has :Object1, 'is', OBJECT_TYPE
    has :Object2, 'is', OBJECT_TYPE
    has :Object1, 'box', :OneValue
    has :Object2, 'box', :OneValue
  }

Of course, if you're only using the rule engine on one type of thing, you can leave out the type step/rule.

If there's a better way, I'd love to hear about it :-)

@ulfurinn
Copy link
Owner

There isn't. If you want to use structures, you must decompose them into triples.

@ulfurinn
Copy link
Owner

Although having some sort of automatic translation is an interesting idea.

@ulfurinn
Copy link
Owner

I've been slowly working towards this, actually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants