Skip to content
Snippets Groups Projects
Commit 25c47746 authored by Chris MacLellan's avatar Chris MacLellan
Browse files

removed py_rete dependency

parent ffa9e0f0
Branches
No related tags found
No related merge requests found
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
# from apprentice.agents.pyrete_agent import PyReteAgent # from apprentice.agents.pyrete_agent import PyReteAgent
from apprentice.agents.WhereWhenHowNoFoa import WhereWhenHowNoFoa from apprentice.agents.WhereWhenHowNoFoa import WhereWhenHowNoFoa
from apprentice.working_memory.representation import Sai from apprentice.working_memory.representation import Sai
from py_rete import Production # from py_rete import Production
from py_rete import Fact # from py_rete import Fact
from py_rete import V # from py_rete import V
from py_rete.conditions import Filter # from py_rete.conditions import Filter
from tutorenvs.multicolumn import MultiColumnAdditionSymbolic from tutorenvs.multicolumn import MultiColumnAdditionSymbolic
...@@ -50,97 +50,97 @@ def run_training(agent, n=10): ...@@ -50,97 +50,97 @@ def run_training(agent, n=10):
p += 1 p += 1
@Production( # @Production(
Fact(id=V('selection'), type="TextField", contentEditable=True, value="") # Fact(id=V('selection'), type="TextField", contentEditable=True, value="")
& Fact(value=V('value')) & Filter( # & Fact(value=V('value')) & Filter(
lambda value: value != "" and is_number(value) and float(value) < 10)) # lambda value: value != "" and is_number(value) and float(value) < 10))
def update_field(selection, value): # def update_field(selection, value):
return Sai(selection, 'UpdateField', {'value': value}) # return Sai(selection, 'UpdateField', {'value': value})
#
#
def is_number(v): # def is_number(v):
try: # try:
float(v) # float(v)
return True # return True
except Exception: # except Exception:
return False # return False
@Production( # @Production(
V('f1') << Fact(id=V('id1'), value=V('v1')) # V('f1') << Fact(id=V('id1'), value=V('v1'))
& V('f2') << Fact(id=V('id2'), value=V('v2')) # & V('f2') << Fact(id=V('id2'), value=V('v2'))
& Filter(lambda id1, id2, v1, v2: v1 != "" and is_number(v1) and v2 != "" # & Filter(lambda id1, id2, v1, v2: v1 != "" and is_number(v1) and v2 != ""
and is_number(v2) and id1 < id2)) # and is_number(v2) and id1 < id2))
def add_values(net, f1, f2, id1, id2, v1, v2): # def add_values(net, f1, f2, id1, id2, v1, v2):
if 'depth' not in f1: # if 'depth' not in f1:
depth1 = 0 # depth1 = 0
else: # else:
depth1 = f1['depth'] # depth1 = f1['depth']
if depth1 > 1: # if depth1 > 1:
return # return
#
if 'depth' not in f2: # if 'depth' not in f2:
depth2 = 0 # depth2 = 0
else: # else:
depth2 = f2['depth'] # depth2 = f2['depth']
#
if depth1 + depth2 > 1: # if depth1 + depth2 > 1:
return # return
#
print("trying to add values") # print("trying to add values")
v1 = float(v1) # v1 = float(v1)
v2 = float(v2) # v2 = float(v2)
v3 = v1 + v2 # v3 = v1 + v2
if v3 == round(v3): # if v3 == round(v3):
v3 = int(v3) # v3 = int(v3)
f = Fact(id="({}+{})".format(id1, id2), # f = Fact(id="({}+{})".format(id1, id2),
value=str(v3), # value=str(v3),
depth=max(depth1, depth2) + 1) # depth=max(depth1, depth2) + 1)
net.add_fact(f) # net.add_fact(f)
#
#
@Production( # @Production(
V('f1') << Fact(id=V('id1'), value=V('v1')) # V('f1') << Fact(id=V('id1'), value=V('v1'))
& Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10)) # & Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10))
def mod10_value(net, f1, id1, v1): # def mod10_value(net, f1, id1, v1):
if 'depth' not in f1: # if 'depth' not in f1:
depth1 = 0 # depth1 = 0
else: # else:
depth1 = f1['depth'] # depth1 = f1['depth']
if depth1 > 1: # if depth1 > 1:
return # return
#
print("trying to mod10 value") # print("trying to mod10 value")
v1 = float(v1) # v1 = float(v1)
v2 = v1 % 10 # v2 = v1 % 10
if v2 == round(v2): # if v2 == round(v2):
v2 = int(v2) # v2 = int(v2)
f = Fact(id="({}%10)".format(id1), value=str(v2), depth=depth1 + 1) # f = Fact(id="({}%10)".format(id1), value=str(v2), depth=depth1 + 1)
net.add_fact(f) # net.add_fact(f)
#
print(net) # print(net)
#
#
@Production( # @Production(
V('f1') << Fact(id=V('id1'), value=V('v1')) # V('f1') << Fact(id=V('id1'), value=V('v1'))
& Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10)) # & Filter(lambda id1, v1: v1 != "" and is_number(v1) and float(v1) >= 10))
def div10_value(net, f1, id1, v1): # def div10_value(net, f1, id1, v1):
if 'depth' not in f1: # if 'depth' not in f1:
depth1 = 0 # depth1 = 0
else: # else:
depth1 = f1['depth'] # depth1 = f1['depth']
if depth1 > 1: # if depth1 > 1:
return # return
#
print("trying to div10 value") # print("trying to div10 value")
v1 = float(v1) # v1 = float(v1)
v2 = v1 // 10 # v2 = v1 // 10
if v2 == round(v2): # if v2 == round(v2):
v2 = int(v2) # v2 = int(v2)
f = Fact(id="({}//10)".format(id1), value=str(v2), depth=depth1 + 1) # f = Fact(id="({}//10)".format(id1), value=str(v2), depth=depth1 + 1)
net.add_fact(f) # net.add_fact(f)
#
print(net) # print(net)
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment