Code Monkey home page Code Monkey logo

Comments (3)

maxant avatar maxant commented on September 25, 2024

Hi @richiesgr ,

For your problem, I would do something like this:

  1. add rules to engine
  2. for each input, run it against the engine to retrieve the matching rules.
  3. map each matching rule to a score
  4. sum the scores - that is the result for a single input
  5. repeat 2-4 for each input
  6. take the input which had the best result.

Code might look something like this:

static final Map<Rule, Integer> SCORES = new HashMap<>();
SCORES.put(rule1, 30);
SCORES.put(rule2, 50);
//etc...

int bestScore = Integer.MINIMUM;
Input bestInput = null;
for(Input i : inputs){
    List<Rule> matchingRules = engine.getMatchingRules(i);
    int score = matchingRules.toStream().map(r -> SCORES.get(r).sum();
    if(score > bestScore){
        bestScore = score;
        bestInput = i;
    }
}

//now use bestInput...

Would that satisfy your requirements?

from rules.

richiesgr avatar richiesgr commented on September 25, 2024

Of course it seems to be ok

my first question : it is not heavy to process like this ? I want to use it in low latency application based on Akka
Second question: is it thread safe at the engine level and MEVL itself? ( do I need to instanciate each time a new engine ?)

Thanks

from rules.

maxant avatar maxant commented on September 25, 2024

See DefaultEngineTest.testMultithreadingAndPerformance() (https://github.com/maxant/rules/blob/master/rules/src/test/java/ch/maxant/rules/blackbox/DefaultEngineTest.java) => yes it is threadsafe and fast using MVEL. You do NOT need to instantiate several engines - just create one, as in the test.

from rules.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.