File tree Expand file tree Collapse file tree
resources/com/baeldung/drools/backward_chaining Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?xml version =" 1.0" encoding =" UTF-8" ?>
22<project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
33 xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4-
54 <modelVersion >4.0.0</modelVersion >
65
76 <artifactId >drools-backward-chaining</artifactId >
1716 <properties >
1817 <runtime .version>6.4.0.Final</runtime .version>
1918 </properties >
20-
2119 <dependencies >
2220 <dependency >
2321 <groupId >org.kie</groupId >
2624 </dependency >
2725 <dependency >
2826 <groupId >org.drools</groupId >
29- <artifactId >drools-core</artifactId >
3027 <version >${runtime.version} </version >
3128 </dependency >
3229 <dependency >
3532 <version >${runtime.version} </version >
3633 </dependency >
3734 </dependencies >
38- </project >
35+ </project >
Original file line number Diff line number Diff line change @@ -21,13 +21,11 @@ public Result backwardChaining() {
2121 KieSession ksession = kContainer .newKieSession ("ksession-backward-chaining" );
2222 ksession .setGlobal ("result" , result );
2323 ksession .insert (new Fact ("Asia" , "Planet Earth" ));
24- // ksession.insert(new Fact("China", "Asia"));
24+ // ksession.insert(new Fact("China", "Asia"));
2525 ksession .insert (new Fact ("Great Wall of China" , "China" ));
2626
2727 ksession .fireAllRules ();
2828
2929 return result ;
30-
3130 }
32-
3331}
Original file line number Diff line number Diff line change 1+ package com.baeldung
2+
3+ import com.baeldung.drools.model.Fact;
4+
5+ global com.baeldung.drools.model.Result result;
6+
7+ dialect "mvel"
8+
9+ query belongsTo(String x, String y)
10+ Fact(x, y;)
11+ or
12+ (Fact(z, y;) and belongsTo(x, z;))
13+ end
14+
15+ rule "Great Wall of China BELONGS TO Planet Earth"
16+ when
17+ belongsTo("Great Wall of China", "Planet Earth";)
18+ then
19+ result.setValue("Decision one taken: Great Wall of China BELONGS TO Planet Earth");
20+ end
21+
22+ rule "print all facts"
23+ when
24+ belongsTo(element, place;)
25+ then
26+ result.addFact(element + " IS ELEMENT OF " + place);
27+ end
Original file line number Diff line number Diff line change 77 <groupId >com.baeldung</groupId >
88 <artifactId >drools</artifactId >
99 <version >1.0.0-SNAPSHOT</version >
10+
11+ <packaging >pom</packaging >
1012
1113 <parent >
1214 <groupId >com.baeldung</groupId >
You can’t perform that action at this time.
0 commit comments