انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

lec1:: introduction to prolog and fact

الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 3
أستاذ المادة اسراء عبد الله حسين علي الدليمي       17/10/2017 13:33:48
There are only three basic constructs in Prolog: facts, rules, and queries. A collection of facts and rules is called a knowledge base (or a database) and Prolog programming is all about writing knowledge bases.



Facts ::
Facts are those statements that state the objects or describe the relationship between objects. For an instance when we say john likes piano, we are showing the like relationship between two objects john and piano and in prolog this fact can be written as likes(john,piano).



Example 1::
music_student(john). // Read as : john is a music student
likes(John,books) // Read as : john likes books
gives(john, chocolate). // Read as : john gives chocolate





How to query ::
Once you have entered the facts in a program you can ask prolog about it. An example program can be :
eats(fred,oranges). /* Fred eats oranges */
eats(tony,apple). /* Tony eats apple */
eats(john,apple). /* John eats apple */

If we now ask some queries we would get the followings things :
?- eats(fred,oranges).
/* does this match anything in the database? */
yes
/* yes, that matches the first clause */

?- eats(john,apple).
yes
?- eats(mike,apple).
no
/* there is no relation between mike and apple */
Examples 2::
lectures(ahmed, ai).
lectures(john, databases).
female(alison).
age(alison, 29).
office(alison, s134).
animal(lion).
?- lectures(alison, ai).
``yes .
?- lectures(alison, databases).
no




المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .