• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PROLOG: Fact Roles And Queries In Prolog
 

PROLOG: Fact Roles And Queries In Prolog

on

  • 4,441 views

PROLOG: Fact Roles And Queries In Prolog

PROLOG: Fact Roles And Queries In Prolog

Statistics

Views

Total Views
4,441
Views on SlideShare
4,308
Embed Views
133

Actions

Likes
0
Downloads
0
Comments
0

4 Embeds 133

http://www.dataminingtools.net 89
http://dataminingtools.net 37
http://www.slideshare.net 4
http://oliva.uhk.cz 3

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PROLOG: Fact Roles And Queries In Prolog PROLOG: Fact Roles And Queries In Prolog Presentation Transcript

    • Facts, Rules and Queries in Prolog
    • overview
      Introduction
      Simple examples
      Prolog Syntax
      Atoms
      Numbers
      Variables
      Complex terms
    • 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)
    • 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.
    • 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
    • Knowledge Base 2
      Ex:listensToMusic(mia).
      happy(yolanda).
      playsAirGuitar(mia) :- listensToMusic(mia).
      playsAirGuitar(yolanda) :- listensToMusic(yolanda).
      listensToMusic(yolanda):- happy(yolanda).
      • KB2 contains two facts: listensToMusic(mia) and happy(yolanda).
      • The last three
      items are rules.
      Rules state information that is conditionally true of the domain of interest.
    • 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
    • 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.
    • 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).
    • 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.
    • Knowledge Base 5
      Ex:
      loves(vincent,mia).
      loves(marcellus,mia).
      loves(pumpkin,honey_bunny).
      loves(honey_bunny,pumpkin).
      jealous(X,Y) :- loves(X,Z),loves(Y,Z).
      • KB5 contains four facts about the loves relation and one rule.
    • Knowledge Base 5
      In the previous example, It says that an individual X will be jealous of an individual Y if there is some individual Z that X loves, and Y loves that same individual Z too.
      Ex: ?- jealous(marcellus,W).
      • This query asks: can you find an individual W such that Marcellus is jealous of W?
      Prolog will return the value W = vincent
    • 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.
    • ATOMS
      An atom is either:
      • A string of characters made up of upper-case letters, lower-case letters, digits, and the underscore character, that begins with a lower-case letter.
      • An arbitrary sequence of character enclosed in single quotes.
      Ex: 'Vincent','The Gimp', ' A string of special characters. Five_Dollar_Shake', '&^%&#@$ &*', and ' '.
      • For example: @= and ====> and ; and :- are all atoms.
    • NUMBERS
      Prolog implementations support
      • Floating point numbers or floats (that is, representations of real numbers such as 1657.3087 or )
      • Integers (that is: ... -2, -1, 0, 1, 2, 3, ...) are useful for such tasks as counting the elements of a list.
    • VARIABLES
      A variable is a string of :
      upper-case letters
      lower-case letters
      digits
      underscore characters that starts either with an upper-case letter or with underscore.
    • 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.
    • 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