예제 #1
0
파일: tests.py 프로젝트: nedap/dateinfer
    def testFind(self):
        elem_list = [
            Filler(' '),
            DayOfMonth(),
            Filler('/'),
            MonthNum(),
            Hour24(),
            Year4()
        ]
        t = ruleproc.Sequence.find

        self.assertEqual(0, t([Filler(' ')], elem_list))
        self.assertEqual(3, t([MonthNum], elem_list))
        self.assertEqual(2, t([Filler('/'), MonthNum()], elem_list))
        self.assertEqual(4, t([Hour24, Year4()], elem_list))

        elem_list = [
            WeekdayShort, MonthTextShort,
            Filler(' '), Hour24,
            Filler(':'), Minute,
            Filler(':'), Second,
            Filler(' '), Timezone,
            Filler(' '), Year4
        ]
        self.assertEqual(3, t([Hour24, Filler(':')], elem_list))
예제 #2
0
파일: tests.py 프로젝트: nedap/dateinfer
    def testTagMostLikely(self):
        examples = ['8/12/2004', '8/14/2004', '8/16/2004', '8/25/2004']
        t = _tag_most_likely

        actual = t(examples)
        expected = [
            MonthNum(),
            Filler('/'),
            DayOfMonth(),
            Filler('/'),
            Year4()
        ]

        self.assertListEqual(actual, expected)
예제 #3
0
파일: tests.py 프로젝트: nedap/dateinfer
    def testNext(self):
        elem_list = [
            Filler(' '),
            DayOfMonth(),
            Filler('/'),
            MonthNum(),
            Hour24(),
            Year4()
        ]

        next1 = ruleproc.Next(DayOfMonth, MonthNum)
        self.assertTrue(next1.is_true(elem_list))

        next2 = ruleproc.Next(MonthNum, Hour24)
        self.assertTrue(next2.is_true(elem_list))

        next3 = ruleproc.Next(Filler, Year4)
        self.assertFalse(next3.is_true(elem_list))
예제 #4
0
파일: tests.py 프로젝트: nedap/dateinfer
    def testMostRestrictive(self):
        t = _most_restrictive

        self.assertEqual(MonthNum(), t([DayOfMonth(), MonthNum, Year4()]))
        self.assertEqual(Year2(), t([Year4(), Year2()]))
예제 #5
0
from dateinfer.date_elements import (AMPM, DayOfMonth, Filler, Hour12, Hour24,
                                     Minute, MonthNum, MonthTextLong,
                                     MonthTextShort, Second, Timezone,
                                     UTCOffset, WeekdayLong, WeekdayShort,
                                     Year2, Year4)
from dateinfer.ruleproc import (And, Contains, Duplicate, If, KeepOriginal,
                                Sequence, Swap, SwapDuplicateWhereSequenceNot,
                                SwapSequence)

# DATE_ELEMENTS is an ordered sequence of date elements, excluding the filler. It is ordered
# in descending "restrictivity".
# The order is a little loose since date element domains do not necessarily overlap (e.g., the
# range of Jan .. Dec is 12, but the domain is independent of hours 0 .. 23), but overall a lesser
# value should be preferred over a greater value.
# The RULES will be applied after the list is generated following these precedence rules.
DATE_ELEMENTS = (AMPM(), MonthNum(), Hour12(), Hour24(), DayOfMonth(),
                 Minute(), Second(), Year2(), Year4(), UTCOffset(),
                 MonthTextShort(), MonthTextLong(), WeekdayShort(),
                 WeekdayLong(), Timezone())

F = Filler  # short-hand to clarify rules
RULES = [
    If(Sequence(Year4, Year2), SwapSequence([Year4, Year2],
                                            [Year4, MonthNum])),
    If(
        Sequence(MonthNum, F('/'), r'\d', F('/'), Year4),
        SwapSequence(
            [MonthNum, F('/'), r'\d', F('/'), Year4],
            [MonthNum, F('/'), DayOfMonth,
             F('/'), Year4])),
    If(
예제 #6
0
                                     Year2, Year4)
from dateinfer.ruleproc import (And, Contains, Duplicate, If, KeepOriginal,
                                Sequence, Swap, SwapDuplicateWhereSequenceNot,
                                SwapSequence)

# DATE_ELEMENTS is an ordered sequence of date elements, excluding the filler. It is ordered
# in descending "restrictivity".
# The order is a little loose since date element domains do not necessarily overlap (e.g., the
# range of Jan .. Dec is 12, but the domain is independent of hours 0 .. 23), but overall a lesser
# value should be preferred over a greater value.
# The RULES will be applied after the list is generated following these precedence rules.
DATE_ELEMENTS = (AMPM(),
                 MonthNum(),
                 Hour12(),
                 Hour24(),
                 DayOfMonth(),
                 Minute(),
                 Second(),
                 Year2(),
                 Year4(),
                 UTCOffset(),
                 MonthTextShort(),
                 MonthTextLong(),
                 WeekdayShort(),
                 WeekdayLong(),
                 Timezone())

F = Filler  # short-hand to clarify rules
RULES = [
    If(Sequence(MonthNum, F('/'), r'\d', F('/'), Year4),
       SwapSequence([MonthNum, F('/'), r'\d', F('/'), Year4],