Not able to extract entity

Problem:- I have pincode.txt file and I want to serach in this file that user give input pincode. Means I can’t hard code all pincodes in entity or slots. Possible solutions I have tried or think for this : 1> Use lookup table for that but Don’t know how to do it , means how to utter message when pincode not in my lookup table 2> Use custom action for that but not able to extract entity. So, anybody can help me out from this . here are releated flies that I have made

Path41

  • unableupdate_pincode
    • utter_unableupdate_pincode
  • share_pincode
    • action_pincode
    • slot{“pincode”:“123456”}

entities:

  • pincode slots: pincode: type: text

class Actionpincode(Action): def name(self): return “action_pincode”

def run(self, dispatcher, tracker, domain):
    path = '/home/saurbh/Desktop/intern/my_project/rasa/pincode.txt'
    pincode_file = open(path,'r')
    pin = tracker.get_slot('pincode')
    
    global flag
    flag=0
    
    for i in pincode_file:
        print(i)
        if i==pin:
            flag=1
    pincode_file.close()

    if flag==1:
        dispatcher.utter_message("yes")
        return []
    else :
        dispatcher.utter_message("no")
        return []

intent:unableupdate_pincode

  • Payme India, your app is not accepting my pincode?

  • I am not able to update my Pincode.

  • Your app is not allowing me to update my pincode?

intent:share_pincode

regex:pincode

  • [0-9]{6}

I think the for loop is not doing what you want it to do. Try this:

pin=tracker.get_slot(‘pincode’) with open(“pincode.txt”,“r”) as file: for line in file: for word in line.split(): #print(word) if pin==word: flag=1

if flag==1: dispatcher.utter_message(“Yes”) else: dispatcher.utter_message(“No”)

I think this would work for matching the pincode in the file.

@varunsapre10 thanks, But in pincode.txt file i have only pincodes means one pincode in one linepincode.txt (131.3 KB) . I think slots are not properly tracked in variable pin

In that case, try removing the ‘for line in line’ loop and keep ‘word’ loop as the main one. Maybe change “if pin==word” TO “if pin in word”. It is upto you.

@varunsapre10, I’m not getting can you please write it

Sure, Try doing this: with open(“pincode.txt”,“r”) as file: for word in file: if pin in word: flag=1

if flag==1: dispatcher.utter_message(“Yes”) ’ else: dispatcher.utter_message(“No”)

@varunsapre10, not working . I think this is not the error

Can you send the error.

sure,

Try this exact :

def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

pin = str(tracker.get_slot('pincode'))
global flag
flag=0

with open('pincode.txt') as file:
    for line in file:
        for word in line.split():
            if pin in word:
                flag=1
    file.close()

if flag==1:
    dispatcher.utter_message("yes")
    return []
else :
    dispatcher.utter_message("no")
    return []

Also the ‘run’ function needs the above mentioned parameters according to the format by rasa. The type of get_slot is NONE, so we convert it to str.

still not working

@varunsapre10, You are right but my entity is not extracted correctly beacause it is always utter “no” even given input is from this file

Check if you kept the entity name same as the slot name?

Can anybody tell me what should I do ?

yes it same as I mentioned above You can see there