I want to create a collection of facts from a nested collection, where the facts do not share a property with another fact in working memory.
Let's say I have a Person class that has a collection of Address objects. I want the set of all the Address facts from Person John that do not have the same zip code as an Address fact currently in working memory.
I'm thinking that the only way to do this is with a "from accumulate", but I can't figure out how to add an additional condition in the source pattern line. When I try the below, I get a rule compilation error:
when
p: Person(name == "John")
h: HashSet(size > 0) from accumulate (addr: Address(zc: zipcode) from p.addresses /*and not Address(zipcode == zc)*/,
init(Set s = new HashSet();)
action(s.add(addr);),
result(s)
)
I need the contents of the final collection all at once to iterate over in the "then" clause; otherwise I would move the source pattern and the "not" check out of the "from accumulate" and do away with the "from accumulate" entirely.
Is there any way to do what I'm describing? Thanks in advance.