コード例 #1
0
 def testApplyAll(self):
     rules = [normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyAll1', r'{#2} + "01" + {#1}'),
              normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyAll2', r'{#2} + "02" + {#1}')]
     b = normalisation_rule_block(None, [], 'all', rules)
     t = timex(type='date')
     self.assertTrue(b.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
     self.assertEquals(t.value, '19960206')
コード例 #2
0
 def testPosGuardBlocks(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testPosGuardBlocks', r'{#2} + "01" + {#1}',
                               guards = [r'<th~.+><February~.+>'])
     t = timex(type='date')
     (before, body, after) = (
         [('We', 'POS', set()),
          ('took', 'POS', set()),
          ('a', 'POS', set()),
          ('plane', 'POS', set()),
          ('on', 'POS', set()),
          ('the', 'POS', set())],
         [('06', 'POS', set()),
          ('th', 'POS', set()),
          ('January', 'POS', set()),
          ('1996', 'POS', set())],
         [('to', 'POS', set()),
          ('Atlanta', 'POS', set())]
     )
     self.assertFalse(rule.apply(t, '', '', body, before, after)[0])
コード例 #3
0
 def testNegAfterAllows(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testNegAfterAllows', r'{#2} + "01" + {#1}',
                               after_guards = [r'!<a~.+><plane~.+>'])
     t = timex(type='date')
     (before, body, after) = (
         [('We', 'POS', set()),
          ('took', 'POS', set()),
          ('a', 'POS', set()),
          ('plane', 'POS', set()),
          ('on', 'POS', set()),
          ('the', 'POS', set())],
         [('06', 'POS', set()),
          ('th', 'POS', set()),
          ('January', 'POS', set()),
          ('1996', 'POS', set())],
         [('to', 'POS', set()),
          ('Atlanta', 'POS', set())]
     )
     self.assertTrue(rule.apply(t, '', '', body, before, after)[0])
     self.assertEquals(t.value, '19960106')
コード例 #4
0
ファイル: warn.py プロジェクト: jasonzou/entex
 def test_warn(self):
     # Do something that generates a warning
     t = timex()
     r = normalisation_rule('test', value='non_existent_function()')
     r.apply(t, '', '', [('test', 'POS', set([t]))], [], [])
     self.assertEquals(1, self.w.num)
コード例 #5
0
 def testRaiseError(self):
     rules = [normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testRaiseError1', r'{#2} + "01" + {#1}'),
              normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testRaiseError2', r'{#2} + "02" + {#1}')]
     self.assertRaises(rule_load_error, normalisation_rule_block, None, [], 'invalid', rules)
コード例 #6
0
 def testApplyValue(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyValue', r'{#2} + "01" + {#1}')
     t = timex(type='date')
     self.assertTrue(rule.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
     self.assertEquals(t.value, '19960106')
コード例 #7
0
 def testApplyCorrectType(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyCorrectType', r'{#2} + "01" + {#1}')
     t = timex(type='time')
     self.assertFalse(rule.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
コード例 #8
0
 def testApplyQuant(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyQuant', quant=r'"EVERY"')
     t = timex(type='date')
     self.assertTrue(rule.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
     self.assertEquals(t.quant, 'EVERY')
コード例 #9
0
 def testApplyFreq(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyFreq', freq=r'"1D"')
     t = timex(type='date')
     self.assertTrue(rule.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
     self.assertEquals(t.freq, '1D')
コード例 #10
0
 def testApplyChangeType(self):
     rule = normalisation_rule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyChangeType', change_type=r'"non-date"')
     t = timex(type='date')
     self.assertTrue(rule.apply(t, '', '', [('06', 'POS', set([t])), ('th', 'POS', set([t])), ('January', 'POS', set([t])), ('1996', 'POS', set([t]))], [], [])[0])
     self.assertEquals(t.type, 'non-date')