Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python expert system facts generated from an Excel table #31

Open
iTMad200 opened this issue Jun 13, 2022 · 0 comments
Open

Python expert system facts generated from an Excel table #31

iTMad200 opened this issue Jun 13, 2022 · 0 comments

Comments

@iTMad200
Copy link

I have this code, for animals:

from experta import rule
from experta.engine import KnowledgeEngine
from experta.fieldconstraint import L
from experta.rule import Rule
from experta.fact import Fact, Field
from experta.deffacts import DefFacts
from experta.shortcuts import MATCH
from experta.conditionalelement import TEST

class animal(Fact):
name = Field(str, mandatory=True)
number = Field(int, mandatory=True)

class AnimalAnalysis(KnowledgeEngine):
@DefFacts()
def init_animal(self):
yield animal(name = 'dog',
number = 23)
yield animal(name = 'cat',
number = 5)
yield animal(name = 'snake',
number = 14)

@Rule(animal(name=MATCH.name, number=MATCH.number), TEST(lambda number: number > 10))
def animal_analysis(self, name, number):
        return print(name, 'has more than 10 ', number)

engine = AnimalAnalysis()
engine.reset()
engine.run()

Which result:
snake has more than 10 14
dog has more than 10 23

How can I import, at once, a complete excel or txt list of facts?
(Below: )

animal number
dog 23
cat 5
snake 14
dog 32
bird 78
cat 48
dog 52
dog 36
cat 28
bird 14
snake 24
snake 17

Thanks folks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant