The core of Geni--Inference machine (1) Knowledge representation
The last sentence of the goal paragraph is the clause infer (), which implies "reasoning".
Thus, enter the core of the Geni and look at the operation of the inference machine.
Infer ()
Infer ():-topic (Maingoal,_), Go ([],maingoal, ""),!. Infer ():-errorexit.
Topic (maingoal,_)
Topic existing in the fact base Geni, take out the Maingoal = "Animal",
See the "Visual Prolog Web Expert system (4)" For more information.
If you follow the previous sections of the parser, you should now start with the predicate go ([],maingoal, "").
I tried to walk again, and finally, I found no.
The reason is that the amount of code of the inference machine is more than the sum of the previous sections;
The way of processing knowledge data is much more complicated;
It is much more difficult to accurately analyze the program logic and running process.
Therefore, some basic preparatory work must be done to make clear the whole situation of knowledge data of inference machine.
Figure out the logic of the inference machine, the characteristics of its operating mechanism, and the usage of some VIP built-in predicates.
Therefore, the problem of inference machine is decomposed into 4 subsections: Knowledge representation, Process control, built-in predicate and external predicate, and routine analysis.
Today, the 1th section begins.
First, the Prolog knowledge expression
The basic structure of the Prolog program is "fact + rule", or "knowledge + control".
Unlike procedural procedures, descriptive Prolog, knowledge (data) and control seamless.
This is shown in 2 ways:
1. How to express knowledge
Prolog mainly use the fact base to express knowledge, or you can use predicate clauses to express knowledge.
Using the fact base to express knowledge
A fact base, a repository, can be seen as one thing.
A fact base is a knowledge base that is defined inside a program, and a repository of facts that exists outside the program.
Take the Knowledge base Animal.gni as an example to see its contents:
Rule (1, "Carnivore", "Cheetah", [up], "animals\\cheetah.htm") rule (2, "Carnivore", "Tiger", [1,3], " "Rule (6," Bird "," Penguin ", [9,10,8]," ") Rule (7, "Bird", "Albatross", [one], "animals\\albatros.htm") rule (8, "Animal", "mammal", [12,13], "") Rule (9, "Animal", " Bird ", [9,14]," ") Rule (Ten," Mammal "," carnivore ", [[]," ") Rule (one," mammal "," ungulate ", [+]," ") Cond (1," it has tawny Color "," animals\\animals.htm ") Cond (2," It has dark spots "," animals\\animals.htm ") Cond (3," It had black stripes "," Animals\\animals.htm ") Cond (4," it has a long neck "," animals\\giraffe.htm ") Cond (5," It has long legs "," ") Cond (" It eats meat "," animals\\meateat.htm ") cond (" It does chew cud "," animals\\ Animals.htm ") Topic (" Animal "," I'll try to guess which animal you is thinking of ") Default_startpage (" animal.htm ")
Geni uses the built-in predicate consult to load them into the fact base, and "knowledge" becomes "fact".
Expressing knowledge with predicate clauses
For example:
Cheetah:-Mammal, Carnivore, Has_tawny_color,has_dark_spots.tiger:-Mammal, Carnivore,has_tawny_color, Has_ Black_stripes.
Expert system shell
Separate the specific knowledge from the program code, and create an independent knowledge base,
This design structure of the expert system, called "expert system shell."
Geni is this "expert system shell", but the function is relatively simple.
Design expert system, should adopt this "shell + Knowledge Base" structure.
2. Knowledge and control are predicates
Not only "control" predicate can express knowledge, knowledge can also control program.
"Fact", as an informative predicate, directly participates in and influences the direction of program operation.
This question will be discussed in detail in the next section.
Ii. knowledge reserves of the Geni fact base
As described in the previous sections, CGI data processing becomes knowledge and is stored in the internal fact base.
Now, the "inventory" situation in the fact base should be clarified.
1. Static data (knowledge, facts)
This includes the entire contents of the Knowledge base name and Animal.gni.
Briefly analyze the knowledge representation of Knowledge Base Animal.gni.
The meaning of rule
For example, rule (1, "Carnivore", "Cheetah", [up], "animals\\cheetah.htm")
Rule (number, large class (or small Class), small class (or animal name), [condition established by this rule], interpretation of this rule)
The meaning of cond
For example, cond ("It eats meat", "animals\\meateat.htm")
This means: Cond (number, ask the user for questions, tips for asking)
The meaning of topic
Topic ("Animal", "I'll try to guess which animal you is thinking of")
Meaning: Topic (subject, interpretation of the subject)
Rule is a "tree" relationship, subject animal is the root node, but also the starting point of the inference machine work.
Conditions are independent of each other, cond, there is no connection.
2. Dynamic Data (user's answer)
When the network is transmitted, its shape is cond_x,x is the number.
The form in the fact library is yes (x), or no (x).
3. Special Data Whymeet
When the user is in the browser button "Why", it is transmitted to the Geni,
Geni According to this requirement, explain to the user the reason for asking a question.
Whymeet is an operational command that does not participate in the reasoning process.
But static and dynamic knowledge, is the element of reasoning.