Comments (4)
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.
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.
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.
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)
- RETE network generation is not idempotent
- Activations are not well-ordered HOT 1
- ’EXISTS' cannot return accuracy results, influenced by the pattern order insider. HOT 9
- NA
- Firing a rule only once HOT 1
- Strategy bug found by hypothesis
- Investigate negative delays HOT 1
- Need some help about the GC of KnowledgeEngine HOT 1
- multifieldwildcard HOT 1
- How to show fired rule. HOT 1
- Looping Experta for use with a chatbot
- Implementation of the water jugs problem
- Is there still room for optimization in the judgment?
- Is there an easy way to modify facts?
- Python expert system facts generated from an Excel table
- experta
- Check that the fact does not exist, but with the data of another fact
- AttributeError: module 'collections' has no attribute 'Mapping' HOT 4
- Not the expected result
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from experta.