-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrete.py
More file actions
35 lines (27 loc) · 1.02 KB
/
rete.py
File metadata and controls
35 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Fact:
def __init__(self, **kwargs):
self.data = kwargs
class Production:
def __init__(self, condition, action):
self.condition = condition
self.action = action
def evaluate(self, fact):
return self.condition(fact)
# Example facts
patient1 = Fact(symptoms=["fever", "cough"])
patient2 = Fact(symptoms=["fatigue", "headache"])
# Example production rules
def influenza_rule(fact):
return "fever" in fact["symptoms"] and "cough" in fact["symptoms"]
def migraine_rule(fact):
return "fatigue" in fact["symptoms"] and "headache" in fact["symptoms"]
# Create production rules
production1 = Production(condition=influenza_rule, action="Diagnose Influenza")
production2 = Production(condition=migraine_rule, action="Diagnose Migraine")
# Rete network (simplified)
network = [production1, production2]
# Evaluate facts
for patient in [patient1, patient2]:
for production in network:
if production.evaluate(patient.data):
print(f"Patient diagnosed: {production.action}")