MacFurax has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I plan to build an IPTC based images workflow system.

I would like to base the system on a firewall rules like way of working.

matching rules => actions

Like (very pseudo code):

$iptc.CategoryCode == "BKN" => Delete image
$asset.parentFoldername == "150_Alpha" => $iptc.caption happend " \n Credit Alpha"
...

Do you known any perl module that can help me to parse and/or organize the mathcing rules and actions handling?

I'll use Image::ExifTool fot the IPTC processing.

Thanks and regards

Replies are listed 'Best First'.
Re: rules : action processing like firewall
by roboticus (Chancellor) on Mar 26, 2010 at 09:52 UTC

    MacFurax:

    Visiting cpan and searching for "rules processing" turned up FSA::Rules which appears like it might be a good tool for your purpose. From what I've heard, POE sounds like a good tool for event-driven systems like you want. Finally, the Prolog language was created to handle those sorts of problems, so you may want to check out AI::Prolog.

    I've never used any of the three, though, so you may want to do some more digging.

    I *have* created several workflow systems, and their structure is pretty simple, though. Basically you have a list of queues, and a list of rules for each queue. Periodically, your application wakes up and evaluates the rules for each queue. Each rule scans a set of input queues, and for each item that matches the rule, you move the item to the specified queue. Then, of course, you have all the frills, bells and whistles to turn it into an application.

    Toy example:

    Queues: Q1: "START": Initial bucket for all applications. Q2: "Incomplete": Applications still needing information wait here. Q3: "Complete": Applications ready to process wait here. Q4: "Credit Approval": Applications needing credit approval wait he +re. Q5: "Fulfillment": Tasks awaiting fulfillment wait here. Q6: "DONE": Completed tasks sit here until deleted/archived/etc. Rules: R1: "?Form completed?" Input queues (Q1) Move item to Q2 if missing any of: (Name, Phone, Address, Product Selected) R2: "?Big order?" Input queues (Q3) Move item to Q4 if value_of(Product Selected) > $500 R3: "?Form completed?" Input queues (Q1, Q2) Move item to Q3 unless missing any of: (Name, Phone, Address, Product Selected) R4: "?Approved?" Input queues (Q4) Move item to Q5 if approved R5: "?Rejected?" Input queues (Q4) Move item to Q6 if !approved ... etc. ...

    ...roboticus

      or Workflow, which seems quite extensive. That may be a good or a bad thing, depending.
Re: rules : action processing like firewall
by Anonymous Monk on Mar 26, 2010 at 08:43 UTC
Re: rules : action processing like firewall
by doug (Pilgrim) on Mar 26, 2010 at 17:35 UTC

    I don't know of any framework/module for handling this, but much of your "matching a rule" logic would be easy with the when/given mechanism of 5.10. You might need an eval() to glue everything together

    - doug

Re: rules : action processing like firewall
by MacFurax (Initiate) on Mar 26, 2010 at 09:15 UTC
    I known how to manipulate IPTC values, my point is finding
    a module that allow me to configure a workflow on images
    Like, if iptc caption field contain "blabla" do that with the images,
    if iptc field credit containt "Alpha" move picture to Alpha folder ...
    And that like a firewall rules way. As long as a rules didn't match get
    to the next rule up to the last.
    I have hard time to clearlly explain what I want.

      Try following:
      my $rules = [ [ sub { do_some_test_here } => sub { do_some_action } ], [ sub { test2 } => [ [ sub { sub_test } => sub { action } ], ], ]; sub process { my ($list, $data) = @_; my $retval; for my $def (@$list) { next unless $def->[0]($data); $retval = ref $def->[1] eq 'ARRAY' ? process ($def->[1], $data) : $def->[1]($data) || 1 ; last if $retval; } $retval; } process ($rules, { iptc => $iptc });
        yeah happy.barney,

        I was exploring that way right now.
        I will just allow rules file to be provided as a parameters (loaded at runtime) to the "rule engine" script.

        Like that I can monitor more than one folder (that will be considered as queues like suggested by roboticus) for new images.
        Each folder will need different processing.
        Images will pass from one folder to an other, giving me my workflow.

        That will also give me kind of multi processing.

        Sound's good to me !

        Thank's for your suggestions !

        Whow !
        I just realize that you provid "recursion" in the rules !
        Great, I didn't think about it !

        MacFurax