Exemple #1
0
class RuleEngineIoTests(TestCase):
    def setUp(self):
        self.engine = RuleEngine()
        self.engine.load_module('family', ruledefs)
        self.engine.load(resource_filename(inputs.__name__, 'fathers.txt'))
        
    def test_df(self):
        df = facts_to_df(self.engine, 'IsFatherOf')
        names = 'Adam Seth Enos Kenan Mahalalel'.split()
        self.assertEqual(list(df['father']), names[:-1])
        self.assertEqual(list(df['son']), names[1:])
Exemple #2
0
class RuleEngineIoTests(TestCase):
    def setUp(self):
        self.engine = RuleEngine()
        self.engine.load_module('family', ruledefs)
        self.engine.load(resource_filename(inputs.__name__, 'fathers.txt'))

    def test_df(self):
        df = facts_to_df(self.engine, 'IsFatherOf')
        names = 'Adam Seth Enos Kenan Mahalalel'.split()
        self.assertEqual(list(df['father']), names[:-1])
        self.assertEqual(list(df['son']), names[1:])
Exemple #3
0
 def _make_engine(self, ruledef):
     engine = RuleEngine()
     engine.load_module(ruledef, ruledefs)
     return engine
Exemple #4
0
 def setUp(self):
     self.engine = RuleEngine()
     self.engine.load_module('family', ruledefs)
     self.engine.load(resource_filename(inputs.__name__, 'fathers.txt'))
Exemple #5
0
from rulu.engine import RuleEngine

engine = RuleEngine()
# Load the data model and rules
engine.load_module('family')

# Add input facts
engine.assert_('IsFatherOf', father='Adam', son='Seth')
engine.assert_('IsFatherOf', father='Seth', son='Enos')
engine.assert_('IsFatherOf', father='Enos', son='Kenan')
engine.assert_('IsFatherOf', father='Kenan', son='Mahalalel')

# This is where the magic happens
engine.run()

# Print output facts
for fact in engine.get_facts('IsGrandfatherOf'):
    print '{} is the {}grandfather of {}.'.format(fact.grandfather,
                                                  'great-' * fact.greatness,
                                                  fact.grandson)
Exemple #6
0
from rulu.engine import RuleEngine
from utils import print_rst_table
engine = RuleEngine()
engine.load_module('greeting')
engine.assert_('Entity', name='World')
print_rst_table(engine, 'Entity', 'greeting-in.txt')
engine.run()
print_rst_table(engine, 'Greeting', 'greeting-out.txt')
Exemple #7
0
from rulu.engine import RuleEngine

engine = RuleEngine()
# Load the data model and rules
engine.load_module('family')

# Add input facts
from family import IsFatherOf
engine.assert_(IsFatherOf, father='Adam', son='Seth')
engine.assert_(IsFatherOf, father='Seth', son='Enos')
engine.assert_(IsFatherOf, father='Enos', son='Kenan')
engine.assert_(IsFatherOf, father='Kenan', son='Mahalalel')

engine.run()

# Print output facts
for fact in engine.get_facts():
    if fact._name == 'IsGrandfatherOf':
        print '{} is the {}grandfather of {}.'.format(
                fact.grandfather, 'great-'*fact.greatness, fact.grandson)
Exemple #8
0
from rulu.engine import RuleEngine

engine = RuleEngine()
# Load the data model and rules
engine.load_module("family")

# Add input facts
engine.assert_("IsFatherOf", father="Adam", son="Seth")
engine.assert_("IsFatherOf", father="Seth", son="Enos")
engine.assert_("IsFatherOf", father="Enos", son="Kenan")
engine.assert_("IsFatherOf", father="Kenan", son="Mahalalel")

# This is where the magic happens
engine.run()

# Print output facts
for fact in engine.get_facts("IsGrandfatherOf"):
    print "{} is the {}grandfather of {}.".format(fact.grandfather, "great-" * fact.greatness, fact.grandson)
Exemple #9
0
from rulu.engine import RuleEngine

engine = RuleEngine()
engine.load_module('family')
engine.load('family-in.clp')
engine.run()
engine.save('family-out.clp')
 def _make_engine(self, ruledef, trace=False):
     engine = RuleEngine(trace=trace)
     engine.load_module(ruledef, ruledefs)
     return engine
Exemple #11
0
 def _make_engine(self, ruledef):
     engine = RuleEngine()
     engine.load_module(ruledef, ruledefs)
     return engine
Exemple #12
0
 def setUp(self):
     self.engine = RuleEngine()
     self.engine.load_module('family', ruledefs)
     self.engine.load(resource_filename(inputs.__name__, 'fathers.txt'))