Re: [rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-04 Thread Toni Rikkola
If you take a look at the Verifier it goes through the Drools AST with a 
visitor pattern.
It starts by using getting the PackageDescr using DrlParser, this uses Drools 
internals so be warned that it might change in the future.

  Reader drlReader = new InputStreamReader( stream );
  PackageDescr descr = new DrlParser().parse( drlReader );

After that it goes through the PackageDescr using PackageDescrVisitor. 
RuleDescrVisitor shows how to get the condition part from each rule.

https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/PackageDescrVisitor.java
https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/RuleDescrVisitor.java

Toni


On Oct 3, 2011, at 8:11 PM, Mark Proctor wrote:

 On 03/10/2011 18:03, Wolfgang Laun wrote:
 A condition does not have a name, as you write; values of the cells
 below a condition are (usually) literals.
 
 There is no API for extracting parts of a spreadsheet. You can look at
 the Drools source code (in the packages org.drools.decisiontable and
 .../parser) and write whatever you need - it is not too difficult.
 You can also look at drools-verifier, as that shows ho to analyse 
 resulting rule fragments.
 
 Mark
 
 -W
 
 
 On 3 October 2011 17:05, RaviCKotaravi.k...@wellsfargo.com  wrote:
 Hi All, for suppose I have a DecisionTable like below
 
 CONDITION   ACTION
 -
 COND1 ACTION1
 COND2 ACTION2
 COND3 ACTION3
 -
 
 This is just a representation of the DecisionTable. So I need to retrieve
 all the conditions and store them into a Collection like Set. Does Drools
 provide any such feature.
 
 We load the drools as below
 PackageBuilder builder = new PackageBuilder();
 builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of
 decisiontable excel
 
 // add the package to a rulebase (deploy the rule package).
 RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 ruleBase.addPackage(builder.getPackage());
 
 I tried to look into api of RuleBase, tried to get the packages, Rules,
 Consequence, etc etc, but could not find any method, that gets me the
 condition name.
 
 When I tried to do
 Package[] packages = rulebase.getPackages();
 
 for(Package pack : packages){
 System.out.println(Package Name is : +pack.getName());
 Rule[] rules = pack.getRules();
 for(Rule rule : rules){
 System.out.println(Rule name is : +rule.getName());
 
 All I get is some representation of each row, but I'm specifically looking
 for the value of the first column (CONDITION) for each rule.
 
 Please offer some guidance here.
 
 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users
 
 
 
 
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-04 Thread Wolfgang Laun
Since Toni confirms me even before I post this on the list: Using the
Verifier way to get at a column from some spreadsheet is not for the faint
at heart. In addition to what Toni wrote: source code in the Drools AST
corner isn't even commented.
-W


2011/10/4 Toni Rikkola toni.rikk...@gmail.com

 If you take a look at the Verifier it goes through the Drools AST with a
 visitor pattern.
 It starts by using getting the PackageDescr using DrlParser, this uses
 Drools internals so be warned that it might change in the future.

   Reader drlReader = new InputStreamReader( stream );
   PackageDescr descr = new DrlParser().parse( drlReader );

 After that it goes through the PackageDescr
 using PackageDescrVisitor. RuleDescrVisitor shows how to get the condition
 part from each rule.


 https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/PackageDescrVisitor.java

 https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/RuleDescrVisitor.java

 Toni


 On Oct 3, 2011, at 8:11 PM, Mark Proctor wrote:

 On 03/10/2011 18:03, Wolfgang Laun wrote:

 A condition does not have a name, as you write; values of the cells

 below a condition are (usually) literals.


 There is no API for extracting parts of a spreadsheet. You can look at

 the Drools source code (in the packages org.drools.decisiontable and

 .../parser) and write whatever you need - it is not too difficult.

 You can also look at drools-verifier, as that shows ho to analyse
 resulting rule fragments.

 Mark


 -W



 On 3 October 2011 17:05, RaviCKotaravi.k...@wellsfargo.com  wrote:

 Hi All, for suppose I have a DecisionTable like below


 CONDITION   ACTION

 -

 COND1 ACTION1

 COND2 ACTION2

 COND3 ACTION3

 -


 This is just a representation of the DecisionTable. So I need to retrieve

 all the conditions and store them into a Collection like Set. Does Drools

 provide any such feature.


 We load the drools as below

 PackageBuilder builder = new PackageBuilder();

 builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of

 decisiontable excel


 // add the package to a rulebase (deploy the rule package).

 RuleBase ruleBase = RuleBaseFactory.newRuleBase();

 ruleBase.addPackage(builder.getPackage());


 I tried to look into api of RuleBase, tried to get the packages, Rules,

 Consequence, etc etc, but could not find any method, that gets me the

 condition name.


 When I tried to do

 Package[] packages = rulebase.getPackages();


 for(Package pack : packages){

 System.out.println(Package Name is : +pack.getName());

 Rule[] rules = pack.getRules();

 for(Rule rule : rules){

 System.out.println(Rule name is : +rule.getName());


 All I get is some representation of each row, but I'm specifically looking

 for the value of the first column (CONDITION) for each rule.


 Please offer some guidance here.


 --

 View this message in context:
 http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html

 Sent from the Drools: User forum mailing list archive at Nabble.com.

 ___

 rules-users mailing list

 rules-users@lists.jboss.org

 https://lists.jboss.org/mailman/listinfo/rules-users


 ___

 rules-users mailing list

 rules-users@lists.jboss.org

 https://lists.jboss.org/mailman/listinfo/rules-users





 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users



 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-04 Thread Swindells, Thomas
Looking at the SpreadsheetCompiler class you can do something like the following

/**
 * Generates DRL from the input stream containing the spreadsheet.
 *
 * @param xlsStream
 *The stream to the spreadsheet. Uses the first worksheet found
 *for the decision tables, ignores others.
 * @param type
 *The type of the file - InputType.CSV or InputType.XLS
 * @param listener
 *
 * @return DRL xml, ready for use in drools.
 */
public String compile(final InputStream xlsStream,
  final InputType type,
  final RuleSheetListener listener) {
final DecisionTableParser parser = type.createParser( listener );
parser.parseFile( xlsStream );
final Package rulePackage = listener.getRuleSet();

ListRule rules = rulePackage.getRules
for(Rule r : rules) {
r.getName();
ListCondition conditions = r.getConditions();
For(Condition c : conditions) {
String snippet = r.getSnippet();
}
}

final DRLOutput out = new DRLOutput();
rulePackage.renderDRL( out );
return out.getDRL();
}


Thomas
From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 04 October 2011 08:53
To: Rules Users List
Subject: Re: [rules-users] Is it possible to retrieve the collection of 
Conditions from DecisionTable?

Since Toni confirms me even before I post this on the list: Using the Verifier 
way to get at a column from some spreadsheet is not for the faint at heart. In 
addition to what Toni wrote: source code in the Drools AST corner isn't even 
commented.
-W

2011/10/4 Toni Rikkola toni.rikk...@gmail.commailto:toni.rikk...@gmail.com
If you take a look at the Verifier it goes through the Drools AST with a 
visitor pattern.
It starts by using getting the PackageDescr using DrlParser, this uses Drools 
internals so be warned that it might change in the future.

  Reader drlReader = new InputStreamReader( stream );
  PackageDescr descr = new DrlParser().parse( drlReader );

After that it goes through the PackageDescr using PackageDescrVisitor. 
RuleDescrVisitor shows how to get the condition part from each rule.

https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/PackageDescrVisitor.java
https://github.com/droolsjbpm/drools/blob/master/drools-verifier/src/main/java/org/drools/verifier/visitor/RuleDescrVisitor.java

Toni


On Oct 3, 2011, at 8:11 PM, Mark Proctor wrote:


On 03/10/2011 18:03, Wolfgang Laun wrote:

A condition does not have a name, as you write; values of the cells
below a condition are (usually) literals.

There is no API for extracting parts of a spreadsheet. You can look at
the Drools source code (in the packages org.drools.decisiontable and
.../parser) and write whatever you need - it is not too difficult.
You can also look at drools-verifier, as that shows ho to analyse
resulting rule fragments.

Mark


-W


On 3 October 2011 17:05, 
RaviCKotaravi.k...@wellsfargo.commailto:ravi.k...@wellsfargo.com  wrote:
Hi All, for suppose I have a DecisionTable like below

CONDITION   ACTION
-
COND1 ACTION1
COND2 ACTION2
COND3 ACTION3
-

This is just a representation of the DecisionTable. So I need to retrieve
all the conditions and store them into a Collection like Set. Does Drools
provide any such feature.

We load the drools as below
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of
decisiontable excel

// add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());

I tried to look into api of RuleBase, tried to get the packages, Rules,
Consequence, etc etc, but could not find any method, that gets me the
condition name.

When I tried to do
Package[] packages = rulebase.getPackages();

for(Package pack : packages){
System.out.println(Package Name is : +pack.getName());
Rule[] rules = pack.getRules();
for(Rule rule : rules){
System.out.println(Rule name is : +rule.getName());

All I get is some representation of each row, but I'm specifically looking
for the value of the first column (CONDITION) for each rule.

Please offer some guidance here.

--
View this message in context: 
http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html
Sent from the Drools: User forum mailing list archive at 
Nabble.comhttp://Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.orgmailto:rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users

___
rules-users mailing list

[rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-03 Thread RaviCKota
Hi All, for suppose I have a DecisionTable like below

CONDITION   ACTION
-
COND1 ACTION1
COND2 ACTION2
COND3 ACTION3
-

This is just a representation of the DecisionTable. So I need to retrieve
all the conditions and store them into a Collection like Set. Does Drools
provide any such feature.

We load the drools as below
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of
decisiontable excel

// add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(builder.getPackage());

I tried to look into api of RuleBase, tried to get the packages, Rules,
Consequence, etc etc, but could not find any method, that gets me the
condition name.

When I tried to do 
Package[] packages = rulebase.getPackages();

for(Package pack : packages){
System.out.println(Package Name is : +pack.getName());
Rule[] rules = pack.getRules();
for(Rule rule : rules){
System.out.println(Rule name is : +rule.getName());

All I get is some representation of each row, but I'm specifically looking
for the value of the first column (CONDITION) for each rule. 

Please offer some guidance here.

--
View this message in context: 
http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-03 Thread Wolfgang Laun
A condition does not have a name, as you write; values of the cells
below a condition are (usually) literals.

There is no API for extracting parts of a spreadsheet. You can look at
the Drools source code (in the packages org.drools.decisiontable and
.../parser) and write whatever you need - it is not too difficult.

-W


On 3 October 2011 17:05, RaviCKota ravi.k...@wellsfargo.com wrote:
 Hi All, for suppose I have a DecisionTable like below

 CONDITION               ACTION
 -
 COND1                     ACTION1
 COND2                     ACTION2
 COND3                     ACTION3
 -

 This is just a representation of the DecisionTable. So I need to retrieve
 all the conditions and store them into a Collection like Set. Does Drools
 provide any such feature.

 We load the drools as below
 PackageBuilder builder = new PackageBuilder();
 builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of
 decisiontable excel

 // add the package to a rulebase (deploy the rule package).
 RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 ruleBase.addPackage(builder.getPackage());

 I tried to look into api of RuleBase, tried to get the packages, Rules,
 Consequence, etc etc, but could not find any method, that gets me the
 condition name.

 When I tried to do
 Package[] packages = rulebase.getPackages();

 for(Package pack : packages){
 System.out.println(Package Name is : +pack.getName());
 Rule[] rules = pack.getRules();
 for(Rule rule : rules){
 System.out.println(Rule name is : +rule.getName());

 All I get is some representation of each row, but I'm specifically looking
 for the value of the first column (CONDITION) for each rule.

 Please offer some guidance here.

 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is it possible to retrieve the collection of Conditions from DecisionTable?

2011-10-03 Thread Mark Proctor
On 03/10/2011 18:03, Wolfgang Laun wrote:
 A condition does not have a name, as you write; values of the cells
 below a condition are (usually) literals.

 There is no API for extracting parts of a spreadsheet. You can look at
 the Drools source code (in the packages org.drools.decisiontable and
 .../parser) and write whatever you need - it is not too difficult.
You can also look at drools-verifier, as that shows ho to analyse 
resulting rule fragments.

Mark

 -W


 On 3 October 2011 17:05, RaviCKotaravi.k...@wellsfargo.com  wrote:
 Hi All, for suppose I have a DecisionTable like below

 CONDITION   ACTION
 -
 COND1 ACTION1
 COND2 ACTION2
 COND3 ACTION3
 -

 This is just a representation of the DecisionTable. So I need to retrieve
 all the conditions and store them into a Collection like Set. Does Drools
 provide any such feature.

 We load the drools as below
 PackageBuilder builder = new PackageBuilder();
 builder.addPackageFromDrl(new StringReader(drl)); //drl is the filepath of
 decisiontable excel

 // add the package to a rulebase (deploy the rule package).
 RuleBase ruleBase = RuleBaseFactory.newRuleBase();
 ruleBase.addPackage(builder.getPackage());

 I tried to look into api of RuleBase, tried to get the packages, Rules,
 Consequence, etc etc, but could not find any method, that gets me the
 condition name.

 When I tried to do
 Package[] packages = rulebase.getPackages();

 for(Package pack : packages){
 System.out.println(Package Name is : +pack.getName());
 Rule[] rules = pack.getRules();
 for(Rule rule : rules){
 System.out.println(Rule name is : +rule.getName());

 All I get is some representation of each row, but I'm specifically looking
 for the value of the first column (CONDITION) for each rule.

 Please offer some guidance here.

 --
 View this message in context: 
 http://drools.46999.n3.nabble.com/Is-it-possible-to-retrieve-the-collection-of-Conditions-from-DecisionTable-tp3390026p3390026.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users