wongi-engine icon indicating copy to clipboard operation
wongi-engine copied to clipboard

How to use the engine with OpenStruct object

Open rrepen opened this issue 11 years ago • 4 comments

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é

rrepen avatar Apr 19 '13 15:04 rrepen

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 :-)

kwerle avatar Apr 19 '13 16:04 kwerle

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

ulfurinn avatar Apr 19 '13 16:04 ulfurinn

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

ulfurinn avatar Apr 19 '13 16:04 ulfurinn

I've been slowly working towards this, actually.

ulfurinn avatar Aug 28 '15 21:08 ulfurinn