def testApplyAll(self):
     rules = [NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyAll1', r'{#2} + "01" + {#1}'),
              NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyAll2', r'{#2} + "02" + {#1}')]
     b = NormalisationRuleBlock(None, [], 'all', rules)
     t = Timex(type='date')
     self.assertTrue(b.apply(t, '', '', [('06', 'POS', {t}), ('th', 'POS', {t}), ('January', 'POS', {t}), ('1996', 'POS', {t})], [], [])[0])
     self.assertEquals(t.value, '19960206')
 def testApplyUntilSuccess2(self):
     rules = [NormalisationRule(r'<(\d+)~.+><th~.+><February~.+><(\d{4})~.+>', 'date', 'testApplyUntilSuccess2A', r'{#2} + "02" + {#1}'),
              NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>', 'date', 'testApplyUntilSuccess2B', r'{#2} + "01" + {#1}')]
     b = NormalisationRuleBlock(None, [], 'until-success', rules)
     t = Timex(type='date')
     self.assertTrue(b.apply(t, '', '', [('06', 'POS', {t}), ('th', 'POS', {t}), ('January', 'POS', {t}), ('1996', 'POS', {t})], [], [])[0])
     self.assertEquals(t.value, '19960106')
Пример #3
0
 def testApplyAll(self):
     rules = [
         NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>',
                           'date', 'testApplyAll1', r'{#2} + "01" + {#1}'),
         NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>',
                           'date', 'testApplyAll2', r'{#2} + "02" + {#1}')
     ]
     b = NormalisationRuleBlock(None, [], 'all', rules)
     t = Timex(type='date')
     self.assertTrue(
         b.apply(t, '', '', [('06', 'POS', {t}), ('th', 'POS', {t}),
                             ('January', 'POS', {t}), ('1996', 'POS', {t})],
                 [], [])[0])
     self.assertEquals(t.value, '19960206')
Пример #4
0
 def testApplyUntilSuccess2(self):
     rules = [
         NormalisationRule(r'<(\d+)~.+><th~.+><February~.+><(\d{4})~.+>',
                           'date', 'testApplyUntilSuccess2A',
                           r'{#2} + "02" + {#1}'),
         NormalisationRule(r'<(\d+)~.+><th~.+><January~.+><(\d{4})~.+>',
                           'date', 'testApplyUntilSuccess2B',
                           r'{#2} + "01" + {#1}')
     ]
     b = NormalisationRuleBlock(None, [], 'until-success', rules)
     t = Timex(type='date')
     self.assertTrue(
         b.apply(t, '', '', [('06', 'POS', {t}), ('th', 'POS', {t}),
                             ('January', 'POS', {t}), ('1996', 'POS', {t})],
                 [], [])[0])
     self.assertEquals(t.value, '19960106')