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) ]
async def on_recognize( self, turn_context: TurnContext, state: Dict[str, object], options: PromptOptions, ) -> PromptRecognizerResult: if not turn_context: raise TypeError("turn_context can’t be none") if turn_context.activity.type == ActivityTypes.message: utterance = turn_context.activity.text turn_context.activity.locale = self._default_locale recognizer_result = PromptRecognizerResult() recognizer = NumberRecognizer(turn_context.activity.locale) if (self._prompt_type == NumberWithTypePromptType.Ordinal): model = recognizer.get_ordinal_model() elif (self._prompt_type == NumberWithTypePromptType.Percentage): model = recognizer.get_percentage_model() model_result = model.parse(utterance) if len(model_result) > 0 and len(model_result[0].resolution) > 0: recognizer_result.succeeded = True recognizer_result.value = model_result[0].resolution["value"] return recognizer_result
def perform_ner(self, filepath: str, entity_type: str = 'number', update: bool = False) -> str: newfilepath = os.path.join( self.storage_path, entity_type + '_' + os.path.basename(filepath)) if not update and os.path.exists(newfilepath): return newfilepath wfile = open(newfilepath, 'w') filepath = os.path.abspath(filepath) rfile = open(filepath, 'r') recognizer = NumberRecognizer(Culture.English) model = recognizer.get_number_model() for line in rfile: answer = next(rfile) answer_json = json.loads(answer) text = str(answer_json['body']) try: result = model.parse(text) if result: for x in result: if x.type_name == entity_type: wfile.write(line) wfile.write(answer) break except Exception as e: print(e) return newfilepath
def _recognize_ordinal(utterance: str, culture: str) -> List[ModelResult]: model: OrdinalModel = NumberRecognizer(culture).get_ordinal_model( culture) return list( map(ChoiceRecognizers._found_choice_constructor, model.parse(utterance)))