Page 203 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 203

Unit 14: Prolog




          14.2 Converting English to Prolog Facts and Rules                                     Notes


          14.2.1 Facts

          In ProLog, facts describe  the relationships between different objects and are independent  of
          each  other.  Facts  are  also  called  ground  clauses  and  are  the  basis  to  derive  further
          information.
          You can declare facts using predicates or functions. Predicates can take a number of arguments,
          which are enclosed within parentheses and are separated from  each other by commas.  The
          number of arguments that a predicate takes is known as its arity.


                 Example: The ProLog statement for the fact that NeoRage is an employee is:
          employee(neorage).
          In the above example, employee is the predicate and NeoRage is a data object and an argument
          to the predicate. The ‘arity’ of the predicate is one because it has only one argument.
          In the following ProLog statement, the arity of the predicate is two because it has two arguments
          for the fact that Sam is the father of Jack:
          father(sam, jack).
          In the above example, father is the predicate and Sam and Jack are the two arguments. ProLog
          evaluates facts from left to right so the above statement cannot be interpreted in reverse order
          and mean that Jack is the father of Sam.





             Notes   A fact begins with a lowercase letter and a statement ends with a period. All data
             objects, such as sam and jack, are atoms and cannot begin with an uppercase.

          14.2.2 Rules


          In ProLog, rules are used in the process of decision-making and  can deduce new facts from
          existing ones.


                 Example: Suppose there are two facts such as: trope likes mary bob likes sam
          The rule says:
          jim likes X if bob likes X.

          Prolog can deduce that:
          jim likes sam (jim lives in San Fran lol)
          You can give a ProLog program a goal that is a problem it needs to find a solution for.


                 Example: find every person who likes sam: ProLog will use its deductive ability to find
          all solutions to the problem.

          A rule consists of two parts: a conditional part, if, and a conclusion or action part, then.





                                           LOVELY PROFESSIONAL UNIVERSITY                                   197
   198   199   200   201   202   203   204   205   206   207   208