
Our next question is “Can Priya cook?”, it will say “yes”, but if we ask the same question for Jaya, it will say “No”. “Is priya a girl?”, it will reply “yes”, “is jamini a girl?” then it will answer “No”, because it does not know who jamini is. Now we can use this knowledge base by posing some queries. Note − Here we have written the name in lowercase letters, because in Prolog, a string starting with uppercase letter indicates a variable. Let’s try to write these facts in a more generic way as shown below − girl(priya).girl(tiyasha).girl(jaya).can_cook(priya). Suppose we have some knowledge, that Priya, Tiyasha, and Jaya are three girls, among them, Priya can cook. The facts are used to state things, that are unconditionally true of the domain of interest. Suppose we have our very first knowledge base called KB1.
#Block world problem using prolog how to#
Now, we will see how to write some knowledge bases. So we can say that the knowledge base is a collection of facts and rules. Among these three if we collect the facts and rules as a whole then that forms a Knowledge Base.

Well, as we know there are three main components in logic programming − Facts, Rules and Queries. In this section, we will see what knowledge base in logic programming is. So according to these queries, Logic programming language can find the answer and return them. So question can be anything, as given below − Queries are some questions on the relationships between objects and object properties. Example happy(lili) :- dances(lili).hungry(tom) :- search_for_food(tom).friends(jack, bili) :- lovesCricket(jack), lovesCricket(bili).goToPlay(ryan) :- isClosed(school), free(ryan). )Suppose a clause is like :P :- Q R.This can also be written asP :- Q.P :- R.If one clause is like :P :- Q,R S,T,U.Is understood asP :- (Q,R) (S,T,U).Or can also be written as:P :- Q,R.P :- S,T,U.

Here we can use comma (,) which is known as conjunction, and we can also use semicolon, that is known as disjunction. This is also known as neck symbol, the LHS of this symbol is called the Head, and right hand side is called Body. Here the symbol ( :- ) will be pronounced as “If”, or “is implied by”. So these are some rules that are conditionally true, so when the right hand side is true, then the left hand side is also true. Will go to play if school is closed, and he is free. Jack and Bili are friends if both of them love to play cricket. Tom is hungry if he is searching for food. Suppose we have some rules as given below − So when one associated condition is true, then the predicate is also true. We can define rule as an implicit relationship between objects. Exampleįollowing is an example of the above concept − cat(tom).loves_to_eat(kunal,pasta).of_color(hair,black).loves_to_play_games(nawaz).lazy(pratyusha).

The syntax for facts is as follows − relation(object1,object2.). They also can begin with digits (like 1234), and can be strings of characters enclosed in quotes e.g. Objects also begin with lower case letters. Objects appear as comma-separated arguments within parentheses. The relationship name appears as the first term. Names of properties/relationships begin with lower case letters. These are actually statements, that we have to consider as true.įollowing are some guidelines to write facts − So these are some facts, that are unconditionally true.

Suppose we have some facts as given below − So facts are unconditionally true in nature. We can define fact as an explicit relationship between objects, and properties these objects might have. These building blocks are Facts, Rules and the Queries. Here, we will discuss about the essential building blocks of logic programming. We will get some detailed knowledge about facts and rules, and also see some kind of queries that will be used in logic programming. We will see in detail about the Knowledge Base, and how it helps in logic programming.įacts, Rules and Queries − These are the building blocks of logic programming. Knowledge Base − This is one of the fundamental parts of Logic Programming. The different topics that will be covered in this chapter are − So we will move on to the first step of our Prolog Programming. In this chapter, we will gain some basic knowledge about Prolog.
