File size: 1,684 Bytes
2130399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
This module defines a utility interface called WMInterface
which defines a standard interface for adding and removing things from working memory
"""

class WMInterface(object):
    """ An interface standardizing how to add/remove items from working memory """

    def __init__(self):
        self.added = False

    def is_added(self):
        """ Returns true if the wme is currently in soar's working memory """
        return self.added

    def add_to_wm(self, parent_id):
        """ Creates a structure in working memory rooted at the given parent_id """
        if self.added:
            self._remove_from_wm_impl()
        self._add_to_wm_impl(parent_id)
        self.added = True

    def update_wm(self, parent_id = None):
        """ Updates the structure in Soar's working memory
            It will also add it to wm if parent_id is not None """
        if self.added:
            self._update_wm_impl()
        elif parent_id:
            self._add_to_wm_impl(parent_id)
            self.added = True

    def remove_from_wm(self):
        """ Removes the structure from Soar's working memory """
        if not self.added:
            return
        self._remove_from_wm_impl()
        self.added = False


    ### Internal Methods - To be implemented by derived classes
    
    def _add_to_wm_impl(self, parent_id):
        """ Method to implement in derived class - add to working memory """
        pass

    def _update_wm_impl(self):
        """ Method to implement in derived class - update working memory """
        pass

    def _remove_from_wm_impl(self):
        """ Method to implement in derived class - remove from working memory """
        pass