def resolve_by_timerange_constraints(candidates, timex_constraints): timerange_contraints = list( map( lambda ti: TimexHelpers.timerange_from_timex(ti), filter(lambda t: Constants.TIMEX_TYPES_TIMERANGE in t.types, timex_constraints))) collapsed_time_ranges = TimexConstraintsHelper.collapse( TimexConstraintsHelper(), timerange_contraints) if not any(collapsed_time_ranges): return candidates resolution = [] for timex in candidates: t = Timex(timex) if Constants.TIMEX_TYPES_TIMERANGE in t.types: r = TimexRangeResolver.resolve_timerage( t, collapsed_time_ranges) resolution.extend(r) elif Constants.TIMEX_TYPES_TIME in t.types: r = TimexRangeResolver.resolve_time(t, collapsed_time_ranges) resolution.extend(r) return TimexRangeResolver.remove_duplicates(resolution)
def resolve_timerage(timex: Timex, constraints: [TimeRange]): candidate = TimexHelpers.timerange_from_timex(timex) result = [] for contraint in constraints: if candidate.is_overlapping(contraint): start = max(candidate.start.get_time(), contraint.start.get_time()) time = Time.from_seconds(start) resolved = copy.copy(timex) resolved.part_of_day = None resolved.seconds = None resolved.minutes = None resolved.hours = None resolved.second = time.second resolved.minute = time.minute resolved.hour = time.hour result.append(resolved.timex_value()) return result