normalisation_functions Package

date_functions Module

ternip.rule_engine.normalisation_functions.date_functions.convert_to_24_hours(time, ap)[source]

Given a hour and an a/p specifier, then convert the hour into 24 hour clock if need be

ternip.rule_engine.normalisation_functions.date_functions.date_to_dow(y, m, d)[source]

Gets the integer day of week for a date. Sunday is 0.

ternip.rule_engine.normalisation_functions.date_functions.date_to_iso(string)[source]

A translation of GUTime’s Date2ISO function. Given some date/time string representing an absolute date, then return a date string in the basic ISO format.

ternip.rule_engine.normalisation_functions.date_functions.date_to_week(y, m, d)[source]

Convert a date into a week number string, with year

ternip.rule_engine.normalisation_functions.date_functions.easter_date(y)[source]

Return the date of Easter for that year as a string

ternip.rule_engine.normalisation_functions.date_functions.extract_timezone(string)[source]

Given some string, try and extract the timezone it refers to. Returns a string.

ternip.rule_engine.normalisation_functions.date_functions.normalise_two_digit_year(y)[source]

Given a year string, which could be 2 digits, try and get a 4 digit year out of it as a string

ternip.rule_engine.normalisation_functions.date_functions.nth_dow_to_day()[source]

Figures out the day of the nth day-of-week in the month m and year y as an integer

e.g., 2nd Wednesday in July 2010:
nth_dow_to_day((7, 3, 2), 2010)

Conversion from GUTime

relative_date_functions Module

ternip.rule_engine.normalisation_functions.relative_date_functions.compute_offset_base(ref_date, expression, current_direction)[source]

Given a reference date, some simple expression (yesterday/tomorrow or a day of week) and the direction of the relative expression, the base date with which to compute the offset from as a date string

ternip.rule_engine.normalisation_functions.relative_date_functions.offset_from_date(v, offset, gran='D', exact=False)[source]

Given a date string and some numeric offset, as well as a unit, then compute the offset from that value by offset gran’s. Gran defaults to D. If exact is set to true, then the exact date is figured out, otherwise the level of granuality given by gran is used. Returns a date string.

ternip.rule_engine.normalisation_functions.relative_date_functions.relative_direction_heuristic(before, after)[source]

Given what preceeds and proceeds a TIMEX, then use heuristics to use tense to compute which direction a relative expression is in. Converted from GUTime.

string_conversions Module

Functions which convert strings to some number index

ternip.rule_engine.normalisation_functions.string_conversions.build_duration_value(num, unit)[source]
ternip.rule_engine.normalisation_functions.string_conversions.day_to_num(day)[source]

Given the name of a day, the number of that day. Sunday is 0. Invalid data gets 7. All returned as integers.

ternip.rule_engine.normalisation_functions.string_conversions.decade_nums(dec)[source]

Given the decade component (less the ty suffix) of a year, the number of that year as an integer.

ternip.rule_engine.normalisation_functions.string_conversions.fixed_holiday_date(hol)[source]

Get the date string MMDD of a holiday

ternip.rule_engine.normalisation_functions.string_conversions.month_to_num(m)[source]

Given a name of a month, get the number of that month. Invalid data gets 0. Returned as an integer.

ternip.rule_engine.normalisation_functions.string_conversions.nth_dow_holiday_date(hol)[source]

Given the name of a holiday which always occur on the Nth X of some month, where X is day of week, returns tuples of the form (month, dow, n) representing the information about that holiday.

ternip.rule_engine.normalisation_functions.string_conversions.season(s)[source]

Transforms a season name into an identifer from TIDES. Invalid data gets returned as is

ternip.rule_engine.normalisation_functions.string_conversions.season_to_month(s)[source]

Convert seasons to months (roughly), returns an int

ternip.rule_engine.normalisation_functions.string_conversions.units_to_gran(unit)[source]

Given a word, or part of a word, that represents a unit of time, return the single character representing the granuality of that unit of time

words_to_num Module

ternip.rule_engine.normalisation_functions.words_to_num.ordinal_to_num(o)[source]

Given an ordinal (i.e., thirty-first or second) in the range 1st-31st (both numbers and words accepted), return the number value of that ordinal. Unrecognised data gets 1. Returns an integer

ternip.rule_engine.normalisation_functions.words_to_num.words_to_num(words)[source]

Converted from GUTime. Given a string of number words, attempts to derive the numerical value of those words. Returns an integer.