0% found this document useful (0 votes)
5 views35 pages

14-Knowledge Representation - Part2

The document provides an overview of First Order Predicate Logic (FOPL) as part of a course on Knowledge Representation. It covers key concepts such as constants, predicates, functions, variables, quantifiers, and the structure of FOPL sentences, along with examples and semantics. Additionally, it discusses inference methods like Modus Ponens and the process of unification in FOPL.

Uploaded by

dw9324764
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views35 pages

14-Knowledge Representation - Part2

The document provides an overview of First Order Predicate Logic (FOPL) as part of a course on Knowledge Representation. It covers key concepts such as constants, predicates, functions, variables, quantifiers, and the structure of FOPL sentences, along with examples and semantics. Additionally, it discusses inference methods like Modus Ponens and the process of unification in FOPL.

Uploaded by

dw9324764
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Year: 2024-2025

Spring Semester

Natural Language
Processing
Dr. Wafaa Samy
Dr. Hanaa Eissa
Knowledge Representation
(Part 2)
Lecture (14)

2
Contents
• Knowledge Representation (KR)
o First Order Predicate Logic (FOPL)

3
First Order Predicate Logic (FOPL)
• More expressive logic than propositional logic.
• First-order predicate logic (FOPL) models the world
in terms of FOPL Symbols:
1. Constants (or objects)
2. Predicates
3. Functions
4. Variables
5. Quantifiers

4
Constants
• Constants (or objects) refer to a single object
in our domain.
o Objects, which are things with individual
identities.
o Constants are objects: John, apples, etc.

• Examples:
o Adel, Bicycle, Scooter, Cairo, Students, lectures,
companies, cars , etc.
5
Predicates
• Expresses a relationship between objects in a given
domain, or defines properties of those objects.
1. Relations that hold among sets of objects.
2. Properties of objects that distinguish them from other objects.
• With our constants and predicates defined, we can now use the
predicates to define relationships and properties of the constants
(also called Atomic sentences).
• Predicates are properties and relations:
John likes apples.
likes(John, apples)
• Examples:
o Relationships: owns, rides, knows, brother-of, bigger-than,
outside, part-of, has-color, occurs-after, visits, precedes, etc.
o Properties: person, blue, oval, even, large, sunny, book, two-
6 wheeled, etc.
Predicates: Examples
• Adel is a person.
o Person(Adel)
• Ali is a person.
o Person (Ali)
• Adel and Ali both know each other.
o Knows( Adel , Ali )
o Knows( Ali , Adel )
• Ahmed rides a bicycle.
o Rides (Ahmed, Bicycle)
• Ali rides a scooter.
o Rides (Ali, Scooter)
• A Bicycle is two-wheeled.
o Two-Wheeled (Bicycle)
7
Example (1)
• Represent the following statement in FOPL:
ElShabrawy serves vegetarian food.

• Solution:
Serves (ElShabrawy, VegetarianFood)

8
Functions
• Functions, which are a subset of relations where there is
only one “value” for any given “input”.
• Functions transform objects:
o Allows to transform a constant into another constant.
• Examples of Functions:
o father-of, best-friend, second-half, one-more-than,
fruit_of, etc.
• Examples:
o The brother_of function is demonstrated as:
Ahmed knows Hasan's brother
Knows(Ahmed, brother_of(Hasan))

9
o likes(John, fruit_of(apple_tree))
Variables
• Abstract sentence that don’t specify specific
objects.
• Variables represent any object:
likes(X, apples)

• For example:
If x knows Ali then x is a person.
Knows(x, Ali) ⇒ Person(x)
10
Compound Sentences
• A Compound sentence can be built from atomic
sentences using the connectives:
∧ AND
∨ OR
¬ NOT
⇒ Implication or Logical Conditional (if … then …)
⇔ Equivalence (if and only if)

11
Examples
• Ahmed and Ali know one another.
Knows (Ahmed, Ali) ∧ Knows (Ali, Ahmed)

• Ahmed knows Ali, and Ali does not know Ahmed.


Knows(Ahmed, Ali) ∧ ¬ Knows(Ali, Ahmed)

• Ahmed rides a scooter or Ahmed rides a bicycle.


Rides(Ahmed, Scooter) ∨ Rides(Ahmed, Bicycle)

12
Operator Precedence
()
¬ Highest



⇔ Lowest
• Person (Ahmed) ∧ Rides (Ahmed, Scooter) ∨ Rides
(Ahmed, Bicycle)
• Grouped as:
( Person (Ahmed) ∧ Rides (Ahmed, Scooter) ) ∨ Rides
(Ahmed, Bicycle)
13
Semantics of FOPL
• FOPL sentences can be assigned a value True
or False based on whether the proposition
they encode are in accordance with the world
or not.

14
Atomic and Logical Connectives
• Atomic formulas are taken to be true if they are literally
present in the knowledge base or if they can be inferred from
other formula that are in the knowledge base.

• The interpretation of formulas involving logical connectives is


based on the meaning of the components in the formulas
combined with the meanings of the connectives they contain.

P Q ¬P P∧Q P∨Q P⇒Q P⇔Q


F F T F F T T
Connective
Semantics F T T F T T F

T F F F T F F
15
T T F T T T T
Example (2)
• Write the truth table of the following formulas:
¬p ∧ q
(p ∨ q) ∧ ¬p

16
Example (2): Solution
• Write the truth table of the following formulas:
¬p ∧ q
(p ∨ q) ∧ ¬p
p q ¬p ¬p∧q p∨q (p ∨ q) ∧ ¬ p
F F T F F F

F T T T T T

T F F F T F

T T F F T F

Since, the truth table values of both statements is the same. Thus,
17
the two statements ¬p ∧ q and (p ∨ q) ∧ ¬p are logically equivalent.
Quantifiers
• In first-order predicate logic, there are two quantifiers:
o For all: ∀
o There exists: ∃
• Quantifiers qualify values of variables.
o True for all objects (Universal): X. likes(X, apples)
o Exists at least one object (Existential): X. likes(X, apples)
• Examples:
o There exists x, such that x is a person.
∃ x. Person (x)
o For all persons, there exists someone that knows Ahmed
or Ali.
18
∀x. ∃ y. Person (x) ∧ (Knows (y, Ali) ∨ Knows (y, Ahmed))
Quantifiers (Cont.)
• Universal quantification
o x. P(x) means that P is true for all values of x in the
domain associated with that variable.
o Example: x. dolphin(x) ⇒ mammal(x)

• Existential quantification
o x. P(x) means that P is true for some values of x in the
domain associated with that variable.
o Example: x. mammal(x)  lays-eggs(x)
o Permits one to make a statement about some object
without naming it.

19
Quantifiers (Cont.)
• Universal quantifiers are often used with “implies” to form “rules”:
x. student(x) ⇒ smart(x) means “All students are smart”.
• Universal quantification is rarely used to make statements about
every individual in the world:
x. student(x)  smart(x) means “Everyone in the world is a
student and is smart”.
• Existential quantifiers are usually used with “and” to specify a list
of properties about an individual object:
x. student(x)  smart(x) means “There is a student who is smart”.
• A common mistake is to represent this English sentence as the FOPL
sentence: x. student(x) ⇒ smart(x)
But what happens when there is a person who is not a student?
20
Common mistakes to avoid.
Quantifier Scope
• Switching the order of universal quantifiers does not
change the meaning:
x. y. P(x,y) ⇔ y. x. P(x,y)

• Similarly, you can switch the order of existential


quantifiers:
x. y. P(x,y) ⇔ y. x. P(x,y)
• Switching the order of universals and existentials
does change meaning:
o Everyone likes someone: x. y. likes(x,y)
o Someone is liked by everyone: y. x. likes(x,y)
21
Examples of Translating English to
FOPL
• Every gardener likes the sun.
x. gardener(x) ⇒ likes(x, Sun)

• You can fool some of the people all of the time.


x. t. person(x)  time(t) ⇒ can-fool(x, t)

• All purple mushrooms are poisonous.


x. (mushroom(x)  purple(x)) ⇒ poisonous(x)

• Ahmed is not tall.


tall(Ahmed)

22
User provides
• Constant symbols, which represent individuals in the world:
o Mary
o 3
o Green

• Function symbols, which map individuals to individuals:


o father-of(Mary) = John
o color-of(Sky) = Blue

• Predicate symbols, which map individuals to truth values:


o greater(5,3)
o green(Grass)
o color(Grass, Green)
23
Symbols of FOPL
• Logical Symbols: FOPL provides
o Punctuations: “(” , “)” , “.”
o Connectives : “∧”, “∨”, “¬”, “⇒”, “⇔”
o Quantifiers: “∀”, “∃”
 Universal x
 Existential x
o Variables: an infinite symbols, such as x, y, and z, sometimes
with subscripts.
 E.g. x, y, foo, etc.

• Non-Logical Symbols:
o Function symbols
o Predicate symbols
24
How Sentences are built?
• A term (denoting a real-world individual) is a constant
symbol, a variable symbol, or a function.
x and f(x1, ..., xn) are terms, where each xi is a term.
• An atomic sentence which has value true or false.
• A complex sentence is formed from atomic sentences
connected by the logical connectives:
 P, P  Q, P  Q, P ⇒ Q, P ⇔ Q where P and Q are sentences.
• A quantified sentence adds quantifiers  and .
• A well-formed formula (wff) is a sentence containing no
“free” variables.
o That is, all variables are “bound” by universal or existential quantifiers.
x. P(x,y) has x bound as a universally quantified variable,
25
but y is free.
Context-Free Grammar for FOPL
Formula → AtomicFormula
| Formula Connective Formula
| Quantifier Variable . Formula
| ¬ Formula
| (Formula)
AtomicFormula → Predicate (Term,…)
Term → Function (Term,…)
| Constant
| Variable
26
Context-Free Grammar for FOPL
(Cont.)
• Connective → ∨ | ∧ | ⇒ | ⇔
• Quantifier → ∀ | ∃
• Constant → Adel | Cairo|…
• Variable → x | y | …
• Predicate → Person |…
• Function → locationOf | …

27
Example (3)
• Represent the following statement in FOPL:

Giza is near Cairo.

• Near (locationOf(Giza), locationOf(Cairo))

28
Semantics of FOPL
• FOPL sentences can be assigned a value True or False based
on whether the proposition they encode are in accordance
with the world or not.
• Example: Giza is near Cairo.
Near (locationOf(Giza), locationOf(Cairo))
• The meaning of this formula arises from the relationship
between the terms LocationOf (Giza), LocationOf (Cairo), the
predicate Near, and the objects and relation they correspond to
in the world being modeled.
• Specifically, this sentence can be assigned a value of True or
False based on whether or not the real Giza is actually close to
29 Cairo or not.
FOPL: Variables and Existential
Quantifier
• A restaurant that serves grilled food near Pyramids.
∃x. Restaurant(x) ∧ Serves (x, GrilledFood)
∧ Near (locationOf(x),locationOf(Pyramids))
• Note: for this sentence to be true there must be at least one object
such that if we were to substitute it for the variable x, the resulting
sentence would be true. We can substitute variable by a constant ,
predicate, function or another variable. So,
same expression can be used many times
by substitute the variables in expression.
Note: We removed ∃x and replace x by
• Substitute x by Tikka ( { Tikka/x} ) Tikka.
Restaurant(Tikka) ∧ Serves (Tikka, GrilledFood)
∧ Near (locationOf(Tikka),locationOf(Pyramids))
Note: Based on the ∧ operator, this sentence will be true if
30
all of its three component atomic formulas are true.
FOPL: Variables and the Universal
Quantifier
• All fast-food restaurants serve grilled food.
∀x. FastFoodRestaurant(x) ⇒ Serves(x, GrilledFood)

• Note: for this sentence to be true, it must be the case that every
substitution of a known object for x must result in a sentence that
is true. We can substitute variable by a
constant, predicate, function, or
another variable. Note: We removed
∀x and replace x by Tikka. Then,
• Substitute x by Tikka ( { Tikka/x} ) removed ∀x and replace x by Chilis.

FastFoodRestaurant(Tikka) ⇒ Serves(Tikka, GrilledFood)

• Substitute x by Chilis ( { Chilis/x} )


31 FastFoodRestaurant(Chilis) ⇒ Serves(Chilis, GrilledFood)
Inference with FOPL
• Inference is the ability to add valid new propositions to a
knowledge base, or to determine the truth of propositions not
explicitly contained within a knowledge base.
• Modus Ponens is a familiar form of inference and is informally
known as if-then reasoning.
• Modus ponens is defined as follows, where α and β should be
taken as FOPL formulas.
o Modus ponens simply states that if the left-hand side of an
implication rule is present in the knowledge base, then the
right-hand side of the rule can be inferred.

Given α, α ⇒ β, then β
32
Example (4): Inference in First Order
Predicate Logic using Modus Ponens

FastFoodRestaurant(Tikka)
∀x. FastFoodRestaurant (x) ⇒ Serves(x, GrilledFood)
___________________________________________
First, unification of these expressions by
find necessary substitutions of variables
Serves (Tikka, GrilledFood) to make these expressions matched. We
removed ∀x and replace x by Tikka.
Second, apply Modus Ponens inference
rule.
• The formula FastFoodRestaurant(Tikka) matches the
antecedent of the rule, thus allowing us to use modus
33 ponens to conclude Serves(Tikka , GrilledFood).
Unification
• Unification is an algorithm for determining the
substitution needed to make 2 predicate calculus
expressions match.
• The algorithm returns fail if the 2 expressions cannot be
matched.
• Substitution is finite set of bindings of the form: E/x
put the expression E in place of the variable x.
We can substitute variables only.
• Examples of valid Substitutions: We can not substitute constant.
o {Adel/x, Maged/y} We can substitute variable by a
constant, predicate, function, or
o {x/y} another variable.

• Note that {Ali/Maged} is NOT a valid substitution.


34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy