Web expert system for Visual Prolog (9)

Source: Internet
Author: User
Tags knowledge base

The core of Geni--Inference Machine (3) some predicates

In order to focus attention and better analyze the core program of Geni inference machine, we should do some preparatory work to understand some verb functions of auxiliary function.

Is_htmlfile (RULEXPL)
  Is_htmlfile (FILE):-  Filenameext (file,_name,mask),  Mask = ". htm",!.  Is_htmlfile (FILE):-  Filenameext (file,_name,mask),  Mask = ". html",!.

If file's extension is ". htm", or ". html", the predicate succeeds. otherwise failed.

Consult_htm (Rulexpl,htmltext)
  Consult_htm (Filename,htmltekst):-syspath (Exestartuppath,_progname), Filenamepath (Fullname,exestartuppath, FileName), Trap (FILE_STR (Fullname,htmltekst), _,writef ("file% is not found! Correct problem!\n ", FullName)),!.  Consult_htm (_, ""):-        errorexit.

Reads the contents of the HTML file into the variable htmltekst, "return", according to the specified path and file name.

If clause 1 goes wrong, the error exits after the clause 2 is traced.

Gethtmlbody (Htmltext,bodytext)
  Gethtmlbody (text,body):-  Upper_lower (Text,lowertext), SearchString (Lowertext, "<body", LEN1), Frontstr (LEN1 , Lowertext,_,txt1), SearchChar (TXT1, ' > ', body_tag_len), startpos = Len1+body_tag_len+1,searchstring (LOWERTEXT, " </body> ", endpos), LEN = endpos-startpos,substring (text,startpos,len,body),!.  Gethtmlbody (_, ""):-errorexit.

Describes the following predicates:

Upper_lower (Text,lowertext)
VIP built-in predicate. Flow mode (i, I), (i, O), (o, i) upper_lower (string uppercase, String lowercase) upper_lower (char uppercase, char lowercase) for uppercase The characters (strings), and the lowercase characters (strings) are converted to each other
SearchString (Lowertext, "<body", LEN1)
VIP built-in predicate. Flow mode (i, I, O) searchstring (string sourcestr, String searchstr, UNSIGNED Position) determines the position of one end of a substring in a string
SUBSTRING (text,startpos,len,body)
VIP built-in predicate. Stream mode (i, I, I, O) ubstring (string Source, UNSIGNED Pos, UNSIGNED Len, string part) returns a portion of the string (substring) specified in the

Clause gethtmlbody (Text,body), from the string TEXT, keying out the substring BODY,
The algorithm is clear and intuitive, without elaborating.

EndPage ("")
EndPage (""):-!, write_kb,write_conditions, Write ("<Center>"), Write ("<font size=+6 ><i>&lt ; B> "), Write (" </Center> "), Write (" </font>\n "), Write (" </body>\n "), writ   E ("write ("<input type=\" hidden\ "name=\" Answer\ "value=\" yes\ ">\n"),Percent of this sentence is useless, can delete write ("<p><input type=\" submit\ "value=\" yes\ ">\n"), Writef ("<input type=\" button\ "value =\ "no\" onclick=\ "form.%s.value= ' No '; submit () \" >\n ", CONDITION), Writef (" <input type=\ "button\" value=\ "why\" Onclick=\ "form.%s.value= ' why '; submit () \" >\n ", CONDITION), Writef (" </form>\n "),%<form action=\"/ Geni.htm\ ">\n"), Write ("</p></form>\n"), Write ("</font>\n"), Write ("</body&gt ; \ n "), write (" 

2 predicates write_kb and write_conditions are called in EndPage.

write_kb
  WRITE_KB:-KB (KB),!, Writef ("<input type=\" hidden\ "name=\" knowledgebase\ "  value=\"%s\ ">\n", KB).  Write_kb:-errorexit ().

KB is the fact library predicate, the current kb= "Animal", which represents the name of the Knowledge base

In the CGI mode, the variables required by the program are transmitted on each page. Here's the Writef, is doing this thing.

Write_conditons
  Write_conditions:-yes (CNO), Format (CONDITION, "cond_%", CNO), Writef ("<input type=\" hidden\ "name=\"%s\  " Value=\ "Yes\" >\n ", CONDITION), fail.  Write_conditions:-no (CNO), Format (CONDITION, "cond_%", CNO), Writef ("<input type=\" hidden\ "name=\"%s\ "  value =\ "no\" >\n ", CONDITION), fail.  Write_conditions.

Say a little bit about this predicate.

Yes (CNO) and no (CNO) are fact-base predicates that represent the user's affirmative or negative answer to the question CNO (condition). Format (CONDITION, "cond_%", CNO) is the VIP built-in predicate. Format (string outputstring, String FormatString, Arg1, Arg2, ..., ArgN) flow mode (o, I, I, I, I ...), formatting multiple parameters as the result of the string in this example (assuming cno=5) Yes: CONDITION = "Cond_5"
Not (rule (_,mygoal,_,_,_))
VIP built-in predicate, flow mode (i), for logical non-operation. If rule (_,mygoal,_,_,_) is not in the fact library, not (rule (_,mygoal,_,_,_)) is true; otherwise it is false.
Check (rno,history, COND)

The 3rd and 4th clauses of this predicate ( Red part ) are currently not useful and can be deleted.

  Check (RNO, history, [cno| REST]):-yes (CNO),!, check (RNO, History, REST).  Check (_, _, [Cno|_]):-no (CNO),!, fail.   Check (RNO, history, [cno| REST]):-cond (cno,ncond,options), Fronttoken (Ncond, "not", _cond), Frontchar (_cond,_,cond), cond (Cno1,cond,options), Notest (CNO1),!, check (RNO, History, REST).  Check (_,_, [cno|_]):-cond (cno,ncond,options), Fronttoken (Ncond, "not", _cond), Frontchar (_cond,_,cond), cond (CNO1, cond,options), yes (CNO1),!, fail.  Check (RNO, history, [cno| REST]):-cond (cno,text,options),!, inpq (history,rno,cno,text,options), check (RNO, History, REST).  Check (_, _, []).

The 3rd 4th clause of the check, the object that is processed, is the predicate in the Knowledge base cond (number, asking question, hint).

If the "asked question" is preceded by "not", the 3rd 4th clause of the check will be processed accordingly.

However, the "asked question" does not begin with "not", and the 3rd 4th clause of the check is of no practical use.

Similarly, the check of the 4th clause of the Notest (CNO1), also no use, can be deleted together.

Notest (CNO1)
Notest (CNO):-no (CNO),!.  Notest (CNO):-not (yes (CNO)),!.

The above "useless" clauses can be commented out from the Geni.pro code and compiled and run for validation.

This section has a lot of content, but did not mention the important function of the expert system-the treatment of why problem.

The treatment of why problem, more complex, add a section, specifically said.

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.