Trending Technology Machine Learning, Artificial Intelligent, Block Chain, IoT, DevOps, Data Science

Recent Post

Codecademy Code Foundations

Search This Blog

Readline Function and (assert-string) in AI

(read) Function
  • The (read) function is not a general-purpose function that will read anything you type on the keyboard. One limitation is that (read) will read only one field. So if you try to read
               - Primary color is red
  • only the first field, "primary", will be read. To (read) all the input, you must enclose the input within double quotes.
  • Of course once the input is within double quotes, it is a single literal field. You can then access the substrings "primary", "color", "is", and "red" with the str-explode or sub-string functions.
  • The second limitation of (read) is that you can't input parentheses unless they are within double quotes. Just as you can't (read) parentheses directly except as literals.
readline function
  • The readline function is used to read multiple values until terminated by a carriage return. this function reads in data as a string.
  • In order to assert the (readline) data, an (assert-string) function is used to assert the nonstring fact, just as input by (readline).
  • CLIPS>(clear)
  • CLIPS> (assert-string"(primary color is red)")
  • <Fact-1>
  • Notice that the argument of (assert-string) must be a string The following shows how to assert a fact of multiple fields from (readline). 
       CLIPs> (clear)
       CLIPS> (defrule test-readline
       (printout t "Enter input" crlf)
       (bind ?string (readline) )
       (assert-string (str-cat "(" ?string")")))
       CLIPS> (reset)
        CLIPS> (run)

  • Since (assert-string) requires parentheses around  the string to be assert, the (str-cat) function is used to put them arount /string.
  • Both (read) and (readline) also can be used to read information from a file by specifying the logical name of the file as the argument. For more information, see the CLIPS Reference Manual.

Test conditional element
  • The test conditional element provides a very powerful way by which to compare numbers, variables, and strings on the LHS. The (test) is used as a pattern on the LHS.
  • A rule will only be triggered if the (test) is satisfied together with other patterns.
  • Many predefined functions are provided by CLIPS as shown in the following table.
  • All the comparison functions except "eq" and "neq" will give an error message if they are used to compare a number and non-number.
  • If the type is not known in advance, the "eq" and "neq" functions should be used.
  • The eq function checks for the same magnitude and type of its arguments.
  • while the "=" function only checks the the magnitude of its (numeric) arguments and doesn't care if they're integer or floating-point. 
Logical values
  • The logical functions of CLIPS are and, or, and not. they can be used in expressions as Boolean functions. In CLIPS, true and false are represented by the symbols TRUE and FALSE.
  • Note that upper-case must be used for logical values in CLIPS.

No comments:

Post a Comment

Popular Articles