|
4 | 4 | import re |
5 | 5 | from datetime import timedelta, datetime |
6 | 6 | from dateutil.relativedelta import relativedelta |
7 | | -from mycroft_lang_utils.lang.parse_en import _convert_words_to_numbers, \ |
| 7 | +from lingua_franca.lang.parse_en import _convert_words_to_numbers_en, \ |
8 | 8 | is_numeric, extractnumber_en |
9 | | -from mycroft_lang_utils.format import nice_duration, nice_date |
10 | | -from mycroft_lang_utils.time import now_local |
| 9 | +from lingua_franca.format import nice_duration, nice_date |
11 | 10 |
|
12 | 11 |
|
13 | 12 | def _annotate_datetime_en(string, dateNow=None, default_time=None): |
@@ -37,7 +36,7 @@ def _annotate_datetime_en(string, dateNow=None, default_time=None): |
37 | 36 | text consumed in the parsing, or None if no |
38 | 37 | date or time related text was found. |
39 | 38 | """ |
40 | | - dateNow = dateNow or now_local() |
| 39 | + dateNow = dateNow or datetime.now() |
41 | 40 |
|
42 | 41 | def clean_string(s): |
43 | 42 | # clean unneeded punctuation and capitalization among other things. |
@@ -854,7 +853,7 @@ def _annotate_duration_en(text): |
854 | 853 | } |
855 | 854 |
|
856 | 855 | pattern = r"(?P<value>\d+(?:\.?\d+)?)\s+{unit}s?" |
857 | | - norm_text = _convert_words_to_numbers(text) |
| 856 | + norm_text = _convert_words_to_numbers_en(text) |
858 | 857 | t = norm_text |
859 | 858 | duration_text = text |
860 | 859 |
|
@@ -915,7 +914,7 @@ def _annotate_duration_en(text): |
915 | 914 | class DateTimeNER(NERWrapper): |
916 | 915 | def __init__(self, anchor_date=None): |
917 | 916 | super().__init__() |
918 | | - self.anchor_date = anchor_date or now_local() |
| 917 | + self.anchor_date = anchor_date or datetime.now() |
919 | 918 | self.add_detector(self.annotate_datetime) |
920 | 919 | self.add_detector(self.annotate_duration) |
921 | 920 |
|
@@ -972,24 +971,6 @@ def annotate(self, text): |
972 | 971 | } |
973 | 972 | yield Entity(value, "date", source_text=text, data=data) |
974 | 973 |
|
975 | | - def _old_annotate(self, text): |
976 | | - # deprecated |
977 | | - import datefinder |
978 | | - matches = datefinder.find_dates(text, index=True) |
979 | | - for date, span in matches: |
980 | | - value = text[span[0]:span[1]].strip() |
981 | | - data = { |
982 | | - "timestamp": date.timestamp(), |
983 | | - "isoformat": date.isoformat(), |
984 | | - "weekday": date.isoweekday(), |
985 | | - "month": date.month, |
986 | | - "day": date.day, |
987 | | - "hour": date.hour, |
988 | | - "minute": date.minute, |
989 | | - "year": date.year |
990 | | - } |
991 | | - yield Entity(value, "date", source_text=text, data=data) |
992 | | - |
993 | 974 |
|
994 | 975 | if __name__ == "__main__": |
995 | 976 | from pprint import pprint |
|
0 commit comments