def __init__(self):
     self._simple_cases_regexes = [
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.SimpleCasesRegex),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.OneWordPeriodRegex),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.StrictYearRegex),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.YearToYear),
         RegExpUtility.get_safe_reg_exp(
             ChineseDateTime.YearToYearSuffixRequired),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.YearAndMonth),
         RegExpUtility.get_safe_reg_exp(
             ChineseDateTime.PureNumYearAndMonth),
         RegExpUtility.get_safe_reg_exp(
             ChineseDateTime.DatePeriodYearInChineseRegex),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.WeekOfMonthRegex),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.SeasonWithYear),
         RegExpUtility.get_safe_reg_exp(ChineseDateTime.QuarterRegex),
     ]
     self._illegal_year_regex = RegExpUtility.get_safe_reg_exp(
         BaseDateTime.IllegalYearRegex)
     self._year_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.YearRegex)
     self._till_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodTillRegex)
     self._followed_unit = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.FollowedUnit)
     self._number_combined_with_unit = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.NumberCombinedWithUnit)
     self._past_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.PastRegex)
     self._future_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.FutureRegex)
     self._date_point_extractor = ChineseDateExtractor()
     self._integer_extractor = ChineseNumberExtractor()
     self._number_parser = BaseNumberParser(
         ChineseNumberParserConfiguration())
예제 #2
0
 def __init__(self):
     super().__init__(ChineseDatePeriodParserConfiguration())
     self.integer_extractor = ChineseIntegerExtractor()
     self.number_parser = CJKNumberParser(
         ChineseNumberParserConfiguration())
     self.year_in_chinese_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodYearInChineseRegex)
     self.number_combined_with_unit_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.NumberCombinedWithUnit)
     self.unit_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.UnitRegex)
     self.year_and_month_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.YearAndMonth)
     self.pure_number_year_and_month_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.PureNumYearAndMonth)
     self.year_to_year_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.YearToYear)
     self.year_to_year_suffix_required = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.YearToYearSuffixRequired)
     self.chinese_year_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodYearInChineseRegex)
     self.season_with_year_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.SeasonWithYear)
     self.decade_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DecadeRegex)
     self.date_this_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodThisRegex)
     self.date_last_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodLastRegex)
     self.date_next_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DatePeriodNextRegex)
예제 #3
0
    def __init__(self):
        self._simple_cases_regexes = [
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.SimpleCasesRegex),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.OneWordPeriodRegex),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.StrictYearRegex),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.YearToYear),
            RegExpUtility.get_safe_reg_exp(
                ChineseDateTime.YearToYearSuffixRequired),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.YearAndMonth),
            RegExpUtility.get_safe_reg_exp(
                ChineseDateTime.PureNumYearAndMonth),
            RegExpUtility.get_safe_reg_exp(
                ChineseDateTime.DatePeriodYearInChineseRegex),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.WeekOfMonthRegex),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.SeasonWithYear),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.QuarterRegex),
        ]
        self._illegal_year_regex = RegExpUtility.get_safe_reg_exp(
            BaseDateTime.IllegalYearRegex)
        self._year_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.YearRegex)
        self._till_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DatePeriodTillRegex)
        self._followed_unit = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.FollowedUnit)
        self._number_combined_with_unit = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.NumberCombinedWithUnit)
        self._past_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.PastRegex)
        self._future_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.FutureRegex)
        self._date_point_extractor = ChineseDateExtractor()
        self._integer_extractor = ChineseNumberExtractor()
        self._number_parser = BaseNumberParser(
            ChineseNumberParserConfiguration())
        self._now_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.NowRegex)
        self._month_num_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.MonthNumRegex)

        # TODO When the implementation for these properties is added, change the None values to their respective Regexps
        self._previous_prefix_regex = None
        self._check_both_before_after = None
        self._century_suffix_regex = None
        self._year_period_regex = None
        self._duration_date_restrictions = None
        self._more_than_regex = None
        self._less_than_regex = None
        self._later_regex = None
        self._ago_regex = None
        self._future_suffix_regex = None
        self._within_next_prefix_regex = None
        self._cardinal_extractor = None
        self._ordinal_extractor = None
        self._time_unit_regex = None
    def __init__(self):
        self._date_regex = [
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList1),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList2),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList3),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList4),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList5)
        ]

        if ChineseDateTime.DefaultLanguageFallback == Constants.DEFAULT_LANGUAGE_FALLBACK_DMY:
            self._date_regex.append(
                RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList7))
            self._date_regex.append(
                RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList6))
        else:
            self._date_regex.append(
                RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList6))
            self._date_regex.append(
                RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList7))

        self._date_regex.append(
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList8))

        self._month_of_year = ChineseDateTime.ParserConfigurationMonthOfYear
        self._day_of_month = ChineseDateTime.ParserConfigurationDayOfMonth
        self._day_of_week = ChineseDateTime.ParserConfigurationDayOfWeek
        self._special_day_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.SpecialDayRegex)
        self._special_day_with_num_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.SpecialDayWithNumRegex)
        self._this_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateThisRegex)
        self._next_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateNextRegex)
        self._last_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateLastRegex)
        self._unit_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateUnitRegex)
        self._unit_map = ChineseDateTime.ParserConfigurationUnitMap
        self._week_day_of_month_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.WeekDayOfMonthRegex)
        self._week_day_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.WeekDayRegex)
        self._dynasty_year_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DynastyYearRegex)
        self._dynasty_year_map = ChineseDateTime.DynastyYearMap
        self._integer_extractor = ChineseIntegerExtractor()
        self._number_parser = CJKNumberParser(
            ChineseNumberParserConfiguration())
        self._date_extractor = None
        self._dynasty_start_year = ChineseDateTime.DynastyStartYear
 def __init__(self):
     super().__init__(ChineseDateTimePeriodParserConfiguration())
     self.tmo_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DateTimePeriodMORegex)
     self.taf_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DateTimePeriodAFRegex)
     self.tev_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DateTimePeriodEVRegex)
     self.tni_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DateTimePeriodNIRegex)
     self.unit_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.DateTimePeriodUnitRegex)
     self.time_of_day_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.TimeOfDayRegex)
     self.cardinal_extractor = ChineseCardinalExtractor()
     self.cardinal_parser = CJKNumberParser(
         ChineseNumberParserConfiguration())
 def __init__(self):
     config = ChineseHolidayParserConfiguration()
     BaseHolidayParser.__init__(self, config)
     self.__lunar_holiday_regex = RegExpUtility.get_safe_reg_exp(
         ChineseDateTime.LunarHolidayRegex)
     self.__integer_extractor = ChineseIntegerExtractor()
     self.__number_parser = AgnosticNumberParserFactory.get_parser(
         AgnosticNumberParserType.INTEGER,
         ChineseNumberParserConfiguration())
     self.__fixed_holiday_dictionary = dict([
         ('元旦', ChineseHolidayParser.new_year),
         ('元旦节', ChineseHolidayParser.new_year),
         ('教师节', ChineseHolidayParser.teacher_day),
         ('青年节', ChineseHolidayParser.youth_day),
         ('儿童节', ChineseHolidayParser.children_day),
         ('妇女节', ChineseHolidayParser.female_day),
         ('植树节', ChineseHolidayParser.tree_plant_day),
         ('情人节', ChineseHolidayParser.lover_day),
         ('平安夜', ChineseHolidayParser.christmas_eve),
         ('圣诞节', ChineseHolidayParser.christmas_day),
         ('新年', ChineseHolidayParser.new_year),
         ('愚人节', ChineseHolidayParser.fool_day),
         ('五一', ChineseHolidayParser.labor_day),
         ('劳动节', ChineseHolidayParser.labor_day),
         ('万圣节', ChineseHolidayParser.halloween_day),
         ('中秋节', ChineseHolidayParser.midautumn_day),
         ('中秋', ChineseHolidayParser.midautumn_day),
         ('春节', ChineseHolidayParser.spring_day),
         ('除夕', ChineseHolidayParser.new_year_eve),
         ('元宵节', ChineseHolidayParser.lantern_day),
         ('清明节', ChineseHolidayParser.qing_ming_day),
         ('清明', ChineseHolidayParser.qing_ming_day),
         ('端午节', ChineseHolidayParser.dragon_boat_day),
         ('端午', ChineseHolidayParser.dragon_boat_day),
         ('国庆节', ChineseHolidayParser.chs_national_day),
         ('建军节', ChineseHolidayParser.chs_mil_build_day),
         ('女生节', ChineseHolidayParser.girls_day),
         ('光棍节', ChineseHolidayParser.singles_day),
         ('双十一', ChineseHolidayParser.singles_day),
         ('重阳节', ChineseHolidayParser.chong_yang_day)
     ])
예제 #7
0
    def __init__(self):
        self._date_regex = [
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList1),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList2),
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList3),
            # 2015-12-23 - This regex represents the standard format in Chinese dates (YMD) and has precedence over other orderings
            RegExpUtility.get_safe_reg_exp(ChineseDateTime.DateRegexList8)
        ]

        # Regex precedence where the order between D and M varies is controlled by DefaultLanguageFallback
        if ChineseDateTime.DefaultLanguageFallback == Constants.DEFAULT_LANGUAGE_FALLBACK_DMY:
            order_regex_list = [
                ChineseDateTime.DateRegexList5, ChineseDateTime.DateRegexList4
            ]
        else:
            order_regex_list = [
                ChineseDateTime.DateRegexList4, ChineseDateTime.DateRegexList5
            ]

        if ChineseDateTime.DefaultLanguageFallback in [
                Constants.DEFAULT_LANGUAGE_FALLBACK_DMY,
                Constants.DEFAULT_LANGUAGE_FALLBACK_YMD
        ]:
            order_regex_list.extend([
                ChineseDateTime.DateRegexList7, ChineseDateTime.DateRegexList6
            ])
        else:
            order_regex_list.extend([
                ChineseDateTime.DateRegexList6, ChineseDateTime.DateRegexList7
            ])
        self._date_regex.extend(
            [RegExpUtility.get_safe_reg_exp(ii) for ii in order_regex_list])

        self._month_of_year = ChineseDateTime.ParserConfigurationMonthOfYear
        self._day_of_month = ChineseDateTime.ParserConfigurationDayOfMonth
        self._day_of_week = ChineseDateTime.ParserConfigurationDayOfWeek
        self._special_day_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.SpecialDayRegex)
        self._special_day_with_num_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.SpecialDayWithNumRegex)
        self._this_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateThisRegex)
        self._next_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateNextRegex)
        self._last_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateLastRegex)
        self._unit_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DateUnitRegex)
        self._unit_map = ChineseDateTime.ParserConfigurationUnitMap
        self._week_day_of_month_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.WeekDayOfMonthRegex)
        self._week_day_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.WeekDayRegex)
        self._dynasty_year_regex = RegExpUtility.get_safe_reg_exp(
            ChineseDateTime.DynastyYearRegex)
        self._dynasty_year_map = ChineseDateTime.DynastyYearMap
        self._integer_extractor = ChineseIntegerExtractor()
        self._number_parser = CJKNumberParser(
            ChineseNumberParserConfiguration())
        self._date_extractor = None
        self._dynasty_start_year = ChineseDateTime.DynastyStartYear