My first attempt was to find a boss who is in another division…
(run-query '(assert! (rule (big-shot ?name ?division) (and (job ?name (?division . ?title)) (supervisor ?name ?boss) (job ?boss (?division-2 . ?title-2)) (not (same ?division ?division-2)))))) (run-query '(big-shot ?who ?where)) (big-shot (Scrooge Eben) accounting) (big-shot (Bitdiddle Ben) computer)
.. but as pointed out by John Donnellan in the comments, that’s not right because some people do not have a supervisor. We need people who
- don’t have a supervisor OR
- have a supervisor in a different division.
Second attempt:
(run-query '(assert! (rule (big-shot ?name ?division) (and (job ?name (?division . ?title)) (or (not (supervisor ?name ?boss)) (and (supervisor ?name ?boss) (not (job ?boss (?division . ?title-2))))))))) (run-query '(big-shot ?who ?where)) (big-shot (Warbucks Oliver) administration) (big-shot (Scrooge Eben) accounting) (big-shot (Bitdiddle Ben) computer)
Hi thanks again for your blog. I think Oliver Warbucks may be missing from the results. He is in the Adminstration division, but he does not have a supervisor in Adminstration division. I think the query above is asking “Who has an boss in a different division?” (which doesn’t include Oliver), whereas “Who does not (have a boss in same division)?” does include Oliver.
Ahhh yes, you’re right, thanks. I’ve got the logic backwards.