Web expert system for Visual Prolog (10)

Source: Internet
Author: User

The core of Geni--Inference Machine (4) Verification Process Analysis 1, Geni Knowledge Base structure

The design and operation of expert system inference machine is closely related to its knowledge base structure.

Geni Knowledge Base structure is a logical reasoning tree. The root node is the animal, which is the target of verification.

Animal has 2 sub-nodes, that is, the sub-goal of verification. A node or sub-target, expressed in rule. For example:

Rule (8, "Animal", "mammal", [12,13], "" ")

Rule (9, "Animal", "bird", [9,14], "" ")

Note that the 2nd parameter of rule is the target of the verification, and the 3rd parameter is its child target. The relationship of these 2 parameters constitutes a reasoning tree.

Rules 8 and 9 are the relationships of logic or OR. One rule proves to be true, and the target animal is true.

Rule 8, the sub-target is mammal, the mammal, the condition proved to be true is [12,13].

Rule 9, the sub-target is bird, the bird, the condition that proves to be true is [9,14].

The proof condition [12,13] is the relationship between logic and, and. [9,14] also. That is, the 2 conditions are true and the child targets are true.

The proof condition is represented as cond in the Knowledge base. For example, the above 4 conditions:

Cond ("It has Hair", "animals\\animals.htm")

Cond ("It does give milk", "animals\\animals.htm")

Conditions 12, 13 mean that mammals should have hair, secretion of milk.

Cond (9, "It has Feathers", "animals\\bird3.htm")

Cond ("It Lays eggs", "

Condition 9, 14 means that birds have feathers and can lay eggs.

Note that the 3rd parameter of cond, which is used for displaying Web pages, has nothing to do with proving reasoning.

Below the target mammal and bird, there are child targets. Take mammal as an example:

Rule ("Mammal", "carnivore", [15], ""), sub-target is carnivore, carnivore

Rule (one, "mammal", "ungulate", [16], ""), sub-target is ungulate, even hoof-like animal

2 or the target of the relationship under carnivore and ungulate, there are sub-goals. Take carnivore as an example:

Rule (1, "Carnivore", "Cheetah", [up], "animals\\cheetah.htm"), sub-target is cheetah

Rule (2, "Carnivore", "Tiger", [1,3], "

Cheetah and Tiger are the leaf nodes of the above inference tree, and the final sub-goal.

If the proof condition of rule 1 [+] or the proof condition of Rule 2 [1,3] is true, a complete proof chain is formed and a proof conclusion is obtained.

2. Starting point and end point of reasoning verification: predicate go
  Go (_, Mygoal, RULEXPL):-  is_htmlfile (RULEXPL),!, consult_htm (Rulexpl,htmltext), Gethtmlbody (Htmltext,bodytext) ,Write ("I think the answer is:", Mygoal), Nl,write (Bodytext), Nl,endpage ("").  Go (_, Mygoal, RULEXPL):-Not(rule (_,mygoal,_,_,_)),!, nl,write ("I think the answer is:", Mygoal), Nl,write ( RULEXPL), Nl,endpage ("").  Go (History, Mygoal,_):-rule (RNO,MYGOAL,NY,COND,RULEXPL), check (Rno,history, COND), Go ([rno| HISTORY],NY,RULEXPL).  Go (_, mygoal,_):-rule (_RNO,MYGOAL,_NY,_COND,_RULEXPL),!, true,write ("<H> Sorry, but I had no answer for this probl Em! 

The predicate go loops recursively, with the following characteristics:

(1), clauses 1 and 2 are identical recursive termination conditions, not(rule (_,mygoal,_,_,_))

The implication is that the target of the current processing is mygoal, not the "category" of the animal, but the name of the animal. At this time, the specific animal proof condition is true, that is animal all sub-goals are true, the goal proved to be true.

Review the rule data format, and the 2nd parameter is the animal category.

The difference between clauses 1 and 2 is that they deal with different methods of displaying Web pages, regardless of reasoning.

(2), the 3rd clause, take out the current target mygoal (animal category) rule, check to verify whether Mygoal is true, that is, whether the conditions are all true;

If the verification is true, then do 3 things:

①, put the rule number of the Mygoal in the table header of history, and record the rule that was tried to be used to deal with why problem;

②, put Mygoal's sub-target NY as the next target, in order to ensure that the final goal to verify the progress;

③, the previous 2 sets as the parameter, carries on the recursive inference to prove.

(3), the 4th clause, this verification failure, inform the user.

Can prove the phrase, stating that the first 3 clauses have failed to verify.

That is, there is no proof of what kind of animal, and can not continue to recursion, only to prove that the failure ended.

Note that the predicate Go's 3rd clause, quite "technical content", is worth looking at a few more eyes.

3, the conditions for the establishment of the rules of Authenticity: predicate check

This is the version that removes the "useless clause":

Check (RNO, history, [cno| REST]):-yes (CNO),!, check (RNO, History, REST).  Check (_, _, [Cno|_]):-no (CNO),!, fail.  Check (RNO, history, [cno| REST]):-cond (cno,text,options),!, inpq (history,rno,cno,text,options),Check (RNO, History, REST).  Check (_, _, []).

Check has the following features:

(1), clause 1 recursive method, the 3rd parameter [cno| REST], proof of all conditions.

If all the conditions are yes, return to the Go 3rd clause. Go then re-set the parameters, the rules do the next step to verify.

(2), clause 2 specifically to deal with the conditions of the proof is false, thereby denying the rule of the situation.

When no (CNO) is found, the "!,fail" force fails and the backtracking is canceled, no other No (X) conditions are identified, and the 3rd and 4th clauses are not tested back.

This failure of clause 2, which is returned to the GO Clause 3, causes the latter to fail, causing it to retrace the rule and find a new rule retry.

Go Clause 3 If a new rule is found, a new recursion is started; otherwise, the verification fails.

(3), clause 3 to deal with the conditions of proof CNO undecided.

If no fact yes (CNO) and no (CNO) exist, clauses 1 and 2 fail, then go back to Clause 3.

Clause 3 has a logic error. If successful, the INPQ will call the built-in predicate exit,geni.exe close;

If the INPQ fails, the CHECK clause 3 also fails. Also, because there is "!", it does not backtrack to check clause 4.

In either case, at the end of the check clause 3,check (RNO, History, REST) does not prove.

The correct logic should be as follows.

  Check (RNO, history, [cno| REST]):-cond (cno,text,options),!, inpq (history,rno,cno,text,options).

(4), Clause 4 dealing with the error of Knowledge base predicate cond, improper measures.

Clause 4 is only possible if the COND predicate for the Knowledge base has a critical error.

At this point, the correct approach, clause 4 should immediately report an error alarm, can not be withholding information, leaving hidden trouble.

I modified the check clause 3 to block Clause 4 with a comment. The program compiles and runs, and the results are normal.

4. Analysis of other methods of Geni inference machine

The first approach is to use the VIP's own debugger. The use of difficult, but the process trivial, the horizon is small, the effect is limited.

I recommend a way. Mainly talk about concrete operation, the truth is not much verbose.

(1), start the Apache server;

(2), in the browser, open the http://localhost/default.htm

(3), drop-down box check animal

(4), button: Select problem

(5), after the page appears, the button: Yes

(6) Until the page appears: "I think the answer Is:cheetah", and the cheetah image

(7), right click on the mouse, click: "View page source code", the following "variable" can be seen:

<input type= "hidden" name= "Knowledgebase"  value= "Animal" ><input type= "hidden" name= "Cond_12"  Value= "yes" ><input type= "hidden" name= "cond_13"  value= "yes" ><input type= "hidden" name= "cond_15"  value= "yes" ><input type= "hidden" name= "cond_1"  value= "yes" ><input type= "hidden" name= "Cond_2"  value= "Yes" >

As described in the previous sections, these variable values are known to be initialized before the inference machine is run and into the fact base:

KB (animal), Yse (1), Yse (2), Yse (All), Yse (), Yse ()

With these preconditions and factual basis, we can open geni.peo and begin to observe and analyze the operation of Geni inference machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.