jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
drools-legacy
  • drools-legacy
  • DROOLS-104

none XML groovy semantic

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Wish Wish
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: future
  • Component/s: io
  • Labels:
    None
  • Number of attachments :
    0

Description

Would be good to implement a none xml based language in groovy - current suggestion is:

rule myRule(Integer x, String y, Foo bean)
{
when

{ x > 100; bean.whatnot == "cheese"; }

then

{ retract(x); }

}

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Guillaume Laforge added a comment - 23/Jun/04 4:04 PM

This could be done quite easily in Groovy by creating your own "Builder", just like we did with AntBuilder, SwingBuilder or MarkupBuilder. The syntax would be almost as described as in this sample rule.

Here are a few classes in the groovy source tree that extend BuilderSupport to create similar functionalities:

The BuilderSupport class:
http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/util/BuilderSupport.java?rev=1.6&view=auto

The Swing builder
http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/swing/SwingBuilder.java?rev=1.7&view=auto

The Markup builder
http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/xml/MarkupBuilder.java?rev=1.7&view=auto

The Ant builder
http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/util/AntBuilder.java?rev=1.7&view=auto

Show
Guillaume Laforge added a comment - 23/Jun/04 4:04 PM This could be done quite easily in Groovy by creating your own "Builder", just like we did with AntBuilder, SwingBuilder or MarkupBuilder. The syntax would be almost as described as in this sample rule. Here are a few classes in the groovy source tree that extend BuilderSupport to create similar functionalities: The BuilderSupport class: http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/util/BuilderSupport.java?rev=1.6&view=auto The Swing builder http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/swing/SwingBuilder.java?rev=1.7&view=auto The Markup builder http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/xml/MarkupBuilder.java?rev=1.7&view=auto The Ant builder http://cvs.groovy.codehaus.org/groovy/groovy-core/src/main/groovy/util/AntBuilder.java?rev=1.7&view=auto
Hide
Permalink
Brian McCallister added a comment - 23/Jun/04 4:07 PM

Actually, thinking about groovy builders – the builder could just build the xml file, then we have xml, and convenient RuleBuilder =)

Show
Brian McCallister added a comment - 23/Jun/04 4:07 PM Actually, thinking about groovy builders – the builder could just build the xml file, then we have xml, and convenient RuleBuilder =)
Hide
Permalink
Guillaume Laforge added a comment - 30/Jun/04 6:30 PM

I think we could come up with a syntax close to this:

builder = new GroovyRuleSetBuilder()

builder.ruleset {
rule(name: "MyName", salience:10) {
parameters [
"int x", "Foo bean"
]
conditions [
"x > 100",
"bean.whatnot == "cheese"
]
consequence [
action:

{ System.out.println("consequence") }

]
}
}

Show
Guillaume Laforge added a comment - 30/Jun/04 6:30 PM I think we could come up with a syntax close to this: builder = new GroovyRuleSetBuilder() builder.ruleset { rule(name: "MyName", salience:10) { parameters [ "int x", "Foo bean" ] conditions [ "x > 100", "bean.whatnot == "cheese" ] consequence [ action: { System.out.println("consequence") } ] } }
Hide
Permalink
Mark Proctor added a comment - 12/Apr/05 8:08 AM

Was chatting to jstrachan today about where drools-groovy should be heading. He said that GroovyInterp is ok for the xml stuff we currently have and showed us some none-xml exmaples:

This example uses closures:
class RuleSet extends RuleSetSupport {
void loadRuleSet() {
with (rule("Cheese")) {
parameter("hello", String.class)
parameter("foo", int.class)

condition

{ hello -> hello.startsWith("foo") }

condition

{ hello, foo -> foo != hello }

consequence { hellow, foo ->
for (x in 1..100)

{ doSomething(hello, x) }
}
}
}

Closures with bean properties:
class RuleSet extends RuleSetSuport {
void loadRuleSet() {
with (rule("Cheese")) {
@Property String hello
@Property int foo

condition { hello.startsWith("foo") }
condition { foo != hello }

consequence {
for (x in 1..100) { doSomething(hello, x) }

}
}

String doSomething(x, y)

{ println "Hey $x how are you $y" }
}

String doSomething(x, y) { println "Hey $x how are you $y" }

}

Using a Map:
RuleSet ruleSet = new RuleSet()

ruleSet.addRule(
name : "Cheese"
parameters :
[
hello : String.class,
foo : int.class
],
conditions :

{ it.hello.startsWith("foo")}
consequence: { println "Hey" }
)

ruleSet.addRule(
name : "Cheese"
parameters :
[
hello : String.class,
foo : int.class
],

// multiple conditions
conditions :
[
{ it.hello.startsWith("foo")}

,

{ it.foo != it.bar }

]
consequence :

{ println "Hey" }


)

when groovy has inner class support it can do:
import org.drools.*

// assuming we had inner class support...
RuleBase ruleBase = [

new Rule("Cheese") {
@Property String hello
@Property int foo

void loadConditions() {
condition

{ hello.startsWith("foo") }
condition { foo != hello }
}

void consequence() { // whatever }

// arbitrary helper methods
String doSomething(x, y) { println "Hey $x how are you $y" }
},

new Rule("Beer") {
@Property long y = 1234

void loadConditions() {
condition { foo != hello }
}

void consequence() { // whatever }
},
]

or
import org.drools.*

// assuming we had inner class support...
RuleBase ruleBase = new RuleBase()

ruleBase.add new Rule("Cheese") {
@Property String hello
@Property int foo

void loadConditions() {
condition { hello.startsWith("foo") }

condition

{ foo != hello }
}

void consequence() { // whatever }

// arbitrary helper methods
String doSomething(x, y) { println "Hey $x how are you $y" }
}

ruleBase.add new Rule("Beer") {
@Property long y = 1234

void loadConditions() {
condition { foo != hello }

}

void consequence()

{ // whatever }

}

Show
Mark Proctor added a comment - 12/Apr/05 8:08 AM Was chatting to jstrachan today about where drools-groovy should be heading. He said that GroovyInterp is ok for the xml stuff we currently have and showed us some none-xml exmaples: This example uses closures: class RuleSet extends RuleSetSupport { void loadRuleSet() { with (rule("Cheese")) { parameter("hello", String.class) parameter("foo", int.class) condition { hello -> hello.startsWith("foo") } condition { hello, foo -> foo != hello } consequence { hellow, foo -> for (x in 1..100) { doSomething(hello, x) } } } } Closures with bean properties: class RuleSet extends RuleSetSuport { void loadRuleSet() { with (rule("Cheese")) { @Property String hello @Property int foo condition { hello.startsWith("foo") } condition { foo != hello } consequence { for (x in 1..100) { doSomething(hello, x) } } } String doSomething(x, y) { println "Hey $x how are you $y" } } String doSomething(x, y) { println "Hey $x how are you $y" } } Using a Map: RuleSet ruleSet = new RuleSet() ruleSet.addRule( name : "Cheese" parameters : [ hello : String.class, foo : int.class ], conditions : { it.hello.startsWith("foo")} consequence: { println "Hey" } ) ruleSet.addRule( name : "Cheese" parameters : [ hello : String.class, foo : int.class ], // multiple conditions conditions : [ { it.hello.startsWith("foo")} , { it.foo != it.bar } ] consequence : { println "Hey" } ) when groovy has inner class support it can do: import org.drools.* // assuming we had inner class support... RuleBase ruleBase = [ new Rule("Cheese") { @Property String hello @Property int foo void loadConditions() { condition { hello.startsWith("foo") } condition { foo != hello } } void consequence() { // whatever } // arbitrary helper methods String doSomething(x, y) { println "Hey $x how are you $y" } }, new Rule("Beer") { @Property long y = 1234 void loadConditions() { condition { foo != hello } } void consequence() { // whatever } }, ] or import org.drools.* // assuming we had inner class support... RuleBase ruleBase = new RuleBase() ruleBase.add new Rule("Cheese") { @Property String hello @Property int foo void loadConditions() { condition { hello.startsWith("foo") } condition { foo != hello } } void consequence() { // whatever } // arbitrary helper methods String doSomething(x, y) { println "Hey $x how are you $y" } } ruleBase.add new Rule("Beer") { @Property long y = 1234 void loadConditions() { condition { foo != hello } } void consequence() { // whatever } }
Hide
Permalink
Mark Proctor added a comment - 12/Apr/05 8:09 AM

For AST analysis to help with node sharing jstrachan pointed to two exmaple:
http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/groovy-core/src/main/groovy/sql/SqlWhereVisitor.java?r=HEAD
http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/groovy-core/src/main/groovy/sql/DataSet.java?r=HEAD

Show
Mark Proctor added a comment - 12/Apr/05 8:09 AM For AST analysis to help with node sharing jstrachan pointed to two exmaple: http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/groovy-core/src/main/groovy/sql/SqlWhereVisitor.java?r=HEAD http://cvs.groovy.codehaus.org/viewrep/groovy/groovy/groovy-core/src/main/groovy/sql/DataSet.java?r=HEAD
Hide
Permalink
Michael Neale added a comment - 14/Jun/05 4:42 AM

Will this become the lingua franca of drools?

Is the aim for this to be the "native" language for drools execution - and will all other languages eventually compile/translate to this?

A unifiorm language would be handy, and inline with other rule engines. It also makes life easier for those of us who are making value added tools that emit rule language.

Will using groovy impact perforance at all? Will there still be the opportunity to have janino/eclipse equivalent compile to bytecode as needed?

Show
Michael Neale added a comment - 14/Jun/05 4:42 AM Will this become the lingua franca of drools? Is the aim for this to be the "native" language for drools execution - and will all other languages eventually compile/translate to this? A unifiorm language would be handy, and inline with other rule engines. It also makes life easier for those of us who are making value added tools that emit rule language. Will using groovy impact perforance at all? Will there still be the opportunity to have janino/eclipse equivalent compile to bytecode as needed?

People

  • Assignee:
    Unassigned
    Reporter:
    Mark Proctor
Vote (1)
Watch (2)

Dates

  • Created:
    23/Jun/04 3:20 PM
    Updated:
    14/Jun/05 4:42 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.