MCPcopy Create free account
hub / github.com/LHRLAB/ChatKBQA / date_post_process

Function date_post_process

eval_final.py:72–88  ·  view source on GitHub ↗

When quering KB, (our) KB tends to autoComplete a date e.g. - 1996 --> 1996-01-01 - 1906-04-18 --> 1906-04-18 05:12:00

(date_string)

Source from the content-addressed store, hash-verified

70
71
72def date_post_process(date_string):
73 """
74 When quering KB, (our) KB tends to autoComplete a date
75 e.g.
76 - 1996 --> 1996-01-01
77 - 1906-04-18 --> 1906-04-18 05:12:00
78 """
79 pattern_year_month_date = r"^\d{4}-\d{2}-\d{2}$"
80 pattern_year_month_date_moment = r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$"
81
82 if re.match(pattern_year_month_date_moment, date_string):
83 if date_string.endswith('05:12:00'):
84 date_string = date_string.replace('05:12:00', '').strip()
85 elif re.match(pattern_year_month_date, date_string):
86 if date_string.endswith('-01-01'):
87 date_string = date_string.replace('-01-01', '').strip()
88 return date_string
89
90
91

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected