grape
grape copied to clipboard
Match Multiple in Single Rule
It would be helpful to capture and operate on all of the nodes that match a particular pattern in one rule. This might be analgous to a "for all" statement in first order logic.
For example, to fire a worker from an organization you might have delete them from multiple departments. See #11 for example.
(rule 'fire-worker ['name]
:read (pattern
(node 'w :label "Worker" :asserts {:name 'name})
(node 'c :label "Company")
(node 'd :label "Department" :all)
(edge 'e1 :label "employer" :src 'w :tar 'c)
(edge 'e2 :label "in_dept" :src 'w :tar 'd)
:delete ['e1 'e2])
This issue might superceed #11 since you can simple match multiple (0) versions of pattern.
@jenshweber - we discussed one way of doing this with "meta-rules", is that still the preferred solution?
Alternative syntax might be something like...
(pattern
(node 'n1 :label "foo")
(forall
(node 'n2 :label "bar")
(edge 'e :label "foobar" :src 'n1 :tar 'n2)))
This would match a single node labelled foo
and all of the adjcent nodes (via edge foobar
) that are themselves labelled bar
.
Yes, this would be good. I am not sure how difficult this will be though. I'll have to think about this.