Git Product home page Git Product logo

Comments (2)

Clayton7510 avatar Clayton7510 commented on May 20, 2024

You do not need to create a new RuleBook each time you run it. RuleBooks can, however, change facts. So, if you rerun the same facts in a RuleBook multiple times, then you could certainly get a different state after subsequent runs.

Taking a modified version of your example:

   NameValueReferableMap<Integer> facts = new FactMap<>();

    facts.setValue("Steve", 30);
    facts.setValue("Eddie", 42);
    facts.setValue("Mary", 32);

    RuleBook ruleBook = RuleBookBuilder.create().addRule(rule -> rule.withFactType(Integer.class)
        .then(people -> people.entrySet().stream()
            .map(entry -> entry.getValue()) //map entries to people Facts
            .filter(person -> person.getValue() < 40) //filter out people Facts for those who are under 40
            .map(person -> person.getName()) //map people to their names
            .forEach(System.out::println))) //print the names of the people
        .build();

    ruleBook.run(facts);
    ruleBook.run(facts);

RuleBooks accept data as Facts, which can also be created or manipulated within a Rule. A Rule is provided all of the matching facts as an input. So, whereas the above example that I provided from your example does work, it's probably not the best use case for RuleBook. Something more akin to the MegaBank example, the POJO MegaBank Example or another scenario where there are different facts that determine whether or not an action should be taken is probably a better scenario.

Anyway, to your question about having to create a new RuleBook for each run: In the example I used above, the RuleBook I created is run twice from the same instance. In both cases the results are:
Steve
Mary

Thanks,

Clayton

from rulebook.

brunoriscado avatar brunoriscado commented on May 20, 2024

Thanks will give this a try.

from rulebook.

Related Issues (20)

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.