1 / 17

Artificial Intelligence Lecture No. 21

Artificial Intelligence Lecture No. 21 . Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan. Summary of Previous Lecture. Be Assertive variable more than once Retraction single-field wildcard.

sulwyn
Télécharger la présentation

Artificial Intelligence Lecture No. 21

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Artificial IntelligenceLecture No. 21 Dr. Asad Ali Safi ​ Assistant Professor, Department of Computer Science,  COMSATS Institute of Information Technology (CIIT) Islamabad, Pakistan.

  2. Summary of Previous Lecture • Be Assertive • variable more than once • Retraction • single-field wildcard

  3. Today’s Lecture • Single-field wildcard • Multifieldwildcard • single-field variable ? or a multifield variable ?$ • Anywhere • Single- and multifield wildcards

  4. single-field wildcard • Instead of binding a field value to a variable, the presence of a nonempty field can be detected alone using a wildcard. • This type of situation, in which only part of the fact is specified, is very common and very important. To solve this problem, a wildcard can be used to fire the Richards. • The simplest form of wildcard is called a single-field wildcard and is shown by a question mark, "?". The "?" is also called a single-field constraint. • A single-field wildcard stands for exactly one field

  5. (clear) (defrule meeting (meeting-with Khan ?) => (printout t " The meeting will be with Khan…" crlf)) (deffacts M1 (meeting-with Kamal) (meeting-with Khan ) (meeting-with Khan Ali ) (meeting-with Khan Ali Khan) (meeting-with Ali Khan)) (reset) (run)

  6. Three fields • The pattern includes a wildcard to indicate that Khan's last name is not important. • So long as the first name is Khan, the rule will be satisfied and fire. • Now with pattern of three fields of which one is a single-field wildcard, only facts of exactly three fields can satisfy it. In other words, only Khan with exactly two names can satisfy this • Suppose you want to specify Khan with exactly three names?

  7. With first name (meeting-with Khan ? ?) • or, if only persons with three names whose middle name (meeting-with ? Khan ?) • or, if only the last name was Dopey, as in the following • (meeting-with ? ? Khan)

  8. Multirules • Another interesting possibility occurs if Khan must be the first name, but only those Khan’s with two or three names are acceptable. One way of solving this problem is to write two rules. (defrule meeting (meeting-with Khan ?) => (printout t " The meeting will be with Khan " crlf)) (defrule meeting (meeting-with Khan ? ?) => (printout t " The meeting will be with Khan " crlf))

  9. Bind • Of course, if you don't want anonymous meeting, you need to bind the Khan’s names with a variable and print them out. (meeting-with Khan ?a ?b)

  10. Multifield wildcard • Rather than writing separate rules to handle each field, it's much easier to use the multifield wildcard. • This is a dollar sign followed by a question mark, "$?", and represents zero or more fields. • Notice how this contrasts with the single-field wildcard which must match exactly one field. • The two rules for dates can now be written in a single rule as follows.

  11. (clear) (defrule meeting (meeting-with Khan $?) => (printout t " The meeting will be with Khan " crlf)) (deffacts M1 (meeting-with Kamal) (meeting-with Khan ) (meeting-with Khan Ali ) (meeting-with Khan Ali Khan) (meeting-with Ali Khan)) (reset) (run)

  12. variable such as ?x, $?x • Wildcards have another important use because they can be attached to a symbolic • field to create a variable such as ?x, $?x, ?name, or $?name. • The variable can be a single-field variable or a multifield variable depending on whether a "?" or "$?" is used on the LHS. • Note that on the RHS only a ?x is used, where the "x" can be any variable name. • You can think of the "$" as a function whose argument is a single-field wildcard or a single-field variable and returns a multifield wildcard or a multifield variable, respectively.

  13. (defrule meeting (meeting-with Khan $?name) => (printout t " The meeting will be with Khan " ?namecrlf)) • As you can see, on the LHS, the multifield pattern is $?name but is ?name when used as a variable on the RHS. When you enter and run, you'll see the names of all eligible Khan. • The multifield wildcard takes care of any number of fields. Also, notice that multifield values are returned enclosed in parentheses.

  14. Anywhere • Suppose you wanted a match of all candidates who had a Khan somewhere in their name, not necessarily as their first name. (defrule meeting (meeting-with $?First Khan $?Last) => (printout t " The meeting will be with” ?First ”Khan" ?Last crlf)) • The pattern matches any names that have a Khan anywhere in them.

  15. Single- and multifield wildcards • Single- and multifield wildcards can be combined. For example, the pattern (meeting-with ? $? Khan ?) • means that the first and last names can be anything and that the name just prior to the last must be Khan. • This pattern also requires that the matching fact will have at least four fields, since the "$?" matches zero or more fields and all the others must match exactly four.

  16. Single- and multifield wildcards.. • Although multifield variables can be essential for pattern matching in many cases, their overuse can cause much inefficiency because of increased memory requirements and slower execution. • As a general rule of style, you should use $? only when you don't know the length of fields. Do not use $? simply as a typing convenience.

  17. Summery of Today’s Lecture • Single-field wildcard • Multifield wildcard • single-field variable ? or a multifield variable ?$ • Anywhere • Single- and multifield wildcards

More Related