===== Lab 6: PowerLoom =====
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**.
==== PowerLoom ====
* The main webpage of [[http://www.isi.edu/isd/LOOM/PowerLoom/|PowerLoom]];
* You can download [[http://www.isi.edu/cgi-bin/LOOM/download-powerloom.cgi?ID=powerloom-3.2.0.zip|here]] the stable version;
* PowerLoom documentation in [[http://www.isi.edu/isd/LOOM/PowerLoom/documentation/manual/manual.pdf|PDF]] or [[http://www.isi.edu/isd/LOOM/PowerLoom/documentation/manual/manual.html|HTML]] version.
* Some **helpful** commands:
(all-facts-of X) ;; prints out all known facts about X
(help assert) ;; prints out help text about “assert”
(demo) ;; leads you through various PowerLoom demonstrations
==== Doing Knowledge Representation and Reasoning with PowerLoom ====
- **Basic Commands:**\\ Create a new, empty, module to work in and specify representation language syntax:\\
(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
- **Defining a basic type/class predicate (a unary relation) called a "concept":**\\
(defconcept Person(?p)) ;; Defining a Person
(defconcept Male (?p Person)) ;; A Male is a Person
(defconcept Female (?p Person)) ;; A Female is a Person
- **Basic TELLing and ASKing:**\\
(assert (Male John))
(assert (Female Mary))
(ask (Male John))
(ask (Female Mary))
- **Adding First Order Logic (FOL) axioms:**\\ Being a **Male** implies you are a person:
(assert (forall (?x) (=> (Male ?x) (Person ?x))))
Do the same for **Females**.
- **Asking for possible substitutions:**\\ Returns **one** possible substitutions for ?p if it exists:
(retrieve (Person ?p))
Returns **all** possible substitutions for ?p:
(retrieve all (Person ?p))
- **The Open-World semantics:**\\ The following should be unknown since it wouldn't conflict with the KB
(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**.
- **Defining a regular relation predicate:**\\ The following creates a new **Predicate** called **BrotherOf**:
(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**.
- **Defining a regular function and using it:**\\ If a (binary) relation always maps its first argument to exactly one value (i.e., if it it “single-valued”) we can specify it as a function instead of a relation.
(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:
* Is Zod Male?
* Is Zod Mary's parent?
- **Defining more family Relations:**\\ Now you are on your own...add more **family relations** like:
* SisterOf;
* AreSiblings;
* SonOf, DaughterOf, ChildOf;
* GrandmotherOf and GrandfatherOf;
* UncleOf, AuntOf;
* ... \\ and try **answering** questions like:
* Is X a sibling of Y?
* Who are X's grandmothers?
* Who are X's uncles?
* Does X's mother's mother have a male child?
* ...