Skip to content

Python expert system facts generated from an Excel table #31

@iTMad200

Description

@iTMad200

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! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions