def test_get_arity(self):
     th = agnostic.NonrecursiveRuleTheory()
     th.insert(helper.str2form('q(x) :- p(x)'))
     th.insert(helper.str2form('p(x) :- s(x)'))
     self.assertEqual(th.get_arity('p'), 1)
     self.assertEqual(th.get_arity('q'), 1)
     self.assertIsNone(th.get_arity('s'))
     self.assertIsNone(th.get_arity('missing'))
Exemple #2
0
 def test_get_arity(self):
     th = runtime.NonrecursiveRuleTheory()
     th.insert(helper.str2form('q(x) :- p(x)'))
     th.insert(helper.str2form('p(x) :- s(x)'))
     self.assertEqual(th.get_arity('p'), 1)
     self.assertEqual(th.get_arity('q'), 1)
     self.assertIsNone(th.get_arity('s'))
     self.assertIsNone(th.get_arity('missing'))
Exemple #3
0
 def test_get_arity(self):
     run = runtime.Runtime()
     run.debug_mode()
     th = runtime.NonrecursiveRuleTheory()
     th.insert(helper.str2form('q(x) :- p(x)'))
     th.insert(helper.str2form('p(x) :- s(x)'))
     self.assertEqual(th.get_arity('p'), 1)
     self.assertEqual(th.get_arity('q'), 1)
     self.assertIsNone(th.get_arity('s'))
     self.assertIsNone(th.get_arity('missing'))
Exemple #4
0
    def test_theory_inclusion(self):
        """Test evaluation routines when one theory includes another."""
        # spread out across inclusions
        th1 = runtime.NonrecursiveRuleTheory()
        th2 = runtime.NonrecursiveRuleTheory()
        th3 = runtime.NonrecursiveRuleTheory()
        th1.includes.append(th2)
        th2.includes.append(th3)

        th1.insert(helper.str2form('p(x) :- q(x), r(x), s(2)'))
        th2.insert(helper.str2form('q(1)'))
        th1.insert(helper.str2form('r(1)'))
        th3.insert(helper.str2form('s(2)'))

        self.check_equal(helper.pol2str(th1.select(helper.str2form('p(x)'))),
                         'p(1)', 'Data spread across inclusions')
Exemple #5
0
    def test_dependency_graph(self):
        """Test that dependency graph gets updated correctly."""
        run = runtime.Runtime()
        run.debug_mode()
        g = run.global_dependency_graph

        run.create_policy('test')

        run.insert('p(x) :- q(x), nova:q(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))

        run.insert('p(x) :- s(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))

        run.insert('q(x) :- nova:r(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))

        run.delete('p(x) :- q(x), nova:q(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))

        run.update([
            runtime.Event(helper.str2form('p(x) :- q(x), nova:q(x)'),
                          target='test')
        ])
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))
    def test_dependency_graph(self):
        """Test that dependency graph gets updated correctly."""
        run = agnostic.Runtime()
        run.debug_mode()
        g = run.global_dependency_graph

        run.create_policy('test')

        run.insert('p(x) :- q(x), nova:q(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))

        run.insert('p(x) :- s(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))

        run.insert('q(x) :- nova:r(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))

        run.delete('p(x) :- q(x), nova:q(x)', target='test')
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))

        run.update([agnostic.Event(helper.str2form('p(x) :- q(x), nova:q(x)'),
                                   target='test')])
        self.assertTrue(g.edge_in('test:p', 'nova:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:q', False))
        self.assertTrue(g.edge_in('test:p', 'test:s', False))
        self.assertTrue(g.edge_in('test:q', 'nova:r', False))
    def test_theory_inclusion(self):
        """Test evaluation routines when one theory includes another."""
        # spread out across inclusions
        th1 = agnostic.NonrecursiveRuleTheory()
        th2 = agnostic.NonrecursiveRuleTheory()
        th3 = agnostic.NonrecursiveRuleTheory()
        th1.includes.append(th2)
        th2.includes.append(th3)

        th1.insert(helper.str2form('p(x) :- q(x), r(x), s(2)'))
        th2.insert(helper.str2form('q(1)'))
        th1.insert(helper.str2form('r(1)'))
        th3.insert(helper.str2form('s(2)'))

        self.check_equal(
            helper.pol2str(th1.select(helper.str2form('p(x)'))),
            'p(1)', 'Data spread across inclusions')
 def check(query, code, tablenames, correct, msg, find_all=True):
     # We're interacting directly with the runtime's underlying
     #   theory b/c we haven't yet decided whether Abduce should
     #   be a top-level API call.
     run = self.prep_runtime()
     run.insert(code, target=NREC_THEORY)
     query = helper.str2form(query)
     actual = run.theory[NREC_THEORY].abduce(query, tablenames=tablenames, find_all=find_all)
     e = helper.datalog_same(helper.pol2str(actual), correct, msg)
     self.assertTrue(e)
 def check(query, code, tablenames, correct, msg, find_all=True):
     # We're interacting directly with the runtime's underlying
     #   theory b/c we haven't yet decided whether Abduce should
     #   be a top-level API call.
     run = self.prep_runtime()
     run.insert(code, target=NREC_THEORY)
     query = helper.str2form(query)
     actual = run.theory[NREC_THEORY].abduce(
         query, tablenames=tablenames, find_all=find_all)
     e = helper.datalog_same(helper.pol2str(actual), correct, msg)
     self.assertTrue(e)