Course Code: IS 463
Course Title:
Knowledge Base Systems Application
PART : 1
Prof. Taymoor Mohamed Nazmy
Dept. of computer science, faculty of computer science, Ain Shams uni.
Ex-vice dean of post graduate studies and research Cairo, Egypt
Course Description
• Introduction.
• Review of first-order logic, relational algebra, and relational
calculus.
• Fundamentals of logic programming. Logic for knowledge
representation. Architecture of knowledge-base system.
Fundamentals of deductive databases. Top-down and bottom-
up query processing. Some important query processing
strategies and their comparison. Project or term paper on
current research topics.
• Textbook:
• Richard A. Frost, Introduction to Knowledge Based Systems.
About the lecturer
- Prof. of computer science since 2006,
- Director of Ain Shams information network,
- Vice dean of post graduate studies and research,
- Vice dean of environmental and social affairs,
- Member in editorial board of many Int. journals,
- Member in Scientific committee of many int.
conferences
- Executive chair of int. conf. on information and
intelligent systems,
- Published more than 60 scientific papers in int. journals
and conference,
-Supervised more than 20 master and Ph. D thesis.
About the course
• The materials of this course were collected from many resources, include the reference
book, other books, online courses, presentations, and web sites.
• There are many details will be given to simplify topics in this course, however at the end of
the course the most important topics will be highlighted.
• The delivered materials through this presentation is your main resource,
• This presentation will be delivered to you, through one ways, such as drop box, the course
consist of 4 parts, we will starts with Part 1,2, then continue with Part 3,4.
• There will be term exams 40%
• The attendance and term paper 20%
• The final exam 40%
• The exam will include subjective and objective questions,
• Through this course try to extends your knowledge by improving your self learning
capabilities.
The lecture link
• https://www.dropbox.com/s/9ee1j8jxj8jep8e/
Knowledge%20base%20system%20appl.-
%20P%201%2C2-ver1.pptx?dl=0
• Ntaymoor19600@gmail.com
Term paper
• Each 3-4 students have to prepare a report (20-30
page), to be delivered before the end of the term
in one of the following topics:
• Big data analytics,
• Types of query languages,
• Expert systems,
• Web SQL Database,
• Query processing,
• Open topic.
Introduction
Knowledge base system appl.  p 1,2-ver1
Knowledge base system appl.  p 1,2-ver1
Cognitive sensors and networks
Cognitive information fusion
Cognitive robots
Cognitive agent technologies
Cognitive machine learning
Cognitive semantics
Cognitive mobile systems
Cognitive signal processing
Cognitive mobile systems
Cognitive vehicle communication
Cognitive knowledge representation
DNA and genome cognition
Cognitive image processing
Cognitive space communication
Cognitive agent technologies
Cognitive decision theories
Cognitive learning engines
Cognitive inference engines
Big data cognition
Cognitive informatics
Cognitive computer vision
KR and human brain
• Human brain can be considered as a huge knowledge base
system. Human can represent his knowledge by natural
language, sign language, Rhythms, painting, etc.
• Human brain can process the represented knowledge with
many complex fast methods called cognitive processes.
• Do you know that each human cell is it self a storage for
knowledgebase, how?
• Some of those method where simplified to be used by
computer, as we will see later.
Knowledge base system appl.  p 1,2-ver1
KR and artificial cognitive systems
• In the last few years, a big progress was achieved
towards having a machine that can understand
directly human language, self learning, and
compete with human to answer difficult
questions.
• This machine is called IBM WATSON, it
represents the new era of computing to have what
is called artificial cognitive systems. Most of
computer science disciplines will turned towards
this system.
A semantic network to represent the relation
among different topics related to knowledgebase
Definitions
• Knowledge: among other things, knowledge is a relation between a
knower and a proposition
– knower : John
– proposition: the idea expressed by a simple declarative sentence,
like “Mary will come to the party.”
– Knowledge representation, then, is the field of study concerned
with using formal symbols to represent a collection of
propositions.
– Reasoning: it is the formal manipulation of the symbols representing
a collection of believed propositions to produce representations of
new ones.
– Reasoning is a form of calculation, not unlike arithmetic, but over
symbols standing for propositions rather than numbers
Artificial Intelligence and Knowledge Representation
 A description of Artificial Intelligence is:

 The study and development of systems that
demonstrate intelligent behavior
 Based on the above, a description of Knowledge
Representation & Reasoning is:
 The study of ways to represent and reason with
information in order to achieve intelligent behavior
17
Main questions
How we can represent knowledge
as symbol structures ?
How we can use that knowledge to
intelligently solve problems ?
Sources of Knowledge
• The main source of knowledge is the human
and his knowledge can be:
• documented
– books, journals, procedures
– films, databases
• undocumented
– people’s knowledge, explicit and tacit.
Types Knowledge
Type of Knowledge Examples
Facts dogs, teeth, house
Relations mother of Paul
Rules If it is cloudy then
It will rain
Concepts For all X & Y
Procedures Do this then that
Knowledge processing cycle
Levels of Knowledge
• Shallow level:
– very specific to a situation Limited by IF-THEN type
rules. Rules have little meaning. No explanation.
• Deep Knowledge:
– problem solving. Internal causal structure. Built from a
range of inputs
– emotions, common sense,
– difficult to build into a system.
A knowledge-based system
• A knowledge-based system (KBS) is a computer program that can
represents the knowledge and reasons to solve complex problems.
• A knowledge based system has two types of sub-systems: a knowledge
base and an inference engine.
• The knowledge base represents facts about the world using knowledge
representation (KR) methods. The inference engine represents logical
assertions and conditions about the world, usually represented via IF-
THEN rules.
• Knowledge-based systems were first developed by artificial
intelligence researchers. These early knowledge-based systems were
primarily expert systems – in fact, the term is often used synonymously
with expert systems.
Knowledge base system appl.  p 1,2-ver1
Knowledge Representation
A subarea of Artificial Intelligence concerned with understanding,
designing, and implementing ways of representing information
(knowledge) in computers so that programs (agents) can use this
information…
• to derive new information that is implied by it, (inference, and
reasoning),
• to converse with people in natural languages,
• to decide what to do next
• to plan future activities,
• to solve problems in areas that normally require human
expertise.
How can knowledge be represented ?
 Symbolic methods
 Declarative Languages (Logic)
 Declarative programing means style of building the structure and elements of computer programs—that expresses
the logic of a computation without describing its control flow. Where Algorithm = Logic + Control.
 Imperative Languages (C, C++, Java, etc.),
 Imperative programing means programming paradigm that uses statements that change a program's state.
 Hybrid Languages (Prolog)
 Rules
 Frames
 Semantic Networks
…
 Non – symbolic methods
 Neural Networks
 Genetic Algorithms
Knowledge base system appl.  p 1,2-ver1
Knowledge
Representation using
Propositional Logic
What language should we use?
• Natural language, ie English, ASL, Cantonese. Too ambiguous.
• Programming Language, ie C++, Lisp, Java. Not very expressive.
We will use logic! Actually there are many different logics.
We will start by considering
•Propositional Logic. We will find that has some drawbacks so we
will consider the more general
•Predicate Logic. This too, has limitations, so we will consider the
more general
•First-Order Logic.
•Predicate logic
• (occasionally referred to as
• First-order logic (FOL))
Propositional Logic
Predicate Logic
First-Order Logic
Logic for KR
• Logic is a great knowledge representation language for many
AI problems
• Propositional logic is the simple foundation and fine for some
AI problems
• First order logic (FOL), is also known Predicate calculus is
much more expressive as a KR language and more commonly
used in AI
• There are many variations of logics such as: horn logic, higher
order logic, three-valued logic, probabilistic logics, etc.
Simple Propositions and
Compound Propositions
• Fast foods tend to be unhealthy.
• Parakeets are colorful birds.
• More complex proposition such as:
• If fast foods tend to be unhealthy, then you
shouldn’t eat them.
• Parakeets are colorful birds, and colorful birds
are good to have at home.
Basic connectives and truth tables
primitive and compound statements can be represented
by logical connectives, such as:
p p,
(a) conjunction (AND):
(b) disjunction(inclusive OR):
(c) exclusive or:
(d) implication: (if p then q)
(e) biconditional: (p if and only if q, or p iff q)
(f) negation ( )
p q
p q
p q
p q
p q
32
Truth tables
 Logic, like arithmetic, has operators, which apply to
one, two, or more values (operands)
 A truth table lists the results for each possible
arrangement of operands
 The rows in a truth table list all possible sequences of
truth values for n operands, and specify a result for
each sequence
 Hence, there are 2n rows in a truth table for n
operands
Truth tables for logical connectives
TTFFTFF
FTTFTTF
FFTFFFT
TTTTFTT
~ QPQPQPQPPQP 
Or p q p q p q p q p qp q
0 0 0 0 0 1 1
0 1 0 1 1 1 0
1 0 0 1 1 0 0
1 1 1 1 0 1 1
The simplest example
Suppose our KB consists of
P
Q
R
A simple goal is … Q. Literally we are asking is it the
case that Q is true. In this case, the answer is yes!
Another simple example
Suppose our KB consists of
P
Q
R
Now suppose the goal is … P  Q.
We are literally asking is it the case that P is true and Q
is true. In this case, the fact P  Q is not in our KB. But
we can infer it by using the And rule.
36
Example formula and truth-table
(p  q)  r
p q r q p  q (p  q)  r
T T T F T T
T T F F T F
T F T T T T
T F F T T F
F T T F F T
F T F F F T
F F T T T T
F F F T T F
Truth tables II
A complex sentence:
(p H) DH)  P
38
Logical expressions
• All logical expressions can be computed with some combination
of and (), or (), and not () operators
• For example, logical implication can be computed this way:
• Notice that X  Y is equivalent to X  Y
X Y X X  Y X  Y
T T F T T
T F F F F
F T T T T
F F T T T
39
Another example
• Exclusive or (xor) is true if exactly one of its operands is true
• Notice that (XY)(XY) is equivalent to X xor Y
X Y X Y X  Y X  Y (XY)(XY) X xor Y
T T F F F F F F
T F F T F T T T
F T T F T F T T
F F T T F F F F
How to built
Propositional logic sentences
• User defines set of propositional symbols, like P and Q
• User defines semantics of each propositional symbol:
– P means “It is hot”, Q means “It is humid”, etc.
• A sentence (well formed formula) is defined as follows:
– A symbol is a sentence
– If S is a sentence, then S is a sentence
– If S is a sentence, then (S) is a sentence
– If S and T are sentences, then (S  T), (S  T), (S  T), and (S ↔ T)
are sentences
Examples of PL sentences
• P means “It is hot.”
• Q means “It is humid.”
• R means “It is raining.”
• Q  P
“If it is humid, then it is hot”
• (P  Q)  R
“If it is hot and humid, then it is raining”
Example
 B means Mihai has money
 A means The car is white
 F means The car is nice
 C means Mihai goes to the mountain
 If the car is white or the car is nice and Mihai has
money then Mihai goes to the mountain
 (A  F)  B  C
Example
s: Phyllis goes out for a walk.
t: The moon is out.
u: It is snowing.
( )t u s   : If the moon is out and it is not snowing, then
Phyllis goes out for a walk.
If it is snowing and the moon is not out, then Phyllis
will not go out for a walk. ( )u t s   
Tautologies
A sentence is a tautology if it is true for any setting of its
propositional symbols
(P OR Q) OR (NOT(P) AND NOT(Q)) is a tautology
Is this a tautology?
• (P => Q) OR (Q => P)
• Try it.
46
Inference rules in propositional logic
• (a OR b) ≡ (b OR a) commutatitvity
• (a AND b) ≡ (b AND a) commutatitvity
• ((a AND b) AND c) ≡ (a AND (b AND c)) associativity
• ((a OR b) OR c) ≡ (a OR (b OR c)) associativity
• NOT(NOT(a)) ≡ a double-negation elimination
• (a => b) ≡ (NOT(b) => NOT(a)) contraposition
• (a => b) ≡ (NOT(a) OR b) implication elimination
• NOT(a AND b) ≡ (NOT(a) OR NOT(b)) De Morgan
• NOT(a OR b) ≡ (NOT(a) AND NOT(b)) De Morgan
• (a AND (b OR c)) ≡ ((a AND b) OR (a AND c)) distributitivity
• (a OR (b AND c)) ≡ ((a OR b) AND (a OR c)) distributitivity
Question
• Use propositional formulas to represents the
sentence, 'He will come on the 8:15 or the 9:15
train; if he will have time to visit us',
• where
p means 'He will come on the 8:15'
q means 'He will come on the 9:15'
r means 'He will have time to visit us'
48
First-order logic (FOL)
49
Limitations of Propositional Logic
p represents ‘My car is red’
q represents ‘This pen is red’
r represents ‘The planet Mars is red’
Cannot work with lower-level objects like ‘my car’,
‘this pen’, ‘the planet Mars’
For most practical applications, we need to be able to
talk about objects and properties within our logical
system
50
Components of First-Order Logic
• Term
– Constant, e.g. Red
– Function of constant, e.g. Color(Block1)
• Atomic Sentence
– Predicate relating objects (no variable)
• Brother (John, Richard)
• Married (Mother(John), Father(John))
• Complex Sentences
– Atomic sentences + logical connectives
• Brother (John, Richard) Brother (John, Father(John))
Atomic Sentences
• Atomic sentences state facts using terms and
predicate symbols
– P(x,y) interpreted as “x is P of y”
• Examples:
LargerThan(2,3) is false.
Brother_of(Mary,Pete) is false.
Married(Father(Richard), Mother(John)) could
be true or false
Function
Function (evaluates to a constant / variable):
Maps Sentences to Objects
Ali is father of Babar father_of(ali) = baber
father(babar) = ali
Babar is son of Ali son_of(babar) = ali
• Interpretation has to be very clear.
• If you write father(baber), the answer should be ali
• For the above functions the arity is 1 (number of arguments to the
function)
Function-II
Functions:
1) shahid likes zahid likes(shahid) = zahid
2) atif likes abid likes(atif) = abid
3)Constants to Variables likes(X) = Y
{X,Y} have two possible BINDINGS
{X, Y} could be {shahid, zahid}
Or
{X,Y} could be {atif, abid}
likes(X) =Y
Substitutions:
For 1 to be true:
{shahid/X, zahid/Y}
For 2 to be true:
{atif/X, abid/Y}
Predicate
Predicate
Maps Sentences to Truth Values (True/False)
1) Shahid is student student(shahid)
2) Sana is a girl girl(sana)
3) Father of baber is elder than Hamza
elder(father(babar), hamza)
For 1 and 2 arity is 1 and for 3 the arity is 2
Predicate-II
Predicate
1) Shahid is a good student
student(shahid,good) or good_student(shahid) or
is_good(shahid,student)
2) Sana is a friend of Saima, Sana and Saima both are
girls
friend_of(sana,saima)^girl(sana)^girl(saima)
3) Bill helps Fred
helps(bill,fred)
FOL Provides
• Variable symbols
– E.g., x, y, foo
• Connectives
– Same as in PL: not (), and (), or (), implies (), if
and only if (biconditional )
• Quantifiers
– Universal x or (Ax)
– Existential x or (Ex)
57
Components of First-Order Logic
• Quantifiers
– Each quantifier defines a variable for the duration of the
following expression, and indicates the truth of the
expression…
• Universal quantifier “for all” 
– The expression is true for every possible value of the
variable
• Existential quantifier “there exists” 
– The expression is true for at least one value of the variable
Quantification of Two Variables
(read left to right)
xyP(x,y) or yxP(x,y)
•True when P(x,y) is true for every pair x,y.
•False if there is a pair x,y for which P(x,y) is false.
xyP(x,y) or yxP(x,y)
True if there is a pair x,y for which P(x,y) is true.
False if P(x,y) is false for every pair x,y.
Quantification of Two Variables
xyP(x,y)
•True when for every x there is a y for which P(x,y) is true.
(in this case y can depend on x)
•False if there is an x such that P(x,y) is false for every y.
yxP(x,y)
•True if there is a y for which P(x,y) is true for every x.
(i.e., true for a particular y regardless (or independent) of x)
•False if for every y there is an x for which P(x,y) is false.
Note that order matters here
In particular, if yxP(x,y) is true, then xyP(x,y) is true.
However, if xyP(x,y) is true, it is not necessary that yxP(x,y)
is true.
60
Properties of Quantifiers
• x y is the same as y x
• x y is the same as y x
• x y is not the same as y x
– x y Loves(x, y)
• “There is a person who loves everyone in the world”
– y x Loves(x, y)
• “Everyone in the world is loved by at least one person”
The Relational Algebra
62
Formal Relational Query Languages
Two mathematical Query Languages form the basis for
“real” languages (e.g. SQL), and for implementation:
• Relational Algebra: More operational, very useful for
representing execution plans.
• Relational Calculus: Lets users describe what they want,
rather than how to compute it. (Non-operational,
declarative.)
 Understanding Algebra & Calculus is key to
 understanding SQL, query processing!
Relational Algebra
• Relational Algebra is a procedural
language that can be used to tell
the DBMS ( Data Base Management
System) how to build a new relation from
one or more relations in the database.
64
Relational Database: Definitions
Relational database: a set of relations
Relation: made up of 2 parts:
– Instance : a table, with rows and columns.
#Rows = cardinality, #fields = degree (arity).
– Schema : specifies name of relation, plus name and
type of each column.
• e.g. Students(sid: string, name: string, login: string,
age: integer, gpa: real).
We can think of a relation as a set of rows or
tuples (i.e., all rows are distinct).
65
Example Instance of Students Relation
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
 Cardinality = 3, degree = 5, all rows distinct
 Do all columns in a relation instance have to
be distinct?
Relation Instance
• The current values (relation instance) of a
relation are specified by a table
• An element t of r is a tuple, represented by
a row in a table
Jones
Smith
Curry
Lindsay
customer-name
Main
North
North
Park
customer-street
Harrison
Rye
Rye
Pittsfield
customer-city
customer
attributes
(or columns)
tuples
(or rows)
67
Relational Algebra
• Basic operations:
– Selection ( ) Selects a subset of rows from relation.
– Projection ( ) Select a subset of columns from relation.
– Cross-product (  ) Allows us to combine two relations.
– Set-difference ( ) Tuples in reln. 1, but not in reln. 2.
– Union (  ) Tuples in reln. 1 and in reln. 2.
• Additional operations:
– Intersection, join, division, renaming: Not essential, but (very!)
useful.



68
Relational Algebra Operations
69
Example Instances
sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
sid bid day
22 101 10/10/96
58 103 11/12/96
R1
S1
S2
• Consider the following
instances R1, S1, S2.
70
Projection ( )
sname rating
yuppy 9
lubber 8
guppy 5
rusty 10
sname rating
S
,
( )2
age
35.0
55.5
age S( )2
• Deletes attributes that are not in projection list.
• Schema of result contains exactly the fields in the
projection list, with the same names that they had
in the (only) input relation.
• Projection operator has to eliminate duplicates!
(Why??)
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
S2
71
Selection (  )
rating
S
8
2( )
sid sname rating age
28 yuppy 9 35.0
58 rusty 10 35.0
sname rating
yuppy 9
rusty 10
 sname rating rating
S
,
( ( ))
8
2
• Selects rows that satisfy selection
condition.
• No duplicates in result! (Why?)
• Schema of result identical to
schema of (only) input relation.
• Result relation can be the input for
another relational algebra
operation! (Operator
composition.)
S2
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
72
Union, Intersection, Set-Difference
sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
44 guppy 5 35.0
28 yuppy 9 35.0
sid sname rating age
31 lubber 8 55.5
58 rusty 10 35.0
S S1 2
S S1 2
sid sname rating age
22 dustin 7 45.0
S S1 2
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
S2
sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
S1
73
Cross-Product ()
• S1  R1 : Each row of S1 is paired with each row of R1.
• Result schema has one field per field of S1 and R1, with field
names `inherited’ if possible.
– Conflict: Both S1 and R1 have a field called sid.
(sid) sname rating age (sid) bid day
22 dustin 7 45.0 22 101 10/10/96
22 dustin 7 45.0 58 103 11/12/96
31 lubber 8 55.5 22 101 10/10/96
31 lubber 8 55.5 58 103 11/12/96
58 rusty 10 35.0 22 101 10/10/96
58 rusty 10 35.0 58 103 11/12/96
sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
sid bid day
22 101 10/10/96
58 103 11/12/96
R1
S1
Comparison with SQL
Knowledge base system appl.  p 1,2-ver1
UnionChoice of rows
Choice of columns
Course Code: IS 463
Course Title:
Knowledge Base Systems Application
PART : 2
Prof. Taymoor Mohamed Nazmy
Dept. of computer science, faculty of computer science, Ain Shams uni.
Ex-vice dean of post graduate studies and research Cairo, Egypt
Relational calculus
Slide 6- 79
Relational Calculus
• Relational calculus is considered to be a
nonprocedural language.
• This differs from relational algebra, where we
must write a sequence of operations to specify
a retrieval request; hence relational algebra can
be considered as a procedural way of stating a
query.
Slide 6- 80
Relational Calculus
• A relational calculus expression creates a new
relation, which is specified in terms of variables
that range over rows of the stored database
relations (in tuple calculus) or over columns of
the stored relations (in domain calculus).
• In a calculus expression, there is no order of
operations to specify how to retrieve the query
result—a calculus expression specifies only what
information the result should contain.
– This is the main distinguishing feature between
relational algebra and relational calculus.
• In relational calculus user is not concerned with
the procedure to obtain the results, he/she just tell
his/her requirements and the output is available
without knowing the method about its retrieval.
• In relational calculus, a query is expressed as a
formula consisting of a number of variables and
an expression involving these variables. It is up to
the DBMS to transform these nonprocedural
queries into equivalent, efficient, procedural
queries.
Knowledge base system appl.  p 1,2-ver1
Instances of Branch and Staff
Relations
83
Tuple Relational Calculus - Example
• To find details of all staff earning more than
£10,000:
{S | Staff(S)  S.salary > 10000}
• To find a particular attribute, such as salary,
write:
{S.salary | Staff(S)  S.salary > 10000}
84
Domain Oriented Relational Calculus
• The domain calculus differs from the tuple calculus in the type of
variables used in formulas. In domain calculus the variables range
over single values from domains of attributes rather than ranging
over tuples. To form a relation of degree 'n' for a query result, we
must have 'n' of these domain variables-one for each attribute.
• An expression of the domain calculus is of the following form:
• {Xl, X2, ... , Xn I COND(XI, X2, .. ·, Xn, Xn+b Xn+2, , Xn+m)}
• In the above expression Xl, X2, ... , Xn, Xn+b Xn+2, , Xn+m
• are domain variables that range over domains of attributes and
COND is a condition or formula of the domain relational calculus.
Fundamentals of logic programming
PROLOG
• PROLOG or programming in logic.
• is a programming language that allows the programmer to specify
declarative statements only
– declarative statements (things you are declaring)
– once specified, the programmer then introduces questions to be
answered
• PROLOG uses resolution (backward chaining) and
unification to perform the problem solving automatically
– the intent was to provide a language that could accommodate
logic statements and has largely been used in AI but also to a
lesser extent as a database language or to solve database related
problems
Anatomy of a Program
• Prolog programs are made up of facts and rules.
• A fact asserts some property of an object, or relation between
two or more objects.
e.g. parent(jane,alan).
Can be read as “Jane is the parent of Alan.”
• Rules allow us to infer that a property or relationship holds
based on preconditions.
e.g. parent(X,Y) :- mother(X,Y).
= “Person X is the parent of person Y if X is mother of Y.
• Both facts and rules are predicate definitions.
• ‘Predicate’is the name given to the word occurring
before the bracket in a fact or rule:
parent(jane,alan).
• By defining a predicate you are specifying which
information needs to be known for the property
denoted by the predicate to be true.
Predicate Definitions
Predicate name
Clauses
• Predicate definitions may be fact or rule).
e.g. mother(jane,alan). = Fact
parent(P1,P2):- mother(P1,P2). = Rule
• A clause consists of a head
• and sometimes a body.
– Facts don’t have a body because they are always true.
head body
91
A clause Syntax
 A prolog rule is called a clause.
 A clause has a head, a neck and a body:
father(X,Y) :- parent(X,Y) , male(X) .
head neck body
 the head is a rule's conclusion.
 The body is a rule's premise or condition.
 note:
 read :- as IF
 read , as AND
 a . marks the end of input
Arguments
• A predicate head consists of a predicate name and sometimes
some arguments contained within brackets and separated by
commas.
mother(jane,alan).
• A body can be made up of any number of subgoals (calls to
other predicates) and terms.
• Arguments also consist of terms, which can be:
– Constants e.g. jane,
– Variables e.g. Person1, or
– Compound terms
Predicate name
Arguments
Complete Syntax of Terms
Term
Constant VariableCompound Term
Atom Number
alpha17
gross_pay
john_smith
dyspepsia
+
=/=
’12Q&A’
0
1
57
1.618
2.04e-27
-13.6
likes(john, mary)
book(dickens, Z, cricket)
f(x)
[1, 3, g(a), 7, 9]
-(+(15, 17), t)
15 + 17 - t
X
Gross_pay
Diagnosis
_257
_
Names an individual Stands for an individual
unable to be named when
program is written
Names an individual
that has parts
Structure of Programs
• Programs consist of procedures.
• Procedures consist of clauses.
• Each clause is a fact or a rule.
• Programs are executed by posing queries.
An example…
Example
elephant(george).
elephant(mary).
elephant(X) :- grey(X), mammal(X), hasTrunk(X).
Procedure for elephant
Predicate
Clauses
Rule
Facts
Example
?- elephant(george).
yes
?- elephant(jane).
no
Queries
Replies
Clauses: Facts and Rules
Head :- Body. This is a rule.
Head. This is a fact.
‘if’
‘provided that’
‘turnstile’
Full stop at the end.
Body of a (rule) clause contains goals.
likes(mary, X) :- human(X), honest(X).
Head Body
Goals
Exercise: Identify all the parts of Prolog
text you have seen so far.
99
Prolog knowledgebase (database)
father(X,Y) :- parent(X,Y),
male(X).
sibling(X,Y) :- ...
parent(adam,able)
parent(adam,cain)
male(adam)
...
Rules
Facts
• Questions based on facts
• Answered by matching
Two facts match if their predicates are same and the
arguments each are same.
• If matched, prolog answers yes, else no.
• No does not mean falsity.
Questions
• Fact
• likes(john,flowers)
Question:
?- likes(john,X)
Answer:
no
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
yes
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- woman(mia).
yes
?- playsAirGuitar(jody).
yes
?- playsAirGuitar(mia).
no
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
no
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- tattoed(jody).
ERROR: predicate tattoed/1 not defined.
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- party.
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- party.
yes
?-
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- rockConcert.
Knowledge Base 1
woman(mia).
woman(jody).
woman(yolanda).
playsAirGuitar(jody).
party.
?- rockConcert.
no
?-
© Patrick Blackburn, Johan
Bos & Kristina Striegnitz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
© Patrick Blackburn, Johan
Bos & Kristina Striegnitz
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
fact
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
fact
rule
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
fact
rule
rule
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
fact
fact
rule
rule
rule
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
head body
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?-
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?- playsAirGuitar(mia).
yes
?-
Knowledge Base 2
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
?- playsAirGuitar(mia).
yes
?- playsAirGuitar(yolanda).
yes
Clauses
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
There are five clauses in this knowledge base:
two facts, and three rules.
The end of a clause is marked with a full stop.
Predicates
happy(yolanda).
listens2music(mia).
listens2music(yolanda):- happy(yolanda).
playsAirGuitar(mia):- listens2music(mia).
playsAirGuitar(yolanda):- listens2music(yolanda).
There are three predicates
in this knowledge base:
happy, listens2music, and playsAirGuitar
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
Expressing Conjunction
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
The comma “," expresses conjunction in Prolog
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
?- playsAirGuitar(vincent).
no
?-
Knowledge Base 3
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
?- playsAirGuitar(butch).
yes
?-
Expressing Disjunction
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch).
playsAirGuitar(butch):- listens2music(butch).
happy(vincent).
listens2music(butch).
playsAirGuitar(vincent):- listens2music(vincent), happy(vincent).
playsAirGuitar(butch):- happy(butch); listens2music(butch).
Knowledge Base 4
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
Prolog Variables
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
Variable Instantiation
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
X=mia
Asking Alternatives
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
Asking Alternatives
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody
Asking Alternatives
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody;
X=yolanda
Asking Alternatives
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- woman(X).
X=mia;
X=jody;
X=yolanda;
no
Knowledge Base 4
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- loves(marsellus,X), woman(X).
Knowledge Base 4
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- loves(marsellus,X), woman(X).
X=mia
yes
?-
Knowledge Base 4
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- loves(pumpkin,X), woman(X).
Knowledge Base 4
woman(mia).
woman(jody).
woman(yolanda).
loves(vincent, mia).
loves(marsellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
?- loves(pumpkin,X), woman(X).
no
?-
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
?- jealous(marsellus,W).
Knowledge Base 5
loves(vincent,mia).
loves(marsellus,mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X,Y):- loves(X,Z), loves(Y,Z).
?- jealous(marsellus,W).
W=vincent
?-
Logic for knowledge representation
148
Introduction
• Real knowledge representation and reasoning systems
come in several major varieties.
• These differ in their intended use, expressivity, features,…
• Some major families are
– Logic programming languages
– Theorem provers
– Rule-based or production systems
– Semantic networks
– Frame-based representation languages
– Databases (deductive, relational, object-oriented, etc.)
– Constraint reasoning systems
– Description logics
– Bayesian networks
– Evidential reasoning
Knowledge Representation Schemas
Real knowledge representation and reasoning systems come in several major
varieties. They all based on FOL but departing from it in different ways.
Logic based representation – first order predicate
logic, Prolog
Procedural representation – rules, production system
Network representation – semantic networks,
conceptual graphs
Structural representation – scripts, frames, objects
Production Systems
Widely used in expert systems (Production Systems)
System has:
Rule Base
Working Memory
Inference Mechanism (Interpreter)
Explanation Facility
Rule Base
Stores permanent (problem-independent) knowledge.
This knowledge is stored as production rules/condition-action
rules.
E.g.
IF condition-1
AND condition-2
AND …
AND condition-m
THEN action-1
AND action-2
AND …
AND action-n
The IF-part is also called the left-hand side or
antecedent.
The THEN-part is also called the right-hand side or
consequent.
The actions in the consequent usually involve
changes to working memory.
e.g. adding, deleting or modifying working memory
elements.
153
What are Rules?
• Rules represent knowledge using IF-THEN format
• The IF portion of a rule is a condition, (also called a
premise or an antecedent), which tests the truth value
of set of facts.
• If these are found true, the THEN portion of a rule
(also called the action, the conclusion or the
consequent) is inferred as a new set of facts.
154
Production Systems
and the Rules
• The rule based systems are also called production systems.
• Simon and Newel developed the production system to model
human problem solving.
• A production system consists of:
– An area of memory that is used to track the current state of the
universe under consideration (working memory - database).
– A set of production rules :condition - action pairs (knowledge base).
– An interpreter (inference engine) recognizes and executes a
production whose conditions has been satisfied. This control may be
either data driven or goal driven.
155
Rule-based Inference
• Using search techniques and pattern matching, rule
based systems automate reasoning methods and
provide the logical progression from initial data to the
desired conclusion.
• Thus the process of problem solving in knowledge
based systems is to create a series of inferences that
create a “path” between the problem definition and
the solution
• This series of inferences is progressive in nature and
is called an inference chain.
156
Example
• Suppose we are building a knowledge based
system for forecasting the weather over the
next 12 – 24 hours in Florida during the
summer.
RULE 1: IF the ambient temperature is above 900
F
THEN the weather is hot.
RULE 2: IF the relative humidity is greater than 65%
THEN the atmosphere is humid
RULE 3: IF the weather is hot and the atmosphere is humid
THEN thunderstorms are likely to develop.
157
Knowledge Representation scheme:
Rules
• Rules
• These are formalization often used to specify recommendations, give
directives or strategy.
• Format: IF <premises> THEN <conclusion>.
• Related ideas: rules and fact base; conflict set - source of rules;
conflict resolution- deciding on rules to apply.
– Advantages: easy to use; explanations are possible; capture
heuristics; can handle uncertainties to some extent.
– Disadvantages: cannot cope with complex associated knowledge;
they can grow to unmanageable size.
158
Knowledge Representation scheme:
Rules
Consists of:
• a rule set for representing the expert knowledge
• a “database management system” for the case-specific facts
• a rule interpreter for problem solving
Example
IF: (1) stain of organism is Gram neg. AND
(2) morphology of organism is rod AND
(3) aerobicity of organism is aerobic
THEN: strong evidence (0.8) that organism is Enterobact
Properties of rule-based systems:
 modularity of rule, very expressive, easy hadling of certainty factors
(probabilistic, possibilitic reasoning)
 Lack of precise semantics of rules. Not always efficient
159
Rules - A simple example
• Assume: Knowledge base consisting of facts and rules, a rule
interpreter to match the rule conditions against facts and means for
executing the rules.
Rules:
R1: IF: Raining,Outside(x),Has_Umbrella(x)
THEN: Uses_Umbrella(x)
R2: IF: Raining,Outside(x)
NOT Has_Umbrella(x)
THEN: Wet(x)
R3: IF: Wet(x)
THEN: Gets_Cold(x)
R4: IF: Sunny,Outside(x)
THEN: Gets_Sun_Tan(x)
Initial facts: Raining, Outside(John)
160
Rules - A simple example
Correct:
• Only one rule, R2 matches the facts with [xJohn], hence add
Wet(John)
• Facts after first cycle:
Raining, Outside(John), Wet(John)
• Now R3 matches facts, hence add
Gets_Cold(John)
• Facts after second cycle:
Raining, Outside(John), Wet(John), Gets_Cold(John)
Process of deriving new facts from given facts, is called INFERENCE
Incorrect:
Gets_Sun_Tan(John)
Inference Methods 1
deduction
◆ conclusions must follow from their premises; prototype of logical reasoning
induction
◆ inference from specific cases (examples) to the general
abduction
◆ reasoning from a true conclusion to premises that may have caused the conclusion
resolution
◆ find two clauses with complementary literals, and combine them
generate and test
◆ a tentative solution is generated and tested for validity
◆ often used for efficiency (trial and error)
1
6
1
Inference Methods 2
default reasoning
◆ general or common knowledge is assumed in the absence of specific
knowledge
analogy
◆ a conclusion is drawn based on similarities to another situation
heuristics
◆ rules of thumb based on experience
intuition
◆ typically human reasoning method
nonmonotonic reasoning
◆ new evidence may invalidate previous knowledge
auto epistemic
◆ reasoning about your own knowledge
1
6
2

More Related Content

PDF
Lecture: Semantic Word Clouds
PDF
Lecture 2: Computational Semantics
PDF
Information Extraction
PPTX
Artificial Intelligence Notes Unit 4
PDF
Natural Language Processing: L01 introduction
PPT
The impact of standardized terminologies and domain-ontologies in multilingua...
PDF
Lec 3 knowledge acquisition representation and inference
PDF
NLP & Machine Learning - An Introductory Talk
Lecture: Semantic Word Clouds
Lecture 2: Computational Semantics
Information Extraction
Artificial Intelligence Notes Unit 4
Natural Language Processing: L01 introduction
The impact of standardized terminologies and domain-ontologies in multilingua...
Lec 3 knowledge acquisition representation and inference
NLP & Machine Learning - An Introductory Talk

What's hot (20)

PDF
Nlp presentation
PDF
Natural Language Processing, Techniques, Current Trends and Applications in I...
PPT
Artificial Intelligence
PDF
Sentiment Analysis
PDF
Natural Language Processing
PDF
Word representation: SVD, LSA, Word2Vec
PDF
Natural Language Processing Crash Course
PDF
Engineering Intelligent NLP Applications Using Deep Learning – Part 2
PDF
Natural Language Processing (NLP)
PPTX
Frames
PPT
Knowledge Representation in Artificial intelligence
PPTX
natural language processing help at myassignmenthelp.net
PPTX
Structured Knowledge Representation
PDF
Ontologies
PDF
UCU NLP Summer Workshops 2017 - Part 2
PDF
Relation Extraction
PPT
Knowledge Representation & Reasoning
PDF
Machine Learning in NLP
PDF
Engineering Intelligent NLP Applications Using Deep Learning – Part 1
PPTX
Knowledge representation
Nlp presentation
Natural Language Processing, Techniques, Current Trends and Applications in I...
Artificial Intelligence
Sentiment Analysis
Natural Language Processing
Word representation: SVD, LSA, Word2Vec
Natural Language Processing Crash Course
Engineering Intelligent NLP Applications Using Deep Learning – Part 2
Natural Language Processing (NLP)
Frames
Knowledge Representation in Artificial intelligence
natural language processing help at myassignmenthelp.net
Structured Knowledge Representation
Ontologies
UCU NLP Summer Workshops 2017 - Part 2
Relation Extraction
Knowledge Representation & Reasoning
Machine Learning in NLP
Engineering Intelligent NLP Applications Using Deep Learning – Part 1
Knowledge representation
Ad

Similar to Knowledge base system appl. p 1,2-ver1 (20)

PPTX
AI_Unit-3 complete Notes.pptx from RAJIV GANDHI UNIVERSITY
PPTX
Teaching LMMs for Image Quality Scoring and Interpreting
PPT
Artificial Intelligence by B. Ravikumar
PPT
n01.ppt
PPTX
Applied Artificial Intelligence Unit 1 Semester 3 MSc IT Part 2 Mumbai Univer...
PDF
Knowledge Representatiodhdhhdhdn.pptx.pdf
PPTX
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
PPTX
module-2 ppt knowledge representation computer application
PPTX
Networking chapter jkl; dfghyubLec 1.pptx
PDF
ARTIFICIAL INTELLIGENCE_21CS3002.pdf pppt
PPTX
Topic Pages. From articles to answers.
PPTX
Introduction to Text Mining
PPTX
AI material for you computer science.pptx
PPTX
MODULE-2_AI_Computer_Science_Engineering.pptx
PPTX
NLP, Expert system and pattern recognition
PDF
Machine learning with in the python lecture for computer science
PPT
6 KBS_ES.ppt
PPTX
Multimodal Learning Analytics
PPTX
Multimodal Learning Analytics
PDF
Introaied nancy2019 luengo
AI_Unit-3 complete Notes.pptx from RAJIV GANDHI UNIVERSITY
Teaching LMMs for Image Quality Scoring and Interpreting
Artificial Intelligence by B. Ravikumar
n01.ppt
Applied Artificial Intelligence Unit 1 Semester 3 MSc IT Part 2 Mumbai Univer...
Knowledge Representatiodhdhhdhdn.pptx.pdf
ARTIFICIAL INTELLIGENCE---UNIT 4.pptx
module-2 ppt knowledge representation computer application
Networking chapter jkl; dfghyubLec 1.pptx
ARTIFICIAL INTELLIGENCE_21CS3002.pdf pppt
Topic Pages. From articles to answers.
Introduction to Text Mining
AI material for you computer science.pptx
MODULE-2_AI_Computer_Science_Engineering.pptx
NLP, Expert system and pattern recognition
Machine learning with in the python lecture for computer science
6 KBS_ES.ppt
Multimodal Learning Analytics
Multimodal Learning Analytics
Introaied nancy2019 luengo
Ad

More from Taymoor Nazmy (20)

PPTX
Cognitive systems
PPTX
Cognitive systems
PPT
Artificial intelligent Lec 5-logic
PPT
Artificial intelligent Lec 3-ai chapter3-search
PPT
Lec 2-agents
PPT
Artificial intelligent Lec 1-ai-introduction-
PPTX
Image processing 2
PPT
Image processing 1-lectures
PPT
Software Engineering Lec 10 -software testing--
PPT
Software Engineering Lec 8-design-
PPT
Software Engineering Lec 7-uml-
PPT
Software Engineering Lec5 oop-uml-i
PPT
Software Engineering Lec 4-requirments
PPT
Software Engineering Lec 3-project managment
PPT
Software Engineering Lec 2
PPT
Software Engineering Lec 1-introduction
PPT
PPT
presentation skill
PPT
PPT
Cognitive systems
Cognitive systems
Artificial intelligent Lec 5-logic
Artificial intelligent Lec 3-ai chapter3-search
Lec 2-agents
Artificial intelligent Lec 1-ai-introduction-
Image processing 2
Image processing 1-lectures
Software Engineering Lec 10 -software testing--
Software Engineering Lec 8-design-
Software Engineering Lec 7-uml-
Software Engineering Lec5 oop-uml-i
Software Engineering Lec 4-requirments
Software Engineering Lec 3-project managment
Software Engineering Lec 2
Software Engineering Lec 1-introduction
presentation skill

Recently uploaded (20)

PPTX
20th Century Theater, Methods, History.pptx
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
What if we spent less time fighting change, and more time building what’s rig...
PDF
advance database management system book.pdf
PDF
Trump Administration's workforce development strategy
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PDF
Empowerment Technology for Senior High School Guide
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
20th Century Theater, Methods, History.pptx
Weekly quiz Compilation Jan -July 25.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
What if we spent less time fighting change, and more time building what’s rig...
advance database management system book.pdf
Trump Administration's workforce development strategy
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Chinmaya Tiranga quiz Grand Finale.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
History, Philosophy and sociology of education (1).pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
B.Sc. DS Unit 2 Software Engineering.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Share_Module_2_Power_conflict_and_negotiation.pptx
Empowerment Technology for Senior High School Guide
Paper A Mock Exam 9_ Attempt review.pdf.
ChatGPT for Dummies - Pam Baker Ccesa007.pdf

Knowledge base system appl. p 1,2-ver1

  • 1. Course Code: IS 463 Course Title: Knowledge Base Systems Application PART : 1 Prof. Taymoor Mohamed Nazmy Dept. of computer science, faculty of computer science, Ain Shams uni. Ex-vice dean of post graduate studies and research Cairo, Egypt
  • 2. Course Description • Introduction. • Review of first-order logic, relational algebra, and relational calculus. • Fundamentals of logic programming. Logic for knowledge representation. Architecture of knowledge-base system. Fundamentals of deductive databases. Top-down and bottom- up query processing. Some important query processing strategies and their comparison. Project or term paper on current research topics. • Textbook: • Richard A. Frost, Introduction to Knowledge Based Systems.
  • 3. About the lecturer - Prof. of computer science since 2006, - Director of Ain Shams information network, - Vice dean of post graduate studies and research, - Vice dean of environmental and social affairs, - Member in editorial board of many Int. journals, - Member in Scientific committee of many int. conferences - Executive chair of int. conf. on information and intelligent systems, - Published more than 60 scientific papers in int. journals and conference, -Supervised more than 20 master and Ph. D thesis.
  • 4. About the course • The materials of this course were collected from many resources, include the reference book, other books, online courses, presentations, and web sites. • There are many details will be given to simplify topics in this course, however at the end of the course the most important topics will be highlighted. • The delivered materials through this presentation is your main resource, • This presentation will be delivered to you, through one ways, such as drop box, the course consist of 4 parts, we will starts with Part 1,2, then continue with Part 3,4. • There will be term exams 40% • The attendance and term paper 20% • The final exam 40% • The exam will include subjective and objective questions, • Through this course try to extends your knowledge by improving your self learning capabilities.
  • 5. The lecture link • https://www.dropbox.com/s/9ee1j8jxj8jep8e/ Knowledge%20base%20system%20appl.- %20P%201%2C2-ver1.pptx?dl=0 • Ntaymoor19600@gmail.com
  • 6. Term paper • Each 3-4 students have to prepare a report (20-30 page), to be delivered before the end of the term in one of the following topics: • Big data analytics, • Types of query languages, • Expert systems, • Web SQL Database, • Query processing, • Open topic.
  • 10. Cognitive sensors and networks Cognitive information fusion Cognitive robots Cognitive agent technologies Cognitive machine learning Cognitive semantics Cognitive mobile systems Cognitive signal processing Cognitive mobile systems Cognitive vehicle communication Cognitive knowledge representation DNA and genome cognition Cognitive image processing Cognitive space communication Cognitive agent technologies Cognitive decision theories Cognitive learning engines Cognitive inference engines Big data cognition Cognitive informatics Cognitive computer vision
  • 11. KR and human brain • Human brain can be considered as a huge knowledge base system. Human can represent his knowledge by natural language, sign language, Rhythms, painting, etc. • Human brain can process the represented knowledge with many complex fast methods called cognitive processes. • Do you know that each human cell is it self a storage for knowledgebase, how? • Some of those method where simplified to be used by computer, as we will see later.
  • 13. KR and artificial cognitive systems • In the last few years, a big progress was achieved towards having a machine that can understand directly human language, self learning, and compete with human to answer difficult questions. • This machine is called IBM WATSON, it represents the new era of computing to have what is called artificial cognitive systems. Most of computer science disciplines will turned towards this system.
  • 14. A semantic network to represent the relation among different topics related to knowledgebase
  • 15. Definitions • Knowledge: among other things, knowledge is a relation between a knower and a proposition – knower : John – proposition: the idea expressed by a simple declarative sentence, like “Mary will come to the party.” – Knowledge representation, then, is the field of study concerned with using formal symbols to represent a collection of propositions. – Reasoning: it is the formal manipulation of the symbols representing a collection of believed propositions to produce representations of new ones. – Reasoning is a form of calculation, not unlike arithmetic, but over symbols standing for propositions rather than numbers
  • 16. Artificial Intelligence and Knowledge Representation  A description of Artificial Intelligence is:   The study and development of systems that demonstrate intelligent behavior  Based on the above, a description of Knowledge Representation & Reasoning is:  The study of ways to represent and reason with information in order to achieve intelligent behavior
  • 17. 17 Main questions How we can represent knowledge as symbol structures ? How we can use that knowledge to intelligently solve problems ?
  • 18. Sources of Knowledge • The main source of knowledge is the human and his knowledge can be: • documented – books, journals, procedures – films, databases • undocumented – people’s knowledge, explicit and tacit.
  • 19. Types Knowledge Type of Knowledge Examples Facts dogs, teeth, house Relations mother of Paul Rules If it is cloudy then It will rain Concepts For all X & Y Procedures Do this then that
  • 21. Levels of Knowledge • Shallow level: – very specific to a situation Limited by IF-THEN type rules. Rules have little meaning. No explanation. • Deep Knowledge: – problem solving. Internal causal structure. Built from a range of inputs – emotions, common sense, – difficult to build into a system.
  • 22. A knowledge-based system • A knowledge-based system (KBS) is a computer program that can represents the knowledge and reasons to solve complex problems. • A knowledge based system has two types of sub-systems: a knowledge base and an inference engine. • The knowledge base represents facts about the world using knowledge representation (KR) methods. The inference engine represents logical assertions and conditions about the world, usually represented via IF- THEN rules. • Knowledge-based systems were first developed by artificial intelligence researchers. These early knowledge-based systems were primarily expert systems – in fact, the term is often used synonymously with expert systems.
  • 24. Knowledge Representation A subarea of Artificial Intelligence concerned with understanding, designing, and implementing ways of representing information (knowledge) in computers so that programs (agents) can use this information… • to derive new information that is implied by it, (inference, and reasoning), • to converse with people in natural languages, • to decide what to do next • to plan future activities, • to solve problems in areas that normally require human expertise.
  • 25. How can knowledge be represented ?  Symbolic methods  Declarative Languages (Logic)  Declarative programing means style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow. Where Algorithm = Logic + Control.  Imperative Languages (C, C++, Java, etc.),  Imperative programing means programming paradigm that uses statements that change a program's state.  Hybrid Languages (Prolog)  Rules  Frames  Semantic Networks …  Non – symbolic methods  Neural Networks  Genetic Algorithms
  • 28. What language should we use? • Natural language, ie English, ASL, Cantonese. Too ambiguous. • Programming Language, ie C++, Lisp, Java. Not very expressive. We will use logic! Actually there are many different logics. We will start by considering •Propositional Logic. We will find that has some drawbacks so we will consider the more general •Predicate Logic. This too, has limitations, so we will consider the more general •First-Order Logic. •Predicate logic • (occasionally referred to as • First-order logic (FOL)) Propositional Logic Predicate Logic First-Order Logic
  • 29. Logic for KR • Logic is a great knowledge representation language for many AI problems • Propositional logic is the simple foundation and fine for some AI problems • First order logic (FOL), is also known Predicate calculus is much more expressive as a KR language and more commonly used in AI • There are many variations of logics such as: horn logic, higher order logic, three-valued logic, probabilistic logics, etc.
  • 30. Simple Propositions and Compound Propositions • Fast foods tend to be unhealthy. • Parakeets are colorful birds. • More complex proposition such as: • If fast foods tend to be unhealthy, then you shouldn’t eat them. • Parakeets are colorful birds, and colorful birds are good to have at home.
  • 31. Basic connectives and truth tables primitive and compound statements can be represented by logical connectives, such as: p p, (a) conjunction (AND): (b) disjunction(inclusive OR): (c) exclusive or: (d) implication: (if p then q) (e) biconditional: (p if and only if q, or p iff q) (f) negation ( ) p q p q p q p q p q
  • 32. 32 Truth tables  Logic, like arithmetic, has operators, which apply to one, two, or more values (operands)  A truth table lists the results for each possible arrangement of operands  The rows in a truth table list all possible sequences of truth values for n operands, and specify a result for each sequence  Hence, there are 2n rows in a truth table for n operands
  • 33. Truth tables for logical connectives TTFFTFF FTTFTTF FFTFFFT TTTTFTT ~ QPQPQPQPPQP  Or p q p q p q p q p qp q 0 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 0 1 1 0 0 1 1 1 1 0 1 1
  • 34. The simplest example Suppose our KB consists of P Q R A simple goal is … Q. Literally we are asking is it the case that Q is true. In this case, the answer is yes!
  • 35. Another simple example Suppose our KB consists of P Q R Now suppose the goal is … P  Q. We are literally asking is it the case that P is true and Q is true. In this case, the fact P  Q is not in our KB. But we can infer it by using the And rule.
  • 36. 36 Example formula and truth-table (p  q)  r p q r q p  q (p  q)  r T T T F T T T T F F T F T F T T T T T F F T T F F T T F F T F T F F F T F F T T T T F F F T T F
  • 37. Truth tables II A complex sentence: (p H) DH)  P
  • 38. 38 Logical expressions • All logical expressions can be computed with some combination of and (), or (), and not () operators • For example, logical implication can be computed this way: • Notice that X  Y is equivalent to X  Y X Y X X  Y X  Y T T F T T T F F F F F T T T T F F T T T
  • 39. 39 Another example • Exclusive or (xor) is true if exactly one of its operands is true • Notice that (XY)(XY) is equivalent to X xor Y X Y X Y X  Y X  Y (XY)(XY) X xor Y T T F F F F F F T F F T F T T T F T T F T F T T F F T T F F F F
  • 40. How to built Propositional logic sentences • User defines set of propositional symbols, like P and Q • User defines semantics of each propositional symbol: – P means “It is hot”, Q means “It is humid”, etc. • A sentence (well formed formula) is defined as follows: – A symbol is a sentence – If S is a sentence, then S is a sentence – If S is a sentence, then (S) is a sentence – If S and T are sentences, then (S  T), (S  T), (S  T), and (S ↔ T) are sentences
  • 41. Examples of PL sentences • P means “It is hot.” • Q means “It is humid.” • R means “It is raining.” • Q  P “If it is humid, then it is hot” • (P  Q)  R “If it is hot and humid, then it is raining”
  • 42. Example  B means Mihai has money  A means The car is white  F means The car is nice  C means Mihai goes to the mountain  If the car is white or the car is nice and Mihai has money then Mihai goes to the mountain  (A  F)  B  C
  • 43. Example s: Phyllis goes out for a walk. t: The moon is out. u: It is snowing. ( )t u s   : If the moon is out and it is not snowing, then Phyllis goes out for a walk. If it is snowing and the moon is not out, then Phyllis will not go out for a walk. ( )u t s   
  • 44. Tautologies A sentence is a tautology if it is true for any setting of its propositional symbols (P OR Q) OR (NOT(P) AND NOT(Q)) is a tautology
  • 45. Is this a tautology? • (P => Q) OR (Q => P) • Try it.
  • 46. 46 Inference rules in propositional logic • (a OR b) ≡ (b OR a) commutatitvity • (a AND b) ≡ (b AND a) commutatitvity • ((a AND b) AND c) ≡ (a AND (b AND c)) associativity • ((a OR b) OR c) ≡ (a OR (b OR c)) associativity • NOT(NOT(a)) ≡ a double-negation elimination • (a => b) ≡ (NOT(b) => NOT(a)) contraposition • (a => b) ≡ (NOT(a) OR b) implication elimination • NOT(a AND b) ≡ (NOT(a) OR NOT(b)) De Morgan • NOT(a OR b) ≡ (NOT(a) AND NOT(b)) De Morgan • (a AND (b OR c)) ≡ ((a AND b) OR (a AND c)) distributitivity • (a OR (b AND c)) ≡ ((a OR b) AND (a OR c)) distributitivity
  • 47. Question • Use propositional formulas to represents the sentence, 'He will come on the 8:15 or the 9:15 train; if he will have time to visit us', • where p means 'He will come on the 8:15' q means 'He will come on the 9:15' r means 'He will have time to visit us'
  • 49. 49 Limitations of Propositional Logic p represents ‘My car is red’ q represents ‘This pen is red’ r represents ‘The planet Mars is red’ Cannot work with lower-level objects like ‘my car’, ‘this pen’, ‘the planet Mars’ For most practical applications, we need to be able to talk about objects and properties within our logical system
  • 50. 50 Components of First-Order Logic • Term – Constant, e.g. Red – Function of constant, e.g. Color(Block1) • Atomic Sentence – Predicate relating objects (no variable) • Brother (John, Richard) • Married (Mother(John), Father(John)) • Complex Sentences – Atomic sentences + logical connectives • Brother (John, Richard) Brother (John, Father(John))
  • 51. Atomic Sentences • Atomic sentences state facts using terms and predicate symbols – P(x,y) interpreted as “x is P of y” • Examples: LargerThan(2,3) is false. Brother_of(Mary,Pete) is false. Married(Father(Richard), Mother(John)) could be true or false
  • 52. Function Function (evaluates to a constant / variable): Maps Sentences to Objects Ali is father of Babar father_of(ali) = baber father(babar) = ali Babar is son of Ali son_of(babar) = ali • Interpretation has to be very clear. • If you write father(baber), the answer should be ali • For the above functions the arity is 1 (number of arguments to the function)
  • 53. Function-II Functions: 1) shahid likes zahid likes(shahid) = zahid 2) atif likes abid likes(atif) = abid 3)Constants to Variables likes(X) = Y {X,Y} have two possible BINDINGS {X, Y} could be {shahid, zahid} Or {X,Y} could be {atif, abid} likes(X) =Y Substitutions: For 1 to be true: {shahid/X, zahid/Y} For 2 to be true: {atif/X, abid/Y}
  • 54. Predicate Predicate Maps Sentences to Truth Values (True/False) 1) Shahid is student student(shahid) 2) Sana is a girl girl(sana) 3) Father of baber is elder than Hamza elder(father(babar), hamza) For 1 and 2 arity is 1 and for 3 the arity is 2
  • 55. Predicate-II Predicate 1) Shahid is a good student student(shahid,good) or good_student(shahid) or is_good(shahid,student) 2) Sana is a friend of Saima, Sana and Saima both are girls friend_of(sana,saima)^girl(sana)^girl(saima) 3) Bill helps Fred helps(bill,fred)
  • 56. FOL Provides • Variable symbols – E.g., x, y, foo • Connectives – Same as in PL: not (), and (), or (), implies (), if and only if (biconditional ) • Quantifiers – Universal x or (Ax) – Existential x or (Ex)
  • 57. 57 Components of First-Order Logic • Quantifiers – Each quantifier defines a variable for the duration of the following expression, and indicates the truth of the expression… • Universal quantifier “for all”  – The expression is true for every possible value of the variable • Existential quantifier “there exists”  – The expression is true for at least one value of the variable
  • 58. Quantification of Two Variables (read left to right) xyP(x,y) or yxP(x,y) •True when P(x,y) is true for every pair x,y. •False if there is a pair x,y for which P(x,y) is false. xyP(x,y) or yxP(x,y) True if there is a pair x,y for which P(x,y) is true. False if P(x,y) is false for every pair x,y.
  • 59. Quantification of Two Variables xyP(x,y) •True when for every x there is a y for which P(x,y) is true. (in this case y can depend on x) •False if there is an x such that P(x,y) is false for every y. yxP(x,y) •True if there is a y for which P(x,y) is true for every x. (i.e., true for a particular y regardless (or independent) of x) •False if for every y there is an x for which P(x,y) is false. Note that order matters here In particular, if yxP(x,y) is true, then xyP(x,y) is true. However, if xyP(x,y) is true, it is not necessary that yxP(x,y) is true.
  • 60. 60 Properties of Quantifiers • x y is the same as y x • x y is the same as y x • x y is not the same as y x – x y Loves(x, y) • “There is a person who loves everyone in the world” – y x Loves(x, y) • “Everyone in the world is loved by at least one person”
  • 62. 62 Formal Relational Query Languages Two mathematical Query Languages form the basis for “real” languages (e.g. SQL), and for implementation: • Relational Algebra: More operational, very useful for representing execution plans. • Relational Calculus: Lets users describe what they want, rather than how to compute it. (Non-operational, declarative.)  Understanding Algebra & Calculus is key to  understanding SQL, query processing!
  • 63. Relational Algebra • Relational Algebra is a procedural language that can be used to tell the DBMS ( Data Base Management System) how to build a new relation from one or more relations in the database.
  • 64. 64 Relational Database: Definitions Relational database: a set of relations Relation: made up of 2 parts: – Instance : a table, with rows and columns. #Rows = cardinality, #fields = degree (arity). – Schema : specifies name of relation, plus name and type of each column. • e.g. Students(sid: string, name: string, login: string, age: integer, gpa: real). We can think of a relation as a set of rows or tuples (i.e., all rows are distinct).
  • 65. 65 Example Instance of Students Relation sid name login age gpa 53666 Jones jones@cs 18 3.4 53688 Smith smith@eecs 18 3.2 53650 Smith smith@math 19 3.8  Cardinality = 3, degree = 5, all rows distinct  Do all columns in a relation instance have to be distinct?
  • 66. Relation Instance • The current values (relation instance) of a relation are specified by a table • An element t of r is a tuple, represented by a row in a table Jones Smith Curry Lindsay customer-name Main North North Park customer-street Harrison Rye Rye Pittsfield customer-city customer attributes (or columns) tuples (or rows)
  • 67. 67 Relational Algebra • Basic operations: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Select a subset of columns from relation. – Cross-product (  ) Allows us to combine two relations. – Set-difference ( ) Tuples in reln. 1, but not in reln. 2. – Union (  ) Tuples in reln. 1 and in reln. 2. • Additional operations: – Intersection, join, division, renaming: Not essential, but (very!) useful.   
  • 69. 69 Example Instances sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 sid sname rating age 28 yuppy 9 35.0 31 lubber 8 55.5 44 guppy 5 35.0 58 rusty 10 35.0 sid bid day 22 101 10/10/96 58 103 11/12/96 R1 S1 S2 • Consider the following instances R1, S1, S2.
  • 70. 70 Projection ( ) sname rating yuppy 9 lubber 8 guppy 5 rusty 10 sname rating S , ( )2 age 35.0 55.5 age S( )2 • Deletes attributes that are not in projection list. • Schema of result contains exactly the fields in the projection list, with the same names that they had in the (only) input relation. • Projection operator has to eliminate duplicates! (Why??) sid sname rating age 28 yuppy 9 35.0 31 lubber 8 55.5 44 guppy 5 35.0 58 rusty 10 35.0 S2
  • 71. 71 Selection (  ) rating S 8 2( ) sid sname rating age 28 yuppy 9 35.0 58 rusty 10 35.0 sname rating yuppy 9 rusty 10  sname rating rating S , ( ( )) 8 2 • Selects rows that satisfy selection condition. • No duplicates in result! (Why?) • Schema of result identical to schema of (only) input relation. • Result relation can be the input for another relational algebra operation! (Operator composition.) S2 sid sname rating age 28 yuppy 9 35.0 31 lubber 8 55.5 44 guppy 5 35.0 58 rusty 10 35.0
  • 72. 72 Union, Intersection, Set-Difference sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 44 guppy 5 35.0 28 yuppy 9 35.0 sid sname rating age 31 lubber 8 55.5 58 rusty 10 35.0 S S1 2 S S1 2 sid sname rating age 22 dustin 7 45.0 S S1 2 sid sname rating age 28 yuppy 9 35.0 31 lubber 8 55.5 44 guppy 5 35.0 58 rusty 10 35.0 S2 sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 S1
  • 73. 73 Cross-Product () • S1  R1 : Each row of S1 is paired with each row of R1. • Result schema has one field per field of S1 and R1, with field names `inherited’ if possible. – Conflict: Both S1 and R1 have a field called sid. (sid) sname rating age (sid) bid day 22 dustin 7 45.0 22 101 10/10/96 22 dustin 7 45.0 58 103 11/12/96 31 lubber 8 55.5 22 101 10/10/96 31 lubber 8 55.5 58 103 11/12/96 58 rusty 10 35.0 22 101 10/10/96 58 rusty 10 35.0 58 103 11/12/96 sid sname rating age 22 dustin 7 45.0 31 lubber 8 55.5 58 rusty 10 35.0 sid bid day 22 101 10/10/96 58 103 11/12/96 R1 S1
  • 77. Course Code: IS 463 Course Title: Knowledge Base Systems Application PART : 2 Prof. Taymoor Mohamed Nazmy Dept. of computer science, faculty of computer science, Ain Shams uni. Ex-vice dean of post graduate studies and research Cairo, Egypt
  • 79. Slide 6- 79 Relational Calculus • Relational calculus is considered to be a nonprocedural language. • This differs from relational algebra, where we must write a sequence of operations to specify a retrieval request; hence relational algebra can be considered as a procedural way of stating a query.
  • 80. Slide 6- 80 Relational Calculus • A relational calculus expression creates a new relation, which is specified in terms of variables that range over rows of the stored database relations (in tuple calculus) or over columns of the stored relations (in domain calculus). • In a calculus expression, there is no order of operations to specify how to retrieve the query result—a calculus expression specifies only what information the result should contain. – This is the main distinguishing feature between relational algebra and relational calculus.
  • 81. • In relational calculus user is not concerned with the procedure to obtain the results, he/she just tell his/her requirements and the output is available without knowing the method about its retrieval. • In relational calculus, a query is expressed as a formula consisting of a number of variables and an expression involving these variables. It is up to the DBMS to transform these nonprocedural queries into equivalent, efficient, procedural queries.
  • 83. Instances of Branch and Staff Relations 83
  • 84. Tuple Relational Calculus - Example • To find details of all staff earning more than £10,000: {S | Staff(S)  S.salary > 10000} • To find a particular attribute, such as salary, write: {S.salary | Staff(S)  S.salary > 10000} 84
  • 85. Domain Oriented Relational Calculus • The domain calculus differs from the tuple calculus in the type of variables used in formulas. In domain calculus the variables range over single values from domains of attributes rather than ranging over tuples. To form a relation of degree 'n' for a query result, we must have 'n' of these domain variables-one for each attribute. • An expression of the domain calculus is of the following form: • {Xl, X2, ... , Xn I COND(XI, X2, .. ·, Xn, Xn+b Xn+2, , Xn+m)} • In the above expression Xl, X2, ... , Xn, Xn+b Xn+2, , Xn+m • are domain variables that range over domains of attributes and COND is a condition or formula of the domain relational calculus.
  • 86. Fundamentals of logic programming
  • 87. PROLOG • PROLOG or programming in logic. • is a programming language that allows the programmer to specify declarative statements only – declarative statements (things you are declaring) – once specified, the programmer then introduces questions to be answered • PROLOG uses resolution (backward chaining) and unification to perform the problem solving automatically – the intent was to provide a language that could accommodate logic statements and has largely been used in AI but also to a lesser extent as a database language or to solve database related problems
  • 88. Anatomy of a Program • Prolog programs are made up of facts and rules. • A fact asserts some property of an object, or relation between two or more objects. e.g. parent(jane,alan). Can be read as “Jane is the parent of Alan.” • Rules allow us to infer that a property or relationship holds based on preconditions. e.g. parent(X,Y) :- mother(X,Y). = “Person X is the parent of person Y if X is mother of Y.
  • 89. • Both facts and rules are predicate definitions. • ‘Predicate’is the name given to the word occurring before the bracket in a fact or rule: parent(jane,alan). • By defining a predicate you are specifying which information needs to be known for the property denoted by the predicate to be true. Predicate Definitions Predicate name
  • 90. Clauses • Predicate definitions may be fact or rule). e.g. mother(jane,alan). = Fact parent(P1,P2):- mother(P1,P2). = Rule • A clause consists of a head • and sometimes a body. – Facts don’t have a body because they are always true. head body
  • 91. 91 A clause Syntax  A prolog rule is called a clause.  A clause has a head, a neck and a body: father(X,Y) :- parent(X,Y) , male(X) . head neck body  the head is a rule's conclusion.  The body is a rule's premise or condition.  note:  read :- as IF  read , as AND  a . marks the end of input
  • 92. Arguments • A predicate head consists of a predicate name and sometimes some arguments contained within brackets and separated by commas. mother(jane,alan). • A body can be made up of any number of subgoals (calls to other predicates) and terms. • Arguments also consist of terms, which can be: – Constants e.g. jane, – Variables e.g. Person1, or – Compound terms Predicate name Arguments
  • 93. Complete Syntax of Terms Term Constant VariableCompound Term Atom Number alpha17 gross_pay john_smith dyspepsia + =/= ’12Q&A’ 0 1 57 1.618 2.04e-27 -13.6 likes(john, mary) book(dickens, Z, cricket) f(x) [1, 3, g(a), 7, 9] -(+(15, 17), t) 15 + 17 - t X Gross_pay Diagnosis _257 _ Names an individual Stands for an individual unable to be named when program is written Names an individual that has parts
  • 94. Structure of Programs • Programs consist of procedures. • Procedures consist of clauses. • Each clause is a fact or a rule. • Programs are executed by posing queries. An example…
  • 95. Example elephant(george). elephant(mary). elephant(X) :- grey(X), mammal(X), hasTrunk(X). Procedure for elephant Predicate Clauses Rule Facts
  • 97. Clauses: Facts and Rules Head :- Body. This is a rule. Head. This is a fact. ‘if’ ‘provided that’ ‘turnstile’ Full stop at the end.
  • 98. Body of a (rule) clause contains goals. likes(mary, X) :- human(X), honest(X). Head Body Goals Exercise: Identify all the parts of Prolog text you have seen so far.
  • 99. 99 Prolog knowledgebase (database) father(X,Y) :- parent(X,Y), male(X). sibling(X,Y) :- ... parent(adam,able) parent(adam,cain) male(adam) ... Rules Facts
  • 100. • Questions based on facts • Answered by matching Two facts match if their predicates are same and the arguments each are same. • If matched, prolog answers yes, else no. • No does not mean falsity. Questions
  • 108. Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia). yes ?- playsAirGuitar(jody). yes ?- playsAirGuitar(mia). no
  • 111. Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- tattoed(jody). ERROR: predicate tattoed/1 not defined. ?-
  • 116. © Patrick Blackburn, Johan Bos & Kristina Striegnitz Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda).
  • 117. © Patrick Blackburn, Johan Bos & Kristina Striegnitz Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact
  • 118. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact fact
  • 119. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact fact rule
  • 120. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact fact rule rule
  • 121. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact fact rule rule rule
  • 122. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). head body
  • 123. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?-
  • 124. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?- playsAirGuitar(mia). yes ?-
  • 125. Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?- playsAirGuitar(mia). yes ?- playsAirGuitar(yolanda). yes
  • 126. Clauses happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). There are five clauses in this knowledge base: two facts, and three rules. The end of a clause is marked with a full stop.
  • 127. Predicates happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). There are three predicates in this knowledge base: happy, listens2music, and playsAirGuitar
  • 128. Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch).
  • 129. Expressing Conjunction happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). The comma “," expresses conjunction in Prolog
  • 130. Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). ?- playsAirGuitar(vincent). no ?-
  • 131. Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). ?- playsAirGuitar(butch). yes ?-
  • 132. Expressing Disjunction happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch); listens2music(butch).
  • 133. Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin).
  • 134. Prolog Variables woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X).
  • 135. Variable Instantiation woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia
  • 136. Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia;
  • 137. Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody
  • 138. Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody; X=yolanda
  • 139. Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody; X=yolanda; no
  • 140. Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(marsellus,X), woman(X).
  • 141. Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(marsellus,X), woman(X). X=mia yes ?-
  • 142. Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(pumpkin,X), woman(X).
  • 143. Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(pumpkin,X), woman(X). no ?-
  • 144. Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z).
  • 145. Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z). ?- jealous(marsellus,W).
  • 146. Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z). ?- jealous(marsellus,W). W=vincent ?-
  • 147. Logic for knowledge representation
  • 148. 148 Introduction • Real knowledge representation and reasoning systems come in several major varieties. • These differ in their intended use, expressivity, features,… • Some major families are – Logic programming languages – Theorem provers – Rule-based or production systems – Semantic networks – Frame-based representation languages – Databases (deductive, relational, object-oriented, etc.) – Constraint reasoning systems – Description logics – Bayesian networks – Evidential reasoning
  • 149. Knowledge Representation Schemas Real knowledge representation and reasoning systems come in several major varieties. They all based on FOL but departing from it in different ways. Logic based representation – first order predicate logic, Prolog Procedural representation – rules, production system Network representation – semantic networks, conceptual graphs Structural representation – scripts, frames, objects
  • 150. Production Systems Widely used in expert systems (Production Systems) System has: Rule Base Working Memory Inference Mechanism (Interpreter) Explanation Facility
  • 151. Rule Base Stores permanent (problem-independent) knowledge. This knowledge is stored as production rules/condition-action rules. E.g. IF condition-1 AND condition-2 AND … AND condition-m THEN action-1 AND action-2 AND … AND action-n
  • 152. The IF-part is also called the left-hand side or antecedent. The THEN-part is also called the right-hand side or consequent. The actions in the consequent usually involve changes to working memory. e.g. adding, deleting or modifying working memory elements.
  • 153. 153 What are Rules? • Rules represent knowledge using IF-THEN format • The IF portion of a rule is a condition, (also called a premise or an antecedent), which tests the truth value of set of facts. • If these are found true, the THEN portion of a rule (also called the action, the conclusion or the consequent) is inferred as a new set of facts.
  • 154. 154 Production Systems and the Rules • The rule based systems are also called production systems. • Simon and Newel developed the production system to model human problem solving. • A production system consists of: – An area of memory that is used to track the current state of the universe under consideration (working memory - database). – A set of production rules :condition - action pairs (knowledge base). – An interpreter (inference engine) recognizes and executes a production whose conditions has been satisfied. This control may be either data driven or goal driven.
  • 155. 155 Rule-based Inference • Using search techniques and pattern matching, rule based systems automate reasoning methods and provide the logical progression from initial data to the desired conclusion. • Thus the process of problem solving in knowledge based systems is to create a series of inferences that create a “path” between the problem definition and the solution • This series of inferences is progressive in nature and is called an inference chain.
  • 156. 156 Example • Suppose we are building a knowledge based system for forecasting the weather over the next 12 – 24 hours in Florida during the summer. RULE 1: IF the ambient temperature is above 900 F THEN the weather is hot. RULE 2: IF the relative humidity is greater than 65% THEN the atmosphere is humid RULE 3: IF the weather is hot and the atmosphere is humid THEN thunderstorms are likely to develop.
  • 157. 157 Knowledge Representation scheme: Rules • Rules • These are formalization often used to specify recommendations, give directives or strategy. • Format: IF <premises> THEN <conclusion>. • Related ideas: rules and fact base; conflict set - source of rules; conflict resolution- deciding on rules to apply. – Advantages: easy to use; explanations are possible; capture heuristics; can handle uncertainties to some extent. – Disadvantages: cannot cope with complex associated knowledge; they can grow to unmanageable size.
  • 158. 158 Knowledge Representation scheme: Rules Consists of: • a rule set for representing the expert knowledge • a “database management system” for the case-specific facts • a rule interpreter for problem solving Example IF: (1) stain of organism is Gram neg. AND (2) morphology of organism is rod AND (3) aerobicity of organism is aerobic THEN: strong evidence (0.8) that organism is Enterobact Properties of rule-based systems:  modularity of rule, very expressive, easy hadling of certainty factors (probabilistic, possibilitic reasoning)  Lack of precise semantics of rules. Not always efficient
  • 159. 159 Rules - A simple example • Assume: Knowledge base consisting of facts and rules, a rule interpreter to match the rule conditions against facts and means for executing the rules. Rules: R1: IF: Raining,Outside(x),Has_Umbrella(x) THEN: Uses_Umbrella(x) R2: IF: Raining,Outside(x) NOT Has_Umbrella(x) THEN: Wet(x) R3: IF: Wet(x) THEN: Gets_Cold(x) R4: IF: Sunny,Outside(x) THEN: Gets_Sun_Tan(x) Initial facts: Raining, Outside(John)
  • 160. 160 Rules - A simple example Correct: • Only one rule, R2 matches the facts with [xJohn], hence add Wet(John) • Facts after first cycle: Raining, Outside(John), Wet(John) • Now R3 matches facts, hence add Gets_Cold(John) • Facts after second cycle: Raining, Outside(John), Wet(John), Gets_Cold(John) Process of deriving new facts from given facts, is called INFERENCE Incorrect: Gets_Sun_Tan(John)
  • 161. Inference Methods 1 deduction ◆ conclusions must follow from their premises; prototype of logical reasoning induction ◆ inference from specific cases (examples) to the general abduction ◆ reasoning from a true conclusion to premises that may have caused the conclusion resolution ◆ find two clauses with complementary literals, and combine them generate and test ◆ a tentative solution is generated and tested for validity ◆ often used for efficiency (trial and error) 1 6 1
  • 162. Inference Methods 2 default reasoning ◆ general or common knowledge is assumed in the absence of specific knowledge analogy ◆ a conclusion is drawn based on similarities to another situation heuristics ◆ rules of thumb based on experience intuition ◆ typically human reasoning method nonmonotonic reasoning ◆ new evidence may invalidate previous knowledge auto epistemic ◆ reasoning about your own knowledge 1 6 2