Skip to content

Commit

Permalink
Priorities on rete nodes.
Browse files Browse the repository at this point in the history
To be used when iterating overs successors
  • Loading branch information
johnsekar committed Nov 7, 2018
1 parent d10dd07 commit 2a4200d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements.txt
@@ -1,5 +1,6 @@
biopython
blist
sortedcontainers
networkx
textx
numpy
Expand Down
11 changes: 9 additions & 2 deletions wc_rules/rete_nodes.py
@@ -1,13 +1,15 @@
from .utils import generate_id,listify
from .rete_token import new_token,TokenRegister
from sortedcontainers import SortedSet
from operator import attrgetter

class ReteNode(object):
def __init__(self,id=None):
if id is None:
id = generate_id()
self.id = id
self.predecessors = set()
self.successors = set()
self.successors = SortedSet(key=attrgetter('priority'))

# Rules for token-passing.
# On receiving a token, do NOT modify it.
Expand Down Expand Up @@ -114,6 +116,7 @@ class checkTYPE(check):
def __init__(self,_class,id=None):
super().__init__(id)
self._class = _class
self.priority=4

def __str__(self):
return 'isinstance(*,'+self._class.__name__+')'
Expand Down Expand Up @@ -141,6 +144,7 @@ def __init__(self,tuple_of_attr_tuples,id=None):
super().__init__(id)
self.tuple_of_attr_tuples = tuple_of_attr_tuples
self.attrs = [tup[0] for tup in tuple_of_attr_tuples]
self.priority=4
# tuple of attrtuple is a tuple of (attr,op,value)
# attr is a string, op is an operator object

Expand Down Expand Up @@ -207,7 +211,7 @@ class checkEDGE(check):
def __init__(self,attrpair,id=None):
super().__init__(id)
self.attribute_pair = attrpair

self.priority=3
### checkEDGE has passthrough behavior
# It simply checks whether the token has a compatible attrpair
# Then duplicates and passes it on
Expand Down Expand Up @@ -245,6 +249,7 @@ def __init__(self,id=None,number_of_variables=1):
super().__init__(id)
self._register = TokenRegister()
self._number_of_variables = number_of_variables
self.priority = 2

def __str__(self):
return 'store'
Expand Down Expand Up @@ -324,6 +329,7 @@ def __init__(self,var_tuple,id=None):
self.variable_names = var_tuple
self.keymap = dict()
self.reverse_keymap = dict()
self.priority=1

def set_keymap(self,key,value):
self.keymap[key] = value
Expand Down Expand Up @@ -422,6 +428,7 @@ def __init__(self,var_tuple,id=None):
super().__init__(id)
self.variable_names = var_tuple
self._register = TokenRegister()
self.priority = 4

def __str__(self):
return ','.join(self.variable_names)
Expand Down

0 comments on commit 2a4200d

Please sign in to comment.