CsBalazsHungary
CsBalazsHungary

Reputation: 813

Complex decision system modified by user - Java

I have a problem and I would like to ask for alternatives on my existing technologies since the programmed feature would be complex and would be given to users, so it should be as simple as it can be on front-end. I need java based technology.

What I need to do: I am having a basic structure with lot of datas. These datas are mostly well written like Integers, Dates, Booleans etc, so things what can be compared easily.

I need to model decisions with batches of requirements which can be defined and altered by many sources like inner business processes and governmental laws.

So I am thinking to give a scripting ability to the users (most of them have university degrees, so some complexity is ok).
Let's see a simplified example.
Let A be a structure with the following.
A.budget - Integer
A.bankRelatedDebt - Integer
A.privateRelatedDebt - Integer
A.deadLine - Date
A.hasPermissionFromGovernment - Boolean
A.hasProblematicContracts - Boolean

I need rules to define to decide if the rule stands or falls, so I need boolean back.
Rule1: The budget is over 1 million EUR
Rule2: Has no problematic document or has a permission from government
Rule3: The deadline won't be in a month range.
Rule4: The overall debt (local + private) doesn't exceed 100.000 EUR

These rules could be hardcoded in other cases, but this has to be super-dynamic and based on given datas.

We have the options of drools and antlr I would need alternatives if you can mention. Or if you can mention technologies to avoid, that is helpful as well and welcomed, so I can avoid it.

Upvotes: 2

Views: 667

Answers (5)

BlackJoker
BlackJoker

Reputation: 3191

It's like strategy pattern,all different rules are different algorithm apply to the Context(A),algorithm can be selected at runtime.

Add a filter chain design pattern to that,so that you can choose different algorithms(rules) at the same time.

Roolie is a very simple java rule engine that meight be helpful for you .As Roolie says:

Roolie is an extremely simple Java Rule Engine (Non-JSR 94) that uses rules you create in Java. Simply create your basic rules, implement the single "passes" method for each, then chain them together in an XML file to create more complex rules.

Upvotes: 1

Ingo
Ingo

Reputation: 36339

If you had the records in a database, you could select the matching ones with SQL syntax.

For example:

SELECT * FROM data
    WHERE budget > 100000
      AND privatCredits < 50000

Upvotes: 0

Pablo Grisafi
Pablo Grisafi

Reputation: 5047

I would vote against drools because I have terrible experiences, but some people like it.
I would propose a language already integrated in java: JavaScript. Why?

  • Is simple enough and has nice access to java beans: instead of budget.getDealLine() you can use budget.deadLine
  • you have tons of places to check for information
  • you can add simple functions to make it more easy to use

But if you choose JavaScript, Python, Drools, ANTLR remember:

  • Users do not have version control systems like SVN/GIT, so it is up to you make it happen.
  • Give them a tool (a webpage or whatever) that automatically save every version of every script they wrote.
  • Give them a way to test what they wrote without damaging anything.
  • Give them tools to rollback whatever changes they made.
  • Make as much static tests as possible once they commit the code before executing it.
  • Syntax highlighting will make them happier.

And remember: they will use the tool in ways you don't expect, and you will end up writing (or rewriting) most of the scripts. No university degree means you can trust them to understand what they are doing. (Not even CS!)

So if you can make the system less dynamic, would be in your benefit

Upvotes: 1

Bruno Grieder
Bruno Grieder

Reputation: 29814

Develop a DSL for your needs using either Groovy or Scala.

We use CodeMirror to provide syntax highlighting in a web page. Works great for us with Groovy.

Upvotes: 1

Joop Eggen
Joop Eggen

Reputation: 109547

For what it's worth. I would love to do such an expert system too, so bear with my ramblings. First some negative points as you asked what to avoid.

There are many pitfalls.

The "programming" is done by the users, there probably is no version control system for restoral, there maybe is no staging system but one is working in the production system. Think of extending a common library rule test wise. No unit tests?

Then there is the user acceptance. Especially there is a competitor, Excel programming, which you have to supercede. Generating reports with human electable text blocks, diagrams.

Your nunbered rules still lack some life: the system could assist with providing categories to select from: Rule1 - restriction on monetary resource. Nice would be to propose "would you also like to restrict on limitited resources? (a) Rule1, (b) ... .

Also what is the product? What are the advantages? What are the goals? Reports, calculation scenarios (what-ifs, tolerances calculated through).

I certainly would first write a technical document along above lines, and than search the tools - as you seem to be doing. Drools is too basic. ANTLR for a DSL I find risky.

Tools

Data mining seems to be the keyword you are searching.

The JVM programming language Scala (not easily acquired), is productive for DSL, parsing. Many functional languages are a bit easier and offer scripting too (Java scripting API).

What about a web project, maybe using jetty as embedded web server. So you may apply HTML and JavaScript. HTML5?

A rich client platform (eclipse or NetBeans) requires experience for rapid development. For nice graphics, maybe JavaFX (too early).

Upvotes: 1

Related Questions