File: Knowledge.py

package info (click to toggle)
cyphesis-cpp 0.5.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,084 kB
  • ctags: 3,627
  • sloc: cpp: 30,418; python: 4,812; xml: 4,674; sh: 4,118; makefile: 902; ansic: 617
file content (30 lines) | stat: -rw-r--r-- 909 bytes parent folder | download | duplicates (4)
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
#This file is distributed under the terms of the GNU General Public license.
#Copyright (C) 1999 Aloril (See the file COPYING for details).

class Knowledge:
    def __init__(self):
        self.place={}
        self.location={}
        self.goal={}
        self.importance={}
    def add(self, what, key, value):
        if not hasattr(self, what):
            setattr(self, what, {})
        d=getattr(self,what)
        d[key]=value
    def remove(self, what, key):
        if not hasattr(self, what):
            return
        d=getattr(self,what)
        if d.has_key(key):
            del d[key]
        if len(d)==0:
            delattr(self,what)
    def __str__(self):
        s="<know: "
        s=s+"place: "+str(self.place)+"\n"
        s=s+"location: "+str(self.location)+"\n"
        s=s+"goal: "+str(self.goal)+"\n"
        s=s+"importance: "+str(self.importance)+"\n"
        return s+">\n"