How to validate entities?

Hi,

I am trying to create a bot regarding weather. I have called weather API and going well. But I have doubts about how can we validate the “location” entity.

Example:

Bot: which location do you want to check for?
You: Mumbai 
Bot: Haze in Mumbai and temperature is 27 degrees Celcius and Humidity 89%

And if give “12345” it should render “please enter the correct location”.

Bot: which location do you want to check for?
You: 123456
Bot: please enter the correct location

@manoj_kumar Hope you have seen this Forms ?

2 Likes

Yes @nik202 , But I getting confused while implementing the validation.

class ActionWeather(Action):

def name(self) -> Text:
    return "action_weather"

def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    
    loc=tracker.get_slot('location')
    temp = int(Weather(loc)['temp']-273)
    hum =  int(Weather(loc)['humidity'])
    cond = Weather_Condition()[0]['description']
    dispatcher.utter_message(template="utter_temp", LOC=loc, temp=temp, hum=hum, condition=cond)
       
    #return [SlotSet('location',loc)]
    return []

class ValidateWeatherForm(FormValidationAction):

    def name(self) -> Text:
        return "validate_weather_form"
    
    def validate_location(
    self,
    slot_value: Text,
    dispatcher: CollectingDispatcher,
    tracker: Tracker,
    domain: DomainDict,
) ->Dict[Text, Any]:
        
        #loc=tracker.get_slot('location')
        #if slot_value and slot_value.lower() in loc:
            #if loc.isalpha() == True:
                #return {"location": slot_value}
        #if not loc.isalpha() == True:
            #dispatcher.utter_message(template = "utter_invalid")
            #return{"location": None}
        if (str(slot_value.isalpha()))==False:
            dispatcher.utter_message(template="utter_invalid")
            return{"location": None}
        else:
            return {"location": slot_value}

Hi @nik202,

Can I use spacy to validate the location name?

@manoj_kumar means ?