3. Facts Roles and Queries There are only three basic constructs in Prolog: facts, rules, and queries. Prolog programming is all about writing knowledge bases. A collection of facts and rules is called a knowledge base (or a database)
4. Knowledge Base 1 Knowledge Base 1 (KB1) is simply a collection of facts. Facts are used to state things that are unconditionally true of the domain of interest. Ex: woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). ïš state that Mia, Jody, and Yolanda are women, and Jody plays air guitar.
5. Knowledge Base 1 KB1 can be used by posing queries. Ex: We can ask Prolog whether Mia is a woman by posing the query: ?- woman(mia). ïšYes we can ask whether Jody plays air guitar by posing the following query: ?- playsAirGuitar(jody). ïšYes
6.
7. The last three items are rules. Rules state information that is conditionally true of the domain of interest.
8. Knowledge Base 2 :- should be read as ``if'', or``is implied by''. The part on the left hand side of the :- is called the head of the rule. The part on the right hand side is called the body. Ex: We can ask Prolog whether Mia plays air guitar: ?- playsAirGuitar(mia)ïš Yes
9. Knowledge Base 3 KB3 consists of five clauses: happy(vincent). listensToMusic(butch). playsAirGuitar(vincent):- listensToMusic(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listensToMusic(butch). There are two facts, namely happy(vincent) and listensToMusic(butch), and three rules.
10. Knowledge Base 4 KB4 contains no rules, only a collection of facts. woman(mia). woman(jody). woman(yolanda). loves(vincent,mia). loves(marcellus,mia). loves(pumpkin,honey_bunny). loves(honey_bunny,pumpkin).
11. Knowledge Base 4 Ex: if we query ?- woman(X). Prolog reports back to us as follows: X = mia ïšThe first item in the knowledge base is woman(mia). So, Prolog matches X to mia, thus making the query agree perfectly with this first item.
12.
13. Prolog syntax There are four kinds of terms in Prolog: ïšatoms, numbers, variables, and complex terms (or structures). Atoms and numbers are lumped together under the heading constants, and constants and variables together make up the simple terms of Prolog. The upper-case letters are A, B, ..., Z; The lower-case letters are a, b, ..., z; The digits are 1, 2, ..., 9; The special characters are +, -, *, /, <, >,=, :, ., &, ~, and _. The _ character is called underscore. A string is an unbroken sequence of characters.
14.
15.
16.
17. COMPLEX TERMS Complex terms are build out of a functor followed by a sequence of arguments. The arguments are put in ordinary brackets, separated by commas, and placed after the functor. The functor must be an atom. That is, variables cannot be used as functors. Arguments can be any kind of term. Ex: in the previous examples ïšplaysAirGuitar(jody) is a complex term: ïšits functor is playsAirGuitar ïšand its argument is jody.
18. Visit more self help tutorials Pick a tutorial of your choice and browse through it at your own pace. The tutorials section is free, self-guiding and will not involve any additional support. Visit us at www.dataminingtools.net