def parse_all(user_input: str, culture: str) -> List[ModelResult]: return [ # Number recognizer - This function will find any number from the input # E.g "I have two apples" will return "2". NumberRecognizer.recognize_number(user_input, culture), # Ordinal number recognizer - This function will find any ordinal number # E.g "eleventh" will return "11". NumberRecognizer.recognize_ordinal(user_input, culture), # Percentage recognizer - This function will find any number presented as percentage # E.g "one hundred percents" will return "100%" NumberRecognizer.recognize_percentage(user_input, culture), # Age recognizer - This function will find any age number presented # E.g "After ninety five years of age, perspectives change" will return "95 Year" NumberWithUnitRecognizer.recognize_age(user_input, culture), # Currency recognizer - This function will find any currency presented # E.g "Interest expense in the 1988 third quarter was $ 75.3 million" will return "75300000 Dollar" NumberWithUnitRecognizer.recognize_currency(user_input, culture), # Dimension recognizer - This function will find any dimension presented # E.g "The six-mile trip to my airport hotel that had taken 20 minutes earlier in the day took more than three hours." will return "6 Mile" NumberWithUnitRecognizer.recognize_dimension(user_input, culture), # Temperature recognizer - This function will find any temperature presented # E.g "Set the temperature to 30 degrees celsius" will return "30 C" NumberWithUnitRecognizer.recognize_temperature(user_input, culture), # DateTime recognizer - This function will find any Date even if its write in colloquial language - # E.g "I'll go back 8pm today" will return "2017-10-04 20:00:00" DateTimeRecognizer.recognize_datetime(user_input, culture) ]
class DateRecognizer: def __init__(self): self.date_recognizer = None self.date_recognizer_model = None self.init_date_recognizer() def init_date_recognizer(self): self.date_recognizer = DateTimeRecognizer() self.date_recognizer_model = self.date_recognizer.get_datetime_model( Culture.Chinese) def parse_date(self, text): result = self.date_recognizer_model.parse(text) dates = [] for r in result: print(r.text, r.type_name, r.resolution) resolution = r.resolution if resolution: if resolution['values'][0]['type'] == "daterange": if not resolution['values'][0]['timex'] or resolution[ 'values'][0]['value'] == 'not resolved': continue dates.append({ "type": resolution['values'][0]['type'], "start": resolution['values'][0]['start'], "end": resolution['values'][0]['end'], "text": r.text }) elif resolution['values'][0]['type'] == "date": dates.append({ "type": resolution['values'][0]['type'], "entity": resolution['values'][0]['value'], "text": r.text }) elif resolution['values'][0]['type'] == "datetime": dates.append({ "type": resolution['values'][0]['type'], "entity": resolution['values'][0]['value'], "text": r.text }) elif resolution['values'][0]['type'] == "duration": dates.append({ "type": resolution['values'][0]['type'], "entity": resolution['values'][0]['timex'].replace('P', '').replace( 'T', ''), "text": r.text }) return dates
content = f.readlines() LIST_PHONE_DEF = [x.strip() for x in content] with open("post_processing/field_dictionary/prices.txt") as f: content = f.readlines() LIST_PRICES_DEF = [x.strip() for x in content] with open("post_processing/field_dictionary/prices_prioritize.txt") as f: content = f.readlines() LIST_PRICES_PRIORITIZE_DEF = [x.strip() for x in content] with open("post_processing/field_dictionary/date.txt") as f: content = f.readlines() LIST_DATE_DEF = [x.strip() for x in content] model = DateTimeRecognizer(Culture.English).get_datetime_model() def postprocessTimestamp(raw_input): raw_input = raw_input.split('|||') print(raw_input) if len(raw_input) == 1: return extractTimestamp(raw_input[0]) # return raw_input[0] res = [] day_symbol = ['/','-','.'] has_colon = False for component in raw_input: bad_word = ['HET HAN','LAM VIEC','CODE'] isbad = False for x in re.findall('[0-9]+', component):
def init_date_recognizer(self): self.date_recognizer = DateTimeRecognizer() self.date_recognizer_model = self.date_recognizer.get_datetime_model( Culture.Chinese)