




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、chapter 8:advanced pattern matchingexpert systems: principles and programming, fourth editionexpert systems: principles and programming, fourth edition2field constraints in addition to pattern matching capabilities and variable bindings, clips has more powerful pattern matching operators. consider w
2、riting a rule for all people who do not have brown hair: we could write a rule for every type of hair color that is not brown. this involves testing the condition in a roundabout manner tedious, but effective.expert systems: principles and programming, fourth edition3field constraints the technique
3、for writing a rule for all non-brown hair colors implies that we have the ability to supply all hair colors virtually impossible. an alternative is to use a field constraint to restrict the values a field may have on the lhs the then part of the rule.expert systems: principles and programming, fourt
4、h edition4connective constraints connective constraints are used to connect variables and other constraints. not connective the acts on the one constraint or variable that immediately follows it. or constraint the symbol | is used to allow one or more possible values to match a field or a pattern. a
5、nd constraint the symbol & is useful with binding instances of variables and on conjunction with the not constraint.expert systems: principles and programming, fourth edition5combining field constraints field constraints can be used together with variables and other literals to provide powerful
6、pattern matching capabilities. example #1: ?eyes1&blue|green this constraint binds the persons eye color to the variable, ?eyes1 if the eye color of the fact being matched is either blue or green. example #2: ?hair1&black this constraint binds the variable ?hair1 if the hair color of the fac
7、t being matched is not black.expert systems: principles and programming, fourth edition6functions and expressions clips has the capability to perform calculations. the math functions in clips are primarily used for modifying numbers that are used to make inferences by the application program.expert
8、systems: principles and programming, fourth edition7numeric expressions in clips numeric expressions are written in clips in lisp-style using prefix form the operator symbol goes before the operands to which it pertains. example #1:5 + 8 (infix form) + 5 8 (prefix form) example #2:(infix) (y2 y1) /
9、(x2 x1) 0(prefix) ( ( / ( - y2 y1 ) (- x2 x1 ) ) 0)expert systems: principles and programming, fourth edition8return values most functions (addition) have a return value that can be an integer, float, symbol, string, or multivalued value. some functions (facts, agenda commands) have no return values
10、 just side effects. division results are usually rounded off. return values for +, -, and * will be integer if all arguments are integer, but if at least one value is floating point, the value returned will be float.expert systems: principles and programming, fourth edition9variable numbers of argum
11、ents many clips functions accept variable numbers of arguments. example:clips (- 3 5 7) returns 3 - 5 =-2 - 7 = -9 there is no built-in arithmetic precedence in clips everything is evaluated from left to right. to compensate for this, precedence must be explicitly written.expert systems: principles
12、and programming, fourth edition10embedding expressions expressions may be freely embedded within other expressions:expert systems: principles and programming, fourth edition11summing values using rules suppose you wanted to sum the areas of a group of rectangles. the heights and widths of the rectan
13、gles can be specified using the deftemplate:(deftemplate rectangle (slot height) (slot width) the sum of the rectangle areas could be specified using an ordered fact such as:(sum 20)expert systems: principles and programming, fourth edition12summing values a deffacts containing sample information is
14、:(deffacts initial-information(rectangle (height 10) (width 6)(rectangle (height 7) (width 5)(rectangle (height 6) (width 8)(rectangle (height 2) (width 5)(sum 0)expert systems: principles and programming, fourth edition13summing valuesexpert systems: principles and programming, fourth edition14the
15、bind function sometimes it is advantageous to store a value in a temporary variable to avoid recalculation. the bind function can be used to bind the value of a variable to the value of an expression using the following syntax:(bind )expert systems: principles and programming, fourth edition15i/o fu
16、nctions when a clips program requires input from the user of a program, a read function can be used to provide input from the keyboard:expert systems: principles and programming, fourth edition16read function from keyboard the read function can only input a single field at a time. characters entered
17、 after the first field up to the are discarded. to input, say a first and last name, they must be delimited with quotes, “xxx xxx”. data must be followed by a carriage return to be read.expert systems: principles and programming, fourth edition17i/o from/to files input can also come from external fi
18、les. output can be directed to external files. before a file can be accessed, it must be opened using the open function:example:(open “mydata.dat” data “r”) mydata.dat is the name of the file (path can also be provided)expert systems: principles and programming, fourth edition18i/o from/to files dat
19、a is the logical name that clips associates with the file “r” represents the mode how the file will be used here read access the open function acts as a predicate function returns true if the file was successfully opened returns false otherwiseexpert systems: principles and programming, fourth editi
20、on19table 8.2 file access modesexpert systems: principles and programming, fourth edition20close function once access to the file is no longer needed, it should be closed. failure to close a file may result in loss of information. general format of the close function:(close )(close data) exampleexpe
21、rt systems: principles and programming, fourth edition21reading / writing to a file which logical name used, depends on where information will be written logical name t refers to the terminal (standard output device).expert systems: principles and programming, fourth edition22formatting output sent
22、to a terminal or file may need to be formatted enhanced in appearance. to do this, we use the format function which provides a variety of formatting styles. general format:(format *)expert systems: principles and programming, fourth edition23formatting logical name t standard output device; or logic
23、al name associated with a file. control string: must be delimited with quotes consists of format flags to indicate how parameters should be printed 1 1 correspondence between flags and number of parameters constant values or expressions return value of the format function is the formatted string nil
24、 can be used to suppress printing.expert systems: principles and programming, fourth edition24formatting example:(format nil “name: %-15s age: %3d” “bob green” 35) produces the results:“name: bob green age: 35”expert systems: principles and programming, fourth edition25specifications of format flag%
25、-m.nx the “-” means to left justify (right is the default) m total field width no truncation occurs n number of digits of precision default = 6 x display format specificationexpert systems: principles and programming, fourth edition26table 8.3 display format specificationsexpert systems: principles
26、and programming, fourth edition27readline function to read an entire line of input, the readline function can be used:(readline ) example:(defrule get-name=(printout t “what is your name? “(bind ?response (readline)(assert (users-name ?response)expert systems: principles and programming, fourth edit
27、ion28predicate functions a predicate function is defined to be any function that returns: true false any value other than false is considered true. we say the predicate function returns a boolean value.expert systems: principles and programming, fourth edition29the test conditional element processin
28、g of information often requires a loop. sometimes a loop needs to terminate automatically as the result of an arbitrary expression. the test condition provides a powerful way to evaluate expressions on the lhs of a rule. rather than pattern matching against a fact in a fact list, the test ce evaluat
29、es an expression outermost function must be a predicate function.expert systems: principles and programming, fourth edition30test condition a rule will be triggered only if all its test ces are satisfied along with other patterns.(test )example:(test ( ?value 1)expert systems: principles and program
30、ming, fourth edition31predicate field constraint the predicate field constraint : allows for performing predicate tests directly within patterns. the predicate field constraint is more efficient than using the test ce. it can be used just like a literal field constraint by itself or part of a comple
31、x field. the predicate field constraint is always followed by a function for evaluation (predicate function).expert systems: principles and programming, fourth edition32return value constraint the return value constraint = allows the return value of a function to be used for comparison inside a patt
32、ern. the return value constraint must be followed by a function (not necessarily a predicate function). the function must have a single-field return value.expert systems: principles and programming, fourth edition33the or conditional element consider the two rules:expert systems: principles and prog
33、ramming, fourth edition34or conditional elementthese two rules can be combined into one rule or ce requires only one ce be satisfied:expert systems: principles and programming, fourth edition35the and conditional elementthe and ce is opposite in concept to the or ce requiring all the ces be satisfie
34、d:expert systems: principles and programming, fourth edition36not conditional elementwhen it is advantageous to activate a rule based on the absence of a particular fact in the list, clips allows the specification of the absence of the fact in the lhs of a rule using the not conditional element:expe
35、rt systems: principles and programming, fourth edition37not conditionalwe can implement this as follows:expert systems: principles and programming, fourth edition38the exists conditional element the exists ce allows one to pattern match based on the existence of at least one fact that matches a patt
36、ern without regard to the total number of facts that actually match the pattern. this allows a single partial match or activation for a rule to be generated based on the existence of one fact out of a class of facts.expert systems: principles and programming, fourth edition39exists conditionalexpert
37、 systems: principles and programming, fourth edition40exists when more than one emergency fact is asserted, the message to the operators is printed more than once. the following modification prevents this:expert systems: principles and programming, fourth edition41exists this assumes there was already an alert triggered by an operator-emergency rule. what if the operators were merely placed on alert to a drill:expert systems: principles a
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025饮料分销代理合同
- 2025销售劳动合同模板
- 2025公司服装供货合同
- 2025维修合同 设备维修合同
- 2025办公室租赁合同附加协议
- 瓷砖销售类劳动合同协议
- 班干部任职合同协议
- 病人护理中介合同协议
- 电力作业人员合同协议
- 皮卡配件供货合同协议
- 非洲自然灾害
- 2023诗词大会知识竞赛200题题库(含答案)
- TL226 大众试验测试标准
- 2023借款协议书Word模板
- 生产设备拆除工程施工方案
- (完整版)年产30万吨合成氨合成工段工艺设计毕业论文
- 无障碍公共设施建设的问题及其对策研究
- 临床医学(专科)毕业综合考复习题
- 石家庄市存量房买卖合同
- 思想道德与法治2023版教学设计第六章 学习法治思想 提升法治素养
- 自来水厂调试方案
评论
0/150
提交评论