Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Both sides previous revision Poprzednia wersja
Nowa wersja
Poprzednia wersja
pl:dydaktyka:dss:rules:intro [2017/11/28 14:05]
msl [Download]
pl:dydaktyka:dss:rules:intro [2019/06/27 15:50] (aktualna)
Linia 2: Linia 2:
  
 ===== Download ===== ===== Download =====
-Please download the following files containg ​simple knowledge bases about a family:+Please download the following files containing ​simple knowledge bases about a family:
   * CLIPS file: {{ :​pl:​dydaktyka:​dss:​rules:​family_en.clp.zip |}}   * CLIPS file: {{ :​pl:​dydaktyka:​dss:​rules:​family_en.clp.zip |}}
   * Prolog file: {{ :​pl:​dydaktyka:​dss:​rules:​family_en.pl |}}   * Prolog file: {{ :​pl:​dydaktyka:​dss:​rules:​family_en.pl |}}
-  * Manual for CLIPS: [[http://​clipsrules.sourceforge.net/​documentation/​v630/​bpg.htm|version online]]+  * Manual for CLIPS: ​{{:​pl:​dydaktyka:​rules:​lab:​labs:​bpg.pdf|Basic Programming Guide}}, ​[[http://​clipsrules.sourceforge.net/​OnlineDocs.html|version online]]
  
 ===== Knowledge Bases ===== ===== Knowledge Bases =====
Linia 18: Linia 18:
 Defining deffacts: initial-facts Defining deffacts: initial-facts
 Defining defrule: child +j Defining defrule: child +j
-TRUE </ code> The ** TRUE ** is the most important part of this feedback. If ** FALSE ** appears, it means that loading failed.+TRUE </​code>​ The ** TRUE ** is the most important part of this feedback. If ** FALSE ** appears, it means that loading failed.
   * Prolog: <​code>​ [family]. </​code>​ The succesful loading should display something similar to: <​code>​   * Prolog: <​code>​ [family]. </​code>​ The succesful loading should display something similar to: <​code>​
 % family compiled 0.01 sec, 9,232 bytes % family compiled 0.01 sec, 9,232 bytes
Linia 94: Linia 94:
   * This rule will cause the inference to omit the childless couples. In order to define the proper notion of **marriage**,​ KB would have to be supplemented with additional facts (what facts?)   * This rule will cause the inference to omit the childless couples. In order to define the proper notion of **marriage**,​ KB would have to be supplemented with additional facts (what facts?)
  
-=== 5.1.3. ​Siblings ​===+=== 5.1.3. ​Other ===
 Knowing that the concepts **brother** is defined as follow: Knowing that the concepts **brother** is defined as follow:
   * CLIPS: <​code>​   * CLIPS: <​code>​
Linia 107: Linia 107:
   siblings(X, Y),   siblings(X, Y),
   man(X).</​code>​   man(X).</​code>​
-Define ​two additional ​rules: +Define ​the following ​rules: 
-  * "siblings(X, Y)" ​--- two different people with a common parent +  * siblings(X,​Y) --- two different people with a common parent;  
-  * "sister(X,​Y)"​+    * tip: ** (test (neq ?x ?y)) ** checks inequality of variables. 
 +    * question: why do you have to use ** test ** keyword? 
 +  * sister(X,Y) 
 +  * grandfather(X,​Y) 
 +  * grandmother(X,​Y) 
 +  * grandparent(X,​Y) --- tip: use ** OR ** 
 +  * cousins(X,​Y) --- two different people with a common grandparent. You can check this rule in Prolog with a query: <​code>​cousins(X,​Y),​ parent(R,​X),​ parent(R, Y)</​code>,​ it should return **false** 
 +    * remember: siblings are not cousins!  
 +  * aunt(X,Y) and uncle(X,Y) in terms of sister, brother and parent. 
 +  * half-orphan(X) --- a person with only one parent. TIP: celina is the only half-orphan in the KB 
 +  * widow(X) (and widower(X)) --- assume that all the single-parents are single because of the spouse'​s death. TIP: tobiasz is the only widower in the KB, there are no widows. In CLIPS you may check results of the following rule: <​code>​ 
 +(defrule widower 
 + ... 
 +=> 
 + ​(assert (widower ?x)) 
 + ​(printout t ?x " ​is widower"​ crlf) 
 +)</​code>​. Do you get the expected result? 
 + 
 +===== 6. Tracking the execution of the program ===== 
 +Since CLIPS doesn'​t correctly find the widowers, it is necessary to track the execution of the program: 
 + 
 +=== 6.1. Tracking the facts ===== 
 +Allows you to track operations on facts: add, delete, change of the value. 
 +  - In the first step, we will start observing the **widower** rule to see what triggers it: <​code>​ (watch rules widower) </​code>​ 
 +  - We reset the fact base: <​code>​ (reset) </​code>​ 
 +  - Restart the inference: <​code>​ (run) </​code>​ 
 +  - Now we see the triggers and indexes of facts from which we started. 
 +  - Now check which fact triggered the inference: <​code>​(facts)</​code>​ 
 + 
 +===== 6.2. Rule tracking ===== 
 + 
 +Allows tracking of rules: firing, activation. 
 +  - Because we did learn nothing interesting tracing the fact, we will follow the **widow** rule and all the rules it depends on: **parent**, **marriage**:​ <​code>​ 
 +(unwatch all) 
 +(watch rules marriage widow parent) 
 +</​code>​ 
 +  - Now we reset the fact base: <​code>​ (reset) </​code>​ 
 +  - Restart the inference: <​code>​ (run) </​code>​ 
 +  - What is the reason behind the malfunction of the **widower** rule? 
 +  - How can we fix it? 
 + 
 +=== 6.3. Tracking in Prolog ===== 
 +Prolog allows you to follow the program. To do so, you set the so-called. trace point. 
 + 
 +Trace points: 
 +  * ''​trace/​0''​ - sets the trace point on all predicates, eg: 
 +<​code>​ 
 +?- trace, woman(K), parent(K, _). 
 +</​code>​ 
 +  * **trace/1** - sets the trace point at the indicated predicate,​ 
 +  * **trace/2** - modifies trace point of the specific events (call, redo, exit, fail), eg: 
 +    * remove the trace point from the specified predicate //​something/​1//​ <​code>​ trace(something/​1,​ -all) </​code>​ 
 +    * set a trace point tracking only calls to the specified predicates //​something//​ of arbitrary arity. <​code>​trace(something,​ call +)</​code>​ 
 +  * Predicate ''​debugging/​0''​ lists all the set trace points. 
 +  * The ''​debug/​0''​ predicate activates debug mode. 
 +  * Predicate ''​nodebug/​0''​ disactivates debug mode. 
 + 
 +Check following code: 
 +<​code>​ 
 +?- trace(parent). 
 +[debug] ?- trace(mother). 
 +[debug] ?- trace(father) 
 +[debug] ?- parent(dariusz,​ tomasz). 
 +[debug] ?- nodebug. 
 +</​code>​
pl/dydaktyka/dss/rules/intro.1511874316.txt.gz · ostatnio zmienione: 2019/06/27 15:57 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0