Expert systems - CLIPS language learning (1) fact & rule

What is an expert system?

Expert system (Expert System) is a system with a program level of experts in a particular field of problem-solving skills, belonging to a development branch of artificial intelligence. It can effectively use expert accumulated over the years of effective experience and expertise, through the thought process simulation experts to solve the problem needs to be resolved expert.

The basic structure of the expert system as shown, where the direction of the arrow is the direction of data flow. Expert systems are often, knowledge base, inference engine, an interpreter, a comprehensive database of knowledge acquired by the man-machine interface and other six parts. (From: MBA think tank)

 

What is CLIPS?

CLIPS is a programming language for writing expert systems, also known as expert system tools. CLIPS shell (shell represent part of the programming environment on behalf of the analysis, reasoning) contains a fact-lists (a list of facts), knowledge-base (knowledge base), inference engine (Inference Engine).

The official document as follows: (WPS open eye, green eyes sparkling Ning)

We plan to develop an expert system CLIPS heuristic reasoning based data processing and UI interface will use Python to write code that implements late. At this stage the main completion logic module, selected as an expert system CLIPS programming language, configure the appropriate coding environment, learning the official document CLIPS6.4 and synchronization take notes here.

 

Programming environment: CLIPS IDE

Harm, said IDE, in fact, a good-looking interface Diudiu CLIPSDOS, the command prompt is "CLIPS>". Programming process does not match the shortcut and error, but this "back to nature" of programming, but also help improve the sensitivity of the programming it. In addition to each CLIPS statement and the different keywords need to wrap this point outside the parentheses, such as (fact), other programming ideas and data structures with more or less similar to C and Java.

 

Part One: Facts

fact (fact) is the most basic element of an expert system, how to master the main statement (assert), remove (retract) the fact that you can.

In fact assert generate, delete retract, <Fact-1> ID corresponding to each of the facts to (FACTS) to see a list of the fact that static data, (watch facts) dynamically view, the command is entered, the program changes the dynamic display status list .

 

Part Two: Rule

(Hear say, send a few rules to create, change the world ah ha ha)

This section describes how to define rules Rule, in which the heuristic reasoning based on facts inferred next move, similar to the IF THEN Java, C or Ada language. Let's pseudo-code ( Pseudocode define a simple rule):

IF the animal is a duck  THEN the sound made is quack

We defrule define a rule, similar to the function, it can be called back (block there's no language selection in CLIPS, bad review!)

; After that comment

CLIPS> (assert (animal-is duck))                  ;事先声明fact

<Fact-1>
CLIPS> (defrule duck                              ;duck是规则名
 (animal-is duck)                                 ;LHS条件fact
=>                                                ;符合条件后执行下一步
 (assert (sound-is quack)))                       ;RHS执行活动activation

CLIPS> (agenda)
0      duck: f-1                                  ;默认优先级为0,这个范围是-10000~10000
For a total of 1 activation.
CLIPS>  (watch facts)
CLIPS> (watch activations)
CLIPS> (run)                                      ;运行名为duck的rule,符合条件,成功执行活动

==> f-2     (sound-is quack)
CLIPS> (facts)

f-1     (animal-is duck)
f-2     (sound-is quack)
For a total of 2 facts.
CLIPS> 

A simple logic, (animal-is duck) obtained in conditions rule the match, triggered activity (assert (sound-is quack)), which is a new declaration of fact. In this simple programming process, also encountered some small problems, leading to rule difficult to trigger, mainly due to rule of LHS (left hand side) must be declared conditions, or can not match.

Further, RHS (right hand side) may be output to the active screen, a => downward to the right to command

(printout t "quack" crlf)

"T" to inform the content CLIPS output standard output device is a computer (usually a terminal terminal)

发布了2 篇原创文章 · 获赞 0 · 访问量 822

Guess you like

Origin blog.csdn.net/Jariswale/article/details/104291931