date and time - for tonight, weekdays (#2023)

* date and time - for tonight, weekdays

* Updating the previous commit test_extractdatetime_en

* Editing comments for extract_date_time_en

* Generalized as a marker

Expanded this from just handling "weekends" to any day or plural of the day, "weekend", "weekday" or "weekdays".
pull/2024/head
Ruthvicp 2019-02-28 01:15:55 -06:00 committed by Steve Penrod
parent 4bacdeaee6
commit ec7ed25ed5
2 changed files with 29 additions and 1 deletions

View File

@ -741,7 +741,7 @@ def extract_datetime_en(string, dateNow, default_time):
timeQualifier = ""
timeQualifiersAM = ['morning']
timeQualifiersPM = ['afternoon', 'evening', 'tonight', 'night']
timeQualifiersPM = ['afternoon', 'evening', 'night']
timeQualifiersList = set(timeQualifiersAM + timeQualifiersPM)
markers = ['at', 'in', 'on', 'by', 'this', 'around', 'for', 'of', "within"]
days = ['monday', 'tuesday', 'wednesday',
@ -749,6 +749,8 @@ def extract_datetime_en(string, dateNow, default_time):
months = ['january', 'february', 'march', 'april', 'may', 'june',
'july', 'august', 'september', 'october', 'november',
'december']
recur_markers = days + [d+'s' for d in days] + ['weekend', 'weekday',
'weekends', 'weekdays']
monthsShort = ['jan', 'feb', 'mar', 'apr', 'may', 'june', 'july', 'aug',
'sept', 'oct', 'nov', 'dec']
year_multiples = ["decade", "century", "millennium"]
@ -815,6 +817,9 @@ def extract_datetime_en(string, dateNow, default_time):
elif word == "today" and not fromFlag:
dayOffset = 0
used += 1
elif word == "tonight" and not fromFlag:
dayOffset = 0
used += 1
elif word == "tomorrow" and not fromFlag:
dayOffset = 1
used += 1
@ -1165,6 +1170,15 @@ def extract_datetime_en(string, dateNow, default_time):
strHH = strNum
remainder = "am"
used = 1
elif (
remainder in recur_markers or
wordNext in recur_markers or
wordNextNext in recur_markers):
# Ex: "7 on mondays" or "3 this friday"
# Set strHH so that isTime == True
# when am or pm is not specified
strHH = strNum
used = 1
else:
if (
int(strNum) > 100 and

View File

@ -455,6 +455,20 @@ class TestNormalize(unittest.TestCase):
"2017-07-08 10:00:00", "remind me to call mom")
testExtract("remind me to call mom at 10am next saturday",
"2017-07-08 10:00:00", "remind me to call mom")
# Below two tests, ensure that time is picked
# even if no am/pm is specified
# in case of weekdays/tonight
testExtract("set alarm for 9 on weekdays",
"2017-06-27 21:00:00", "set alarm weekdays")
testExtract("for 8 tonight",
"2017-06-27 20:00:00", "")
testExtract("for 8:30pm tonight",
"2017-06-27 20:30:00", "")
# Tests a time with ':' & without am/pm
testExtract("remind me about the game tonight at 11:30",
"2017-06-27 23:30:00", "remind me about game")
testExtract("set alarm at 7:30 on weekdays",
"2017-06-27 19:30:00", "set alarm on weekdays")
def test_extract_ambiguous_time_en(self):
morning = datetime(2017, 6, 27, 8, 1, 2)