Пример #1
0
 def test_deferred_list(self):
     self.assertRaises(ValueError, parse_rule, 'with() ()')
     d = parse_rule(' with( object:0 )  ')
     self.assertEqual(len(d), 0)
     d = parse_rule(r'with(object:0) \0 bool AND \0 bool AND \0.0 bool')
     self.assertEqual(len(d), 3)
     self.assertIs(d.children[0].left, d.children[1].left)
     self.assertIs(d.children[0].left, d.children[2].left.stype)
Пример #2
0
 def test_collapse(self):
     d = parse_rule('    NOT (object:0 bool AND min() bool)    ')
     self.assertEqual(len(d), 2)
     self.assertFalse(d.negated)
     self.assertEqual(d.connector, 'OR')
     self.assertTrue(d.children[0].negated)
     self.assertTrue(d.children[1].negated)
Пример #3
0
 def test(self):
     s = Selector(0, None)
     c1 = Condition(Selector(s, ('hey',)), 'bool')
     c2 = Condition(Function('min', ('hi', 'bye')), '==', Selector('extra', ['greeting']))
     c3 = Condition(Selector(1, ['split']), '!=', Selector(('const', ('one',)), ()))
     c4 = Condition(Selector(s, ('ho',)), '>', Selector(2, None), negated=True)
     n1 = ConditionNode([c1, c2], connector='OR')
     n2 = ConditionNode([c3], connector='OR')
     n3 = ConditionNode([c4, n1, n2])
     x = format_rule(n3)
     n3.collapse()
     y = (r'with(object:0,\0.ho;,object:2,\0.hey;,min("hi","bye"),'
          r'extra.greeting;,object:1.split;) '
          r'(NOT \1 > \2 AND (\3 bool OR \4 == \5) AND (\6 != ["one"]))')
     self.assertEqual(x, y)
     z = parse_rule(y)
     self.assertEq(z, n3)
Пример #4
0
 def parse(sentence, scope, tnorm=None, snorm=None, cnorm=None):
     """
     Parse a str-rule with given scope and norms
     """
     from rules.parser import parse_rule
     return parse_rule(sentence, scope, tnorm, snorm, cnorm)
Пример #5
0
 def parse(sentence, scope, tnorm=None, snorm=None, cnorm=None):
     """
     Parse a str-rule with given scope and norms
     """
     from rules.parser import parse_rule
     return parse_rule(sentence, scope, tnorm, snorm, cnorm)