In this lab we will work with First Order Logic and PowerLoom, a knowledge representation system. You will have to go through the following steps and create some logical statements representing Family Relations.
(defmodule "PL-USER/FAMILY") (in-module "FAMILY") (reset-features) (in-dialect KIF)
Save your module to disk (show up in your powerloom folder or the “kbs” subfolder), and loading it back later:
(save-module "FAMILY" "FAMILY.PLM") (load "FAMILY.PLM") (in-module "FAMILY") ;; If not already in this module
(defconcept Person(?p)) ;; Defining a Person (defconcept Male (?p Person)) ;; A Male is a Person (defconcept Female (?p Person)) ;; A Female is a Person
(assert (Male John)) (assert (Female Mary)) (ask (Male John)) (ask (Female Mary))
(assert (forall (?x) (=> (Male ?x) (Person ?x))))
Do the same for Females.
(retrieve (Person ?p))
Returns all possible substitutions for ?p:
(retrieve all (Person ?p))
(ask (Male Mary))
If we add this assertion, being a male implies you are not a female:
(assert (forall (?p) (<=> (Male ?p) (not (Female ?p)))))
Create the same assertion for Females.
(defrelation BrotherOf ((?p1 Male) (?p2 Person))) (assert (BrotherOf John Mary)) (assert (Person Olaf)) (assert (BrotherOf Olaf Mary)) (retrieve all (BrotherOf ?x Mary)) ;; Retrieve all Brothers of Mary
Create a new predicate called ParentOf.
(deffunction GetFather ((?p1 Person)) :-> (?p2 Male)) ;; The second value (after the symbol ":->") is the output variable of the function
We can refer to a function in a sentence in this way:
(assert (= (GetFather Mary) Zod))
A new axiom that uses a function and equivalence
(assert (<=> (= (GetFather ?c) ?f) (and (Male ?f) (ParentOf ?f ?c))))
Ask the following: