def test_extract_duration_de(self): self.assertEqual(extract_duration("10 sekunden", lang="de-de"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5 minuten", lang="de-de"), (timedelta(minutes=5), "")) self.assertEqual(extract_duration("2 stunden", lang="de-de"), (timedelta(hours=2), "")) self.assertEqual(extract_duration("3 tage", lang="de-de"), (timedelta(days=3), "")) self.assertEqual(extract_duration("25 wochen", lang="de-de"), (timedelta(weeks=25), "")) # TODO no german text to number parsing yet #self.assertEqual(extract_duration("sieben stunden"), # (timedelta(hours=7), "")) self.assertEqual(extract_duration("7.5 sekunden", lang="de-de"), (timedelta(seconds=7.5), "")) #self.assertEqual(extract_duration("eight and a half days thirty" # " nine seconds"), # (timedelta(days=8.5, seconds=39), "")) self.assertEqual( extract_duration("starte timer für 30 minuten", lang="de-de"), (timedelta(minutes=30), "starte timer für")) #self.assertEqual(extract_duration("Four and a half minutes until" # " sunset"), # (timedelta(minutes=4.5), "until sunset")) #self.assertEqual(extract_duration("Nineteen minutes past the hour"), # (timedelta(minutes=19), "past the hour")) self.assertEqual( extract_duration( "weck mich in 3 wochen, " " 497 tage und" " 391.6 sekunden", lang="de-de"), (timedelta( weeks=3, days=497, seconds=391.6), "weck mich in , und")) #self.assertEqual(extract_duration("The movie is one hour, fifty seven" # " and a half minutes long"), # (timedelta(hours=1, minutes=57.5), # "the movie is , long")) self.assertEqual(extract_duration("10-sekunden", lang="de-de"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5-minuten", lang="de-de"), (timedelta(minutes=5), ""))
def test_extract_duration_nl(self): self.assertEqual(extract_duration("een minuut", LANG), (timedelta(seconds=60), "")) self.assertEqual(extract_duration("10 minuten", LANG), (timedelta(seconds=600), "")) self.assertEqual(extract_duration("een uur en 2 minuten", LANG), (timedelta(seconds=3720), "en")) self.assertEqual(extract_duration("een dag", LANG), (timedelta(days=1), "")) self.assertEqual(extract_duration("twee dag", LANG), (timedelta(days=2), "")) self.assertEqual(extract_duration("vijf minuten na het uur", LANG), (timedelta(seconds=300), "na het uur")) self.assertEqual(extract_duration("zet een timer voor 1 uur", LANG), (timedelta(seconds=3600), "zet 1 timer voor")) self.assertEqual( extract_duration( "een treinrit van 2 uur, 17 minuten en zestien seconden", LANG), (timedelta(seconds=8236), "1 treinrit van , en")) self.assertEqual(extract_duration("een uurtje", LANG), (timedelta(seconds=3600), ""))
def handle_start_timer(self, data): print(data) if 'duration' in data: print(extract_duration(data['duration']), languages_utils.get_language()) if 'name' in data: print("Start timer for {} named {}".format( data['duration'], data['name'])) pass else: print("Start timer for {} without name".format( data['duration'])) # TODO : ask for name pass else: print("No amount and/or time_unit") pass
def test_extract_duration_pl(self): self.assertEqual(extract_duration("10 sekund"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5 minut"), (timedelta(minutes=5), "")) self.assertEqual(extract_duration("2 godziny"), (timedelta(hours=2), "")) self.assertEqual(extract_duration("3 dni"), (timedelta(days=3), "")) self.assertEqual(extract_duration("25 tygodni"), (timedelta(weeks=25), "")) self.assertEqual(extract_duration("siedem godzin"), (timedelta(hours=7), "")) self.assertEqual(extract_duration("7.5 sekundy"), (timedelta(seconds=7.5), "")) self.assertEqual( extract_duration("osiem i pół dnia trzydzieści dziewięć sekund", lang='pl-pl'), (timedelta(days=8.5, seconds=39), "")) self.assertEqual(extract_duration("Ustaw stoper na 30 minut"), (timedelta(minutes=30), "ustaw stoper na")) self.assertEqual(extract_duration("Cztery i pół minuty do zachodu"), (timedelta(minutes=4.5), "do zachodu")) self.assertEqual( extract_duration("dziewiętnaście minut po pełnej godzinie"), (timedelta(minutes=19), "po pełnej godzinie")) self.assertEqual( extract_duration( "obudź mnie za 3 tygodnie, czterysta dziewięćdziesiąt siedem dni i" " trzysta 91.6 sekund"), (timedelta( weeks=3, days=497, seconds=391.6), "obudź mnie za , i")) self.assertEqual( extract_duration( "ten film trwa jedną godzinę, pięćdziesiąt siedem i pół minuty", lang='pl-pl'), (timedelta(hours=1, minutes=57.5), "ten film trwa ,")) self.assertEqual(extract_duration("10-sekund"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5-minut"), (timedelta(minutes=5), ""))
def test_extract_duration_en(self): self.assertEqual(extract_duration("10 seconds"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5 minutes"), (timedelta(minutes=5), "")) self.assertEqual(extract_duration("2 hours"), (timedelta(hours=2), "")) self.assertEqual(extract_duration("3 days"), (timedelta(days=3), "")) self.assertEqual(extract_duration("25 weeks"), (timedelta(weeks=25), "")) self.assertEqual(extract_duration("seven hours"), (timedelta(hours=7), "")) self.assertEqual(extract_duration("7.5 seconds"), (timedelta(seconds=7.5), "")) self.assertEqual( extract_duration("eight and a half days thirty" " nine seconds"), (timedelta(days=8.5, seconds=39), "")) self.assertEqual(extract_duration("Set a timer for 30 minutes"), (timedelta(minutes=30), "set a timer for")) self.assertEqual( extract_duration("Four and a half minutes until" " sunset"), (timedelta(minutes=4.5), "until sunset")) self.assertEqual(extract_duration("Nineteen minutes past the hour"), (timedelta(minutes=19), "past the hour")) self.assertEqual( extract_duration("wake me up in three weeks, four" " hundred ninety seven days, and" " three hundred 91.6 seconds"), (timedelta(weeks=3, days=497, seconds=391.6), "wake me up in , , and")) self.assertEqual( extract_duration("The movie is one hour, fifty seven" " and a half minutes long"), (timedelta(hours=1, minutes=57.5), "the movie is , long"))
assert extract_number("six trillion") == 6000000000000.0 assert extract_number("six trillion", short_scale=False) == 6e+18 assert extract_number("1 and 3/4 cups") == 1.75 assert extract_number("1 cup and a half") == 1.5 ## extracts all numbers assert extract_numbers("nothing") == [] assert extract_numbers("this is a one twenty one test") == [1.0, 21.0] assert extract_numbers("1 dog, seven pigs, macdonald had a farm, " "3 times 5 macarena") == [1, 7, 3, 5] ## extract durations from datetime import timedelta assert extract_duration("nothing") == (None, 'nothing') assert extract_duration("Nineteen minutes past the hour") == (timedelta( minutes=19), "past the hour") assert extract_duration("wake me up in three weeks, four hundred ninety seven" " days, and three hundred 91.6 seconds") == (timedelta( weeks=3, days=497, seconds=391.6), "wake me up in , , and") assert extract_duration( "The movie is one hour, fifty seven and a half minutes long") == ( timedelta(hours=1, minutes=57.5), "the movie is , long") ## extract date times from datetime import datetime
def test_extract_duration_cs(self): self.assertEqual(extract_duration("10 sekund"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5 minut"), (timedelta(minutes=5), "")) self.assertEqual(extract_duration("2 hodiny"), (timedelta(hours=2), "")) self.assertEqual(extract_duration("3 dny"), (timedelta(days=3), "")) self.assertEqual(extract_duration("25 týdnů"), (timedelta(weeks=25), "")) self.assertEqual(extract_duration("sedm hodin"), (timedelta(hours=7), "")) self.assertEqual(extract_duration("7.5 sekund"), (timedelta(seconds=7.5), "")) self.assertEqual(extract_duration("osm a polovina dne třicet" " devět sekund"), (timedelta(days=8.5, seconds=39), "")) self.assertEqual(extract_duration("Nastav časovač na 30 minut"), (timedelta(minutes=30), "nastav časovač na")) self.assertEqual(extract_duration("Čtyři a půl minuty do" " západu"), (timedelta(minutes=4.5), "do západu")) self.assertEqual(extract_duration("devatenáct minut po hodině"), (timedelta(minutes=19), "po hodině")) self.assertEqual(extract_duration("vzbuď mě za tři týdny, čtyři" " sto devadesát sedm dní, a" " tři sto 91.6 sekund"), (timedelta(weeks=3, days=497, seconds=391.6), "vzbuď mě za , , a")) self.assertEqual(extract_duration("film je jedna hodina, padesát sedm" " a půl minuty dlouhý"), (timedelta(hours=1, minutes=57.5), "film je , dlouhý")) self.assertEqual(extract_duration("10-sekund"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5-minut"), (timedelta(minutes=5), ""))
def test_extract_duration_fr(self): self.assertEqual(extract_duration("10 secondes", lang="fr-fr"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5 minutes", lang="fr-fr"), (timedelta(minutes=5), "")) self.assertEqual(extract_duration("2 heures", lang="fr-fr"), (timedelta(hours=2), "")) self.assertEqual(extract_duration("3 jours", lang="fr-fr"), (timedelta(days=3), "")) self.assertEqual(extract_duration("25 semaines", lang="fr-fr"), (timedelta(weeks=25), "")) # No conversion for work to number yet for fr self.assertEqual(extract_duration("sept heures"), (timedelta(hours=7), "")) self.assertEqual(extract_duration("7.5 secondes", lang="fr-fr"), (timedelta(seconds=7.5), "")) self.assertEqual(extract_duration("5 jours et vingt-neuf secondes"), (timedelta(days=5, seconds=29), "et")) # Fraction not yet implemented #self.assertEqual(extract_duration("huit jours et demi et trente-neuf secondes"), # (timedelta(days=8.5, seconds=39), "et ")) self.assertEqual( extract_duration("démarre un minuteur pour 30 minutes", lang="fr-fr"), (timedelta(minutes=30), "démarre 1 minuteur pour")) #self.assertEqual(extract_duration("Quatre minutes et demi avant le coucher du soleil"), # (timedelta(minutes=4.5), "avant le coucher du soleil")) self.assertEqual(extract_duration("Une heure dix-neuf minutes"), (timedelta(hours=1, minutes=19), "")) self.assertEqual( extract_duration( "réveille moi dans 3 semaines, " " 497 jours et" " 391.6 secondes", lang="fr-fr"), (timedelta(weeks=3, days=497, seconds=391.6), "réveille moi dans et")) self.assertEqual( extract_duration("Le film dure une heure, cinquante-sept minutes"), (timedelta(hours=1, minutes=57), "film dure")) self.assertEqual(extract_duration("10-secondes", lang="fr-fr"), (timedelta(seconds=10.0), "")) self.assertEqual(extract_duration("5-minutes", lang="fr-fr"), (timedelta(minutes=5), ""))