forked from apache/incubator-kie-drools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DROOLS-6271 Drools phreak rete diagram (apache#3530)
* Initial commit * Print nodes by layer to try align left the LIA. * clean. * prepare for unknown nodes. * le bug correction. * Collecting at level 1-5 all the required nodes. * MANUAL experiment for subnetwork. * Trying to collate as possible the subnetwork. * Fixing breaking when complex subnetwork although same level nodes. * Fixing beta node constraints and classpath problems. * fixes. * Avoiding problem when using as a dependency (until merged upstream). * comsmetics on the not display. * with partitioning instead of vertical layering. * Still trying to merge the 2 approaches, for now it's a switch b/w them. * with the files. * Moar tests * latest imgs. * wrong loop nesting. * renaming to diagramRete() * Clean-up. * Adding browser FIREFOX, tested works. * Aligning with DROOLS-1024. * print debug vertical cluster flag in configuration * bugfix * oops commit * Bump junit from 4.12 to 4.13.1 (#1) Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](junit-team/junit4@r4.12...r4.13.1) Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * realign * Migrate to graphviz-java * Use platform agnostic open file * main refactors without package renames * Refactor naming and package to drools-retediagram as agreed * subdir drools-retediagram * move into drools-retediagram * wire module into the build * dependency mgt * update logback for proper package Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6ab1c79
commit 5dacbf5
Showing
13 changed files
with
1,553 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/target | ||
/local | ||
|
||
# Eclipse, Netbeans and IntelliJ files | ||
/.* | ||
!.gitignore | ||
/nbproject | ||
/*.ipr | ||
/*.iws | ||
/*.iml | ||
|
||
# Repository wide ignore mac DS_Store files | ||
.DS_Store | ||
|
||
# generated files | ||
dependency-reduced-pom.xml | ||
|
||
# these modules don't exist anymore on master | ||
/drools-clips/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# drools-retediagram | ||
|
||
An experiment to plot Rete diagram, similar to `ReteDumper`, using Dot language format. | ||
|
||
## Usage | ||
|
||
To plot the diagram files for a Knowledge Base of a given `KieSession` using the defaults: | ||
|
||
```java | ||
ReteDiagram.newInstance().diagramRete(kieSession); | ||
``` | ||
|
||
It is possible to change some settings and formatting, as in the following example: | ||
|
||
```java | ||
ReteDiagram.newInstance() | ||
.configLayout(Layout.PARTITION) // use Partition layout, instead of default Vertical layout | ||
.configFilenameScheme(new File("./target"), true) // set output directory manually instead of OS default for temporary directory | ||
.configOpenFile(true, false) // automatically open SVG file with OS default application | ||
.diagramRete(kieSession); | ||
``` | ||
|
||
Please notice to leverage the OS capability to automatically open file with the default application, it is required that the JVM property `java.awt.headless` but be `false`, which can be set manually with: | ||
|
||
```java | ||
System.setProperty("java.awt.headless", "false"); | ||
``` | ||
|
||
## Example: simple KB plotted with default Vertical layout | ||
|
||
Given the following rules in the Knowledge Base: | ||
|
||
``` | ||
rule "For color" | ||
no-loop | ||
when | ||
Measurement( id == "color", $colorVal : val ) | ||
then | ||
controlSet.add($colorVal); | ||
end | ||
rule "Likes cheddar" | ||
when | ||
Cheese( $cheddar : name == "cheddar" ) | ||
$person : Person( favouriteCheese == $cheddar ) | ||
then | ||
System.out.println( $person.getName() + " likes cheddar" ); | ||
end | ||
rule "Don't like cheddar" | ||
when | ||
Cheese( $cheddar : name == "cheddar" ) | ||
$person : Person( favouriteCheese != $cheddar ) | ||
then | ||
System.out.println( $person.getName() + " does not like cheddar" ); | ||
end | ||
rule "Color count" | ||
when | ||
accumulate( $m: Measurement( id == "color" ); $c: count($m) ) | ||
then | ||
System.out.println( $c ); | ||
end | ||
rule "Not a Color" | ||
when | ||
not ( Measurement( id == "color" ) and String() ) | ||
then | ||
System.out.println( "no color yet." ); | ||
end | ||
``` | ||
|
||
The diagram plotted with the defaults settings and Vertical layout: | ||
|
||
```java | ||
ReteDiagram.newInstance().diagramRete(kieSession); | ||
``` | ||
|
||
is rendered as: | ||
|
||
![example1](example1.png) | ||
|
||
the diagram displays the default entry point, Object Type nodes, Alpha nodes, Left Input Adapter nodes, join Beta nodes, etc. down to Rule Terminal nodes. | ||
|
||
## Example: plotting Partition layout | ||
|
||
Given the following rules in the Knowledge Base: | ||
|
||
``` | ||
rule R0 when | ||
$i : Integer( intValue == 0 ) | ||
String( toString == $i.toString ) | ||
then | ||
list.add($i); | ||
end | ||
rule R1 when | ||
$i : Integer( intValue == 1 ) | ||
String( toString == $i.toString ) | ||
then | ||
list.add($i); | ||
end | ||
rule R2 when | ||
$i : Integer( intValue == 2 ) | ||
String( toString == $i.toString ) | ||
then | ||
list.add($i); | ||
end | ||
rule R3 when | ||
$i : Integer( intValue == 2 ) | ||
String( length == $i ) | ||
then | ||
list.add($i); | ||
end | ||
``` | ||
|
||
The diagram plotted with the Partition layout: | ||
|
||
```java | ||
ReteDiagram.newInstance().configLayout(Layout.PARTITION).diagramRete(ksession); | ||
``` | ||
|
||
is rendered as: | ||
|
||
![example2](example2.png) | ||
|
||
The diagram displays nodes in their respective Partitions. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools</artifactId> | ||
<version>7.53.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>drools-retediagram</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>drools-retediagram</name> | ||
<description>Internal utility (EXPERIMENTAL) to plot Rete diagram, similar to `ReteDumper`, using Dot language format</description> | ||
<url>http://drools.org</url> | ||
|
||
<properties> | ||
<java.module.name>org.drools.retediagram</java.module.name> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>guru.nidi</groupId> | ||
<artifactId>graphviz-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-compiler</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-mvel</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-core</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-compiler</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.drools</groupId> | ||
<artifactId>drools-legacy-test-util</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId><!-- route dependencies using java util Logging to slf4j --> | ||
<artifactId>jul-to-slf4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.