Skip to content

Instantly share code, notes, and snippets.

@dicato
Created April 24, 2012 21:54
Show Gist options
  • Save dicato/2484156 to your computer and use it in GitHub Desktop.
Save dicato/2484156 to your computer and use it in GitHub Desktop.
Test for Intellect
from wobbit import BaseWobbit, ColoredWobbit
rule is_blue:
when:
$i := ColoredWobbit( color = 'blue')
then:
print('Found a blue wobbit')
$i.construct()
rule is_wobbit:
when:
$i := BaseWobbit()
then:
print('Yes this is a wobbit')
#!/usr/bin/env python
import pdb
from intellect.Intellect import Intellect
from wobbit import ColoredWobbit
if __name__ == '__main__':
print 'Running...'
intel = Intellect()
pdb.set_trace()
intel.learn_policy("./basic_rules.policy")
blue_wobbit = ColoredWobbit(5, 'blue')
print blue_wobbit.color
intel.learn(blue_wobbit)
intel.reason()
#!/usr/bin/env python
class BaseWobbit(object):
"""
Base class for a Wobbit
"""
def __init__(self, size):
print 'Instantiating a wobbit'
self._size = size
# Data descriptors
@property
def size(self):
return self._size
@size.setter
def size(self, value):
if isinstance(value, int):
self._size = value
else:
raise TypeError('Size must be set to an integer')
def construct(self):
print "Building a house out of wobbits"
class ColoredWobbit(BaseWobbit):
"""
This is an extended Wobbit that is colored
"""
def __init__(self, size, color):
print 'Instantiating a colored wobbit'
self._color = color
# Call the base class explicitly
# or use 'super'
BaseWobbit.__init__(self, size)
# Data descriptors
@property
def color(self):
return self._color
@color.setter
def color(self, value):
if isinstance(value, str):
self._color = value
else:
raise TypeError('Color must be set to a string')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment