Giter Club home page Giter Club logo

Comments (4)

nilp0inter avatar nilp0inter commented on August 11, 2024

The facts that you can use with modify are the ones returned by declare or the ones received in a rule as parameters. In your example:

engine = Rules()
fact_1 = Fact_1(value_1 = 1)
fact_2 = Fact_2(value_2 = 3)
engine.reset()
declared_1 = engine.declare(fact_1)
declared_2 = engine.declare(fact_2)
engine.run()

engine.modify(declared_1, value_1=5)
engine.modify(declared_2, value_2=3)
engine.run()

This is due to the fact that you can instantiate a fact and use it with multiple engines at the same time or be modified in an unsafe manner by the user. To avoid data corruption, when you declare a fact an immutable copy is made and managed by the engine.

Do this solve your problem?

from experta.

cdemulde avatar cdemulde commented on August 11, 2024

Hi,

I did not actually, at least not for the test case. I noticed that in your answer, you modify declared_1 and declared_2, while what I would like to be able to do is modify declared_1 twice, with an engine run in between. And that still throws the same error (except when I use the fix I proposed earlier).

from experta.

nilp0inter avatar nilp0inter commented on August 11, 2024

In that case what you need to do is to store the fact returned by modify, this is an example:

import experta as exp

class Fact_1(exp.Fact):
    value_1 = exp.Field(int)

class Fact_2(exp.Fact):
    value_2 = exp.Field(int)

class Rules(exp.KnowledgeEngine):
    @exp.Rule(Fact_1(value_1 = exp.MATCH.v1),
              Fact_2(value_2 = exp.MATCH.v2))
    def subtract(self, v1, v2):
        print(v1-v2)


engine = Rules()
fact_1 = Fact_1(value_1 = 1)
fact_2 = Fact_2(value_2 = 3)

engine.reset()
f1 = engine.declare(fact_1)
f2 = engine.declare(fact_2)
engine.run()

f1_1 = engine.modify(f1, value_1=3)
engine.run()

f1_2 = engine.modify(f1_1, value_1=8)
engine.run()

from experta.

cdemulde avatar cdemulde commented on August 11, 2024

Aha, that does the trick indeed, for the working example at least. For the time being, I'll keep working with the fix I proposed though. Somehow, I think it does make more sense to update a fact and leave it in place, i.e. with the same fact number and everything.

Thank you for your answers!

from experta.

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.