Skip to content

Instantly share code, notes, and snippets.

@rishisidhu
Last active January 30, 2020 02:09
Show Gist options
  • Save rishisidhu/42488235acc6363b5f997145f272d971 to your computer and use it in GitHub Desktop.
Save rishisidhu/42488235acc6363b5f997145f272d971 to your computer and use it in GitHub Desktop.
A retrieval based python chatbot that acts as an FAQ Answerer
#Imports
import string
import random
import nltk
from nltk.tokenize import sent_tokenize, word_tokenize
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
from nltk.tokenize import PunktSentenceTokenizer
import sklearn
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import pandas as pd
from termcolor import colored
#NLTK Downloads (Need to do only once)
nltk.download('punkt')
nltk.download('stopwords')
nltk.download('averaged_perceptron_tagger')
nltk.download('wordnet')
nltk.download('nps_chat')
#Global Constants
GREETING_INPUTS = ("hello", "hi")
GREETING_RESPONSES = ["hi", "hey", "*nods*", "hi there", "Talkin' to me?"]
FILENAME = "canada_faq.txt"
#Global Variables
lem = nltk.stem.WordNetLemmatizer()
remove_punctuation = dict((ord(punct), None) for punct in string.punctuation)
#Functions
'''
fetch_features transforms a chat into a classifier friendly format
'''
def fetch_features(chat):
features = {}
for word in nltk.word_tokenize(chat):
features['contains({})'.format(word.lower())] = True
return features
'''
lemmatise performs lemmatization on words
'''
def lemmatise(tokens):
return [lem.lemmatize(token) for token in tokens]
'''
tokenise tokenizes the words
'''
def tokenise(text):
return lemmatise(nltk.word_tokenize(text.lower().translate(remove_punctuation)))
'''
Standard greeting responses that the bot can recognize and respond with
'''
def greet(sentence):
for word in sentence.split():
if word.lower() in GREETING_INPUTS:
return random.choice(GREETING_RESPONSES)
'''
match matches a user input to the existing set of questions
'''
def match(user_response):
resp =''
q_list.append(user_response)
TfidfVec = TfidfVectorizer(tokenizer=tokenise, stop_words='english')
tfidf = TfidfVec.fit_transform(q_list)
vals = cosine_similarity(tfidf[-1], tfidf)
idx = vals.argsort()[0][-2]
flat = vals.flatten()
flat.sort()
req_tfidf = flat[-2]
if(req_tfidf==0):
resp = resp+"Sorry! I don't know the answer to this. Would you like to try again? Type Ciao to exit"
return resp
else:
resp_ids = qa_dict[idx]
resp_str = ''
s_id = resp_ids[0]
end = resp_ids[1]
while s_id<end :
resp_str = resp_str + " " + sent_tokens[s_id]
s_id+=1
resp = resp+resp_str
return resp
#Training the classifier
chats = nltk.corpus.nps_chat.xml_posts()[:10000]
featuresets = [(fetch_features(chat.text), chat.get('class')) for chat in chats]
size = int(len(featuresets) * 0.1)
train_set, test_set = featuresets[size:], featuresets[:size]
classifier = nltk.MaxentClassifier.train(train_set)
#classifier = nltk.NaiveBayesClassifier.train(train_set) #If you need to test Naive Bayes as well
print(nltk.classify.accuracy(classifier, test_set))
#Question Bank Creation
ques_bank = open(FILENAME,'r',errors = 'ignore')
qb_text = ques_bank.read()
qb_text = qb_text.lower()
sent_tokens = nltk.sent_tokenize(qb_text)# converts to list of sentences
word_tokens = nltk.word_tokenize(qb_text)# converts to list of words
qa_dict = {} #The Dictionary to store questions and corresponding answers
q_list = [] #List of all questions
s_count = 0 #Sentence counter
#Extract questions and answers
#Answer is all the content between 2 questions [assumption]
while s_count < len(sent_tokens):
result = classifier.classify(fetch_features(sent_tokens[s_count]))
if("question" in result.lower()):
next_question_id = s_count+1
next_question = classifier.classify(fetch_features(sent_tokens[next_question_id]))
while(not("question" in next_question.lower()) and next_question_id < len(sent_tokens)-1):
next_question_id+=1
next_question = classifier.classify(fetch_features(sent_tokens[next_question_id]))
q_list.append(sent_tokens[s_count])
end = next_question_id
if(next_question_id-s_count > 5):
end = s_count+5
qa_dict.update({len(q_list)-1:[s_count+1,end]})
s_count = next_question_id
else:
s_count+=1
#Response Fetching
flag=True
print(colored("NEO:\nI am Neo, I have all the answers If you want to exit, type Ciao",'blue',attrs=['bold']))
while(flag==True):
print(colored("\nYOU:",'red',attrs=['bold']))
u_input = input()
u_input = u_input.lower()
if(u_input!='ciao'):
if(greet(u_input)!=None):
print(colored("\nNEO:",'blue',attrs=['bold']))
print(greet(u_input))
else:
print(colored("\nNEO:",'blue',attrs=['bold']))
print(colored(match(u_input).strip().capitalize(),'blue'))
q_list.remove(u_input)
else:
flag=False
print(colored("\nNEO: Bye! take care..",'blue', attrs=['bold']))
@Gmercau1966
Copy link

de donde bajo el archivo : canada_faq.txt?

@rishisidhu
Copy link
Author

de donde bajo el archivo : canada_faq.txt?

You can scrape any site for their FAQs and paste the text into a txt file. For your reference I have pasted the canada_faq.txt text below
`

What is dual citizenship?
Every country decides whom it considers to be a citizen. If more than one country recognizes you as a citizen, you have dual citizenship.

You don’t apply for dual citizenship, and there is no related certificate. Canadians are allowed to take foreign citizenship while keeping their Canadian citizenship.

Ask the embassy of your country of citizenship about its rules before applying for Canadian citizenship.

For more information
Travelling as a dual citizen
Do I become a Canadian citizen when I marry a Canadian?
No. Marrying a Canadian citizen doesn’t give you citizenship.

If you want to become a Canadian citizen, you must follow the same steps as everyone else. There isn’t a special process for spouses of Canadian citizens.

You must meet several requirements to apply for citizenship. You must be physically present in Canada for at least 1,095 days during the five years right before the date you applied. This includes time as a:

permanent resident (PR)
temporary resident (lawfully authorized to remain in Canada)
protected person
Your Canadian spouse can sponsor you to become a permanent resident if you:

don’t live in Canada or
aren’t a permanent resident
You may apply for citizenship if you:

are a permanent resident
have been physically present in Canada long enough
meet the other requirements
There are different rules to determine if children of Canadians born outside Canada have Canadian citizenship.

For more information
Application processing times
I am Canadian but my children were born outside Canada. Are they Canadian?
Every situation is different. The official way to find out if your child is a citizen is to apply for a proof of citizenship for them.

This answer is only for people who were citizens when their children were born. If you got Canadian citizenship after your children were born, they did not automatically become citizens.

On April 17, 2009, the rules changed for persons born outside Canada to a Canadian parent.

My children were born before April 17, 2009
There are many laws and rules that affect if your children are Canadian. Most children born to Canadian parents before April 17, 2009, were citizens at birth.

Find out if they are Canadian by using the scenarios in the instruction guide for Proof of Citizenship.

Find out more about the citizenship rules for people born outside of Canada before April 17, 2009.

My children were born on or after April 17, 2009
Your children will only be Canadian at birth if you:

were born in Canada
became a naturalized Canadian citizen before they were born
if you were adopted, see the exceptions
There are exceptions to these rules.

You were born outside Canada and adopted by a Canadian
Your children born outside Canada will not be citizens if you:

were born outside Canada
were adopted by a Canadian citizen
became a Canadian citizen using the citizenship process for intercountry adoption
However, they will become citizens if their other parent was born in Canada or is a naturalized citizen.

Your children are born outside Canada while you are working for the Canadian government
Your children will be citizens at birth if, when they were born, you had a job with the:

Canadian Armed Forces
federal public administration
public service of a province or territory
This rule does not apply if you worked as a locally engaged person.

You were born outside Canada while your parent worked for the Canadian government
Your children will be citizens at birth if, when you were born outside Canada, your Canadian parent had a job with the:

Canadian Armed Forces
federal public administration
public service of a province or territory
This rule does not apply if your Canadian parent worked as a locally engaged person.

Can I count any time I’ve spent outside of Canada toward the physical presence requirement when applying for citizenship?
The time you spend outside of Canada doesn’t count toward your physical presence requirement, except in some cases.

You can count time spent outside Canada toward the physical presence requirement for citizenship if you:

were a permanent resident employed in or with the:
Canadian Armed Forces
federal public administration
public service of a province or territory
lived outside Canada with your Canadian spouse or common-law partner or permanent resident spouse, common-law partner, or parent who was employed in or with the:
Canadian Armed Forces
federal public administration
public service of a province or territory
This doesn’t include employment as a locally engaged person.

The physical presence requirement only uses time after:

becoming a permanent resident
your common-law relationship began (for calculating residence with a common-law partner)
Use the online physical presence calculator. Complete and submit the CIT 0177 Residence Outside Canada form when you apply. We’ll decide if we can count the time you lived outside Canada.

The travel journal is an easy way to record your time outside Canada. It will help you fill out the physical presence calculator or the Residence Outside Canada form.

Do I have to use the travel journal?
No, using the travel journal is optional. You don’t need to submit it with your application.

When you apply for a permanent resident card or citizenship, you need to be able to tell us about all your trips outside Canada during certain periods of time. We created the travel journal to help record the dates and destinations of your trips.

If I’m applying for citizenship, do I still have to submit the physical presence calculator if I submit the travel journal?
Yes, you must always submit one of the following physical presence calculators with adult, and some minor, citizenship applications:

a printed copy of the online physical presence calculator
the paper physical presence form (PDF, 1.83 MB) filled out by hand
An application without the physical presence calculator is incomplete, and we’ll return it to you.

You don’t need to submit the travel journal with your application. It’s for your personal use only, to help you complete the physical presence calculator.

If I’m transferring through different countries at the airport, or by car or train, do I need to record it in my travel journal?
If you don’t leave the airport during your stop, then you don’t need to record that country in your travel journal.

If you leave the airport, even if it’s only for a couple of hours, you should record the date and destination in the travel journal.

If you’re traveling by car or train, you’ll need to record dates and destinations of the countries you passed through.

How do I get more copies of the travel journal?
You can print more copies of the travel journal.

What is a non-routine application?
We consider your application non-routine if:

you asked to change your personal information, such as:
name
sex designation
date of birth
you missed a:
test
interview
hearing
we need you to submit extra documents, like:
fingerprints
residence documents
we asked you to come to another interview or hearing after you attended your interview
We also consider your citizenship application non-routine if you:

failed a test
didn’t meet the language requirements during your interview
For more information
How are IRCC processing times calculated?
Can I get my citizenship application processed urgently?
Yes, we can process applications for citizenship services urgently in some situations.

The application process depends on the service you are applying for.

Apply for Canadian citizenship (grant of citizenship) urgently
Apply for proof of citizenship urgently
Apply for a search of the citizenship records urgently
Apply to give up (renounce) Canadian citizenship urgently
We will review your application to see if it qualifies. Even if you qualify, we can’t guarantee your application will be processed urgently or that you will get your permanent resident (PR) card on time.

My citizenship application is being processed. How will the 2017 legislation changes affect my application?
If we received your completed application before October 11, 2017, then only some of the changes will apply to you.

Language and knowledge requirements
If you were a minor (an applicant between 14 and 17 years of age at the time you applied) you won’t need to meet language requirements or take a knowledge test.

If you were between 18 and 54 years old when you applied, you will still need to meet the language requirement and pass a knowledge test.

If you were between 55 and 64 years old when you applied, you won’t need to meet language requirements or take a knowledge test.

If you have received a notice to appear for a knowledge test or language assessment, IRCC will be contacting you about the next steps in your application.

Time spent in Canada
The changes to the amount of time you must be physically present in Canada do not apply to you. You must meet the physical presence requirements that were in place at the time you submitted your application.

I hired a representative before June 11, 2015 and my citizenship application is still in process. Can they continue to act as my representative?
Yes. As long as your citizenship application was received and deemed complete before June 11, 2015, any person who is advising or representing you can continue throughout the duration of that specific application (or until four years has passed).

Who can represent me on my citizenship application?
If your citizenship application is received after June 10, 2015, any paid representatives you may have hired must be authorized to do so. This would include members of the Immigration Consultants of Canada Regulatory Council, lawyers or notaries including paralegals and students at law.

How much does it cost to apply for Canadian citizenship?
View our application fees list for adults and children under 18.

I am a citizen of another country. Will I lose that citizenship if I become a Canadian?
Under Canadian law, you can be both a Canadian citizen and a citizen of another country.

However, some countries won’t let you keep their citizenship if you become a Canadian citizen.

The consulate or embassy of your other country of citizenship can tell you whether this applies to you.

What are the requirements for the photos I need to include with my citizenship application?
You must provide two citizenship photos taken within the last 6 months. Take the Citizenship Photograph Specifications form, included in the application kit, to the photographer to make sure that your photos are the right size.

Can I leave Canada after I mail my citizenship application?
Yes. You can leave Canada after we receive your application.

If you need to leave Canada and want to stay eligible for Canadian citizenship, you must:

make sure that you live in Canada long enough to keep your Permanent Resident (PR) status
be a permanent resident (when you apply)
not lose PR status before you take the Oath of Citizenship
bring your PR card with you when you leave Canada so you can return easily
Make sure your PR card won’t expire while you are outside Canada.

We usually only mail letters, notices and other documents to addresses in Canada. In some cases, you may receive an email from us. You must reply to these letters or emails within a specified amount of time. If you don’t reply within the time frame and don’t provide an acceptable reason for not being able to keep your appointment with us or providing requested information, we may stop processing your application.

You must attend appointments and other events at our offices, like your:

citizenship test (for applicants 18 to 54 years of age)
interview or hearing
ceremony
These events only take place in Canada. If you can’t attend the appointment or event, you must either e-mail or write to the local office that sent you the event notice. You can also use the online web form to contact us.

What if I cannot attend my appointment with IRCC? Can I reschedule it?
Yes. If you are not available on the date and time of your appointment, write us a letter of explanation. Send this letter to the IRCC office that scheduled your original appointment. You can send this letter by mail, or online, using this Web form. We will reschedule your appointment on a different date.

If you do not attend your appointment, you must contact us within a certain amount of time. The notice we sent you inviting you to the appointment will tell you when you must contact us. Use this Web form and tell us why you missed your appointment. If you do not contact us in time, we will close your application. You will have to apply again and pay the required fees.

Where can I find out the status of my citizenship application and the processing time?
To check the status of your application, you can:

Step 1: Check the processing times.
Step 2: Check the status of your application online through the Client Application Status service.
Step 3: If normal processing time for your application has passed, you may contact the Call Centre to verify the status of your application.
Find out more about improvements to our processing times and reducing the backlog.

What does my status mean when I check my citizenship application status?
When you check your application status for your citizenship grant application, you’ll see one of these status updates:

Received

“Received” means your application is ready to be processed and you:

answered all the questions on the form
sent all the required documents
paid the fees
It may be several weeks between when we get your application and it’s ready to be processed.

In process

“In process” means we started processing your application.

While your application is in process, we’ll invite you to the citizenship test, if you need to take it, interview, and hearing if you need one.

If we need more information from you before we make a decision, we’ll contact you.

Decision made

“Decision made” means we either approved or refused your application. A citizenship official makes a decision on your application after the test, if you had to take it, interview, and hearing, if you had one.

If we approved your application, you passed the citizenship test, if you had to take it, and meet all the requirements for citizenship. We’ll send you an invitation to take the Oath of Citizenship at a citizenship ceremony. You must continue to meet all of the requirements for citizenship until you take the Oath at the ceremony. We can change the decision if your situation changes and you no longer meet the requirements.

If we refused your application, you don’t meet the requirements for citizenship. We’ll send you a letter by registered mail explaining why.

How do I withdraw my application for citizenship services?
First, find out if you can get a refund. If you still wish to withdraw your application, send a request by mail.

Write “Withdrawal of Application” on the envelope. Send us:

Form CIT 0027E Withdrawal of Citizenship Application (PDF, 600 KB); and
A copy of the electronic payment receipt or a copy of both sides of the payment receipt (Form IMM5401).
We recommend that you keep a copy of the withdrawal form for your records.

Where to mail the application

If you sent your application to a Canadian embassy, high commission or consulate, mail your withdrawal request there.

If you sent your application to CPC-Sydney and your application has not yet been transferred to a local IRCC office, mail your withdrawal request to:

General Mailing Address
CPC-Sydney
P.O. Box 12000
Sydney, Nova Scotia
B1P 7C2
Courier Address
CPC-Sydney
49 Dorchester Street
Sydney, Nova Scotia
B1P 5Z2
If your application has been transferred to a local IRCC office, mail your withdrawal request to that office. You will find contact information for the office processing your application on the letter we sent you.

If you do not know if your application has been transferred or which office is processing your application, contact us through this Web form.

What can I do if my citizenship application is refused?
You can apply for Canadian citizenship again. This new application must include all the required forms and documents, including a new application fee. There is no waiting period before you can reapply. However, you should make sure you meet the requirements for Canadian citizenship before you reapply.

If your citizenship application is refused, you may also seek judicial review of the decision by the Federal Court of Canada. This is not an appeal of the decision. You have thirty (30) days from the date on the refusal letter to apply.

Do I need to ask the Canada Border Services Agency for a history of entries when applying for citizenship?
No. Provide consent by checking the “Yes” box for question 14B “Have you held travel documents and or passports during your eligibility period” on your citizenship application. This will give us permission to get your history of entries from the Canada Border Services Agency (CBSA). It will also take less time than you asking the CBSA for your history.

We use your history of entries to make sure that you have been in Canada long enough to qualify for citizenship.

If you do not provide consent by checking the “Yes” box, you may be asked to send a request for personal information to the CBSA to get your history of entries. Doing this may make the time to process your application longer than the routine processing times for citizenship.

What happens if I check “Yes” on Question 14B (“Consent to the CBSA and IRCC”) on the application for citizenship?
When you check “Yes”, you are giving us permission to get your history of entries from the Canada Border Services Agency (CBSA). We need this information to process your citizenship application.

You must check this box because one government department cannot share your personal information with another department without your permission. If you do not check the “Yes” box, you may be asked to request your history from the CBSA and then send it to us. This process takes longer and may make your application take longer than the routine processing times for citizenship.

What happens if I submitted my citizenship application with an old version of the form?
It depends on how old the form is.

We currently accept versions of the application form dated October 2017 or later. You can find the version date on the bottom left corner of the form. For example, “CIT 0002 (01-2019)” means the version date is January 2019. The current version is always available as part of your application package.

If you submitted your application on a form with a version date before October 2017, we’ll return it to you and ask you to resubmit your application using the newest version of the form.

If you used a form dated October 2017 or later and we returned it to you as incomplete, you don’t need use the newest form to resubmit your application. You can resubmit it using the same form once you get the missing information or documents.

Who has to take the citizenship test?
Everyone between the ages of 18 and 54 at the time they apply for citizenship must take the citizenship test. We use the test to determine if you have adequate knowledge of Canada and the responsibilities and privileges of citizenship.

If you are 55 or older when you apply, you do not have to take the test. If you turn 55 during the processing of your application, you still have to take the test since you were under 55 when you signed your application.

Is the citizenship test difficult?
The citizenship test covers the range of topics and subjects found in the citizenship study guide entitled Discover Canada: The Rights and Responsibilities of Citizenship. You should study this guide to prepare for the test. On the test, you can expect to see questions that ask about:

facts and ideas presented in Discover Canada;
your understanding of Canada’s history, symbols, institutions and values; and
the rights, responsibilities and privileges of citizenship.
Does the study guide have sample questions to help me prepare for the citizenship test?
Yes, you can find study questions for the citizenship test in Discover Canada.

After I apply for citizenship, how long will it be before I write the citizenship test?
The time between submitting your application and writing the citizenship test can be different for everyone. It depends on your case and on our processing times.

We will mail you a notice letting you know the time and location of your test. This is your official confirmation that you will be taking the citizenship test.

Check the Client Application Status service to see when we mailed your notices.

If you move to a new address, you must tell us. Update your address online.

If you need urgent processing, check to see if you qualify.

Can I reschedule my citizenship test if I cannot attend it?
Yes. If you are not available on the date and time of your citizenship test, the notice inviting you to the test will tell you how to contact us to reschedule it.

Learn more about what to do if you miss your citizenship test.

Can I bring my child to the citizenship test?
No, only the person scheduled for the test can be in the testing room. However, children can wait in the area outside the testing room if they are with a caregiver at all times.

You can’t leave your child alone in the waiting area to wait for you. If you have a child, plan to have someone care for them while you take your test. If you can’t arrange child care, let us know and we’ll reschedule your test date.

What should I do if I missed my citizenship test?
The steps you should take if you did not attend your citizenship test depend on if we sent you:

a first notice to write the test,
a final notice to write the test, or
a notice to re-write the test.
I was sent my first notice to write the test
If this was the first time you were asked to write the test, you can:

contact us to let us know you missed the test, or
wait to be automatically rescheduled for another date.
Contact us
You have 30 days from the test date to contact us and let us know why you missed the test. Write us a letter explaining why you missed the test. Send this letter to the IRCC office that scheduled your original appointment. You can send this letter by mail or online, using this Web form.

The local office handling your application will decide if you have a valid reason for missing the test.

If your reason is valid, we will send you another notice with a new test date. (We will consider this new notice as another first notice in case you miss this new date, but have a valid reason for not attending.)

If your reason is not valid, we will treat you the same as someone who missed the test and did not contact us. (See “Be rescheduled automatically” below.)

Be rescheduled automatically
We will automatically reschedule you for a new date to write the test if you did not attend the test and you:

did not contact us to let us know, or
did not have a valid reason for missing the test.
We will send you a new notice telling you the new test date. This will be your final notice to write the exam.

This new test date will usually be two weeks or more after the date of the test you missed.

I received a final notice to write the test, but I missed it
You must contact us within 30 days of the test date if you:

missed your first test,
received a final notice to write the test, and
missed that test, too.
The notice inviting you to the new test date will tell you how to contact us.

The local office handling your application will decide if you have a valid reason for missing the test.

If your reason is valid, we will send you another final notice with a new test date.

We may close your application for citizenship if:

you do not contact us within 30 days, or
you do not have a valid reason for missing the test.
You will have to apply for citizenship again and pay the required fees.

You failed the test and were scheduled for a second test
You must contact us within 30 days of the test date if you:

failed the citizenship test the first time you took it,
were scheduled to re-write the test, and
missed that date.
The notice inviting you to the re-write the test will tell you how to contact us.

The local office handling your application will decide if you have a valid reason for missing the test.

If your reason is valid, we will send you a new notice to re-write the test.

We may close your application for citizenship if:

you do not contact us within 30 days, or
you do not have a valid reason for missing the test.
You will have to apply for citizenship again and pay the required fees.

When do I know if I passed the citizenship test?
We will give you the results of your test right after you take it.

If you pass and meet the others requirements for citizenship, we may give you a citizenship ceremony date at the same time we give you the results. If we do not, we will mail you a letter with the date and time of your ceremony. You will receive this letter two to four weeks before the ceremony. The ceremony will normally take place within six months after you pass the test.

If you do not pass the exam the first time, you can write it again. If you pass the second time, we will either give you the date or mail you a letter, just like we would have if you have passed the first exam.

If you are asked to attend a hearing with a citizenship officer or a citizenship judge, we will send you a letter after the hearing. This letter will tell you if the officer or the judge has decided to grant you citizenship and, if so, the date of your ceremony.

What happens if I fail the written citizenship test?
If you do not pass the written test, but you meet the other criteria for citizenship, we will schedule you for a second test. This second test will usually take place 4-8 weeks after your first test, but the delay may be longer. If you are not available to take the test on that date, you must let us know.

If you do not pass the second test, we will send you a notice telling you to appear for a hearing with a citizenship officer. During this hearing, the citizenship officer may assess whether you meet all the requirements for citizenship. During an oral interview, the citizenship officer may:

test your knowledge of Canada and the responsibilities and privileges of citizenship;
ask questions about your residency in Canada; and/or
assess if you have adequate knowledge of English or French.
If you are asked to attend an interview, but applied for citizenship with your family by sending your applications in the same envelope, your application will be processed separately from your family's unless you want them to be processed together.

What if I cannot attend my hearing with a citizenship officer or a citizenship judge? Can I reschedule it?
Yes. If you are not available on the date and time to meet with a citizenship officer or a citizenship judge as part of your application for citizenship, you must inform the office where you have been scheduled to appear. You will also be required to provide the reason why you are unable to attend.

The notice asking you to appear will contain the details of:

How to notify the office.
What will happen if you do not attend the meeting.
Your notice will come either by e-mail (to the address provided by you on your application form) or by paper notice in the regular mail.

What happens after the hearing with a citizenship officer to test my knowledge of Canada?
The hearing will last 30 to 90 minutes. At the hearing, the citizenship officer will ask you questions orally to see if you meet the conditions of citizenship, including knowledge of Canada. After your hearing, we will send you a letter with the results.

If you passed the interview, the letter will tell you the date of your citizenship ceremony.

Not passing the interview will cause your application for citizenship to be refused.

How long will I wait between my citizenship test and the ceremony?
In most cases, the ceremony takes place within three months after you pass the test. We'll give you the results of your test right after you take it.

If your application is non-routine, we may ask you to go to a hearing with a citizenship officer or judge, even after you pass the test. We'll send you a letter after the hearing to let you know:

what the officer or judge decided
the date of your ceremony (if your application was approved)
Can I bring my child to the citizenship ceremony?
Yes, your child is welcome to come to the ceremony, even if they aren’t becoming a citizen.

Children age 14 and over must go to the citizenship ceremony and take the oath if they’re becoming citizens. Parents will get certificates of citizenship for their children under age 14.

You need to stay in the room for the entire ceremony. If you’re bringing a young child, also bring a guest with you who can take care of your child in case they get restless and need to leave the ceremony room. If you can’t arrange child care, let us know and we’ll reschedule your ceremony date.

What does “adequate knowledge” of English or French mean when applying for citizenship?
The Citizenship Act requires that citizenship applicants have “an adequate knowledge of one of the official languages of Canada.” Canada’s two official languages are English and French.

We define “adequate knowledge” as having a Level 4 speaking and listening ability. To measure your ability, we use the Canadian Language Benchmarks (CLB) or Niveaux de compétence linguistique canadien (NCLC). This level means you can, in English or French:

understand simple:
questions
directions
instructions
use basic grammar, including:
tenses
simple structures
show that you know enough common words and phrases to:
express yourself
answer questions
take part in short, everyday conversations about common topics
For more information
How we measure your language ability
How do you measure how well I can speak English or French when applying for citizenship?
To measure if you have adequate knowledge of English or French we use:

Canadian Language Benchmarks (CLB)
Niveaux de compétence linguistique canadien (NCLC)
You must reach CLB/NCLC Level 4 or higher to get Canadian citizenship.

CLB/NCLC is the official standard used in Canada to describe, measure and recognize how well adult immigrants can communicate in their second language. We use this standard to make sure we evaluate everyone the same way.

The ways we measure how well you can speak and listen in English or French include:

reviewing the documents you send in with your application to prove you can speak and listen in English or French at Level 4 (if you’re 18 to 54 years of age)
noting how well you communicate when you talk to staff or a citizenship officer during your interview
Using the CLB/NCLC, a citizenship officer will make the final decision if you have adequate knowledge of English or French.

What language level do I need when I apply for citizenship?
If you are between the ages of 18 and 54 on the date you sign your application, you must meet the Canadian Language Benchmarks Level 4 (CLB 4) or higher in speaking and listening.

This means to become a Canadian citizen you must show that you have an adequate knowledge of English or French by providing, with your citizenship application, proof that you can speak and listen in English or French at CLB/NCLC 4 level or higher.

Learn how we measure your ability to speak and listen in English or French using CLB/NCLC.

What documents can I use to prove that I meet the citizenship language requirement?
You can send us one of a number of different documents to show that you meet the language requirement, including:

the results of an IRCC-approved third-party test
proof from certain government-funded language training programs
proof of completion of secondary or post-secondary education in English or French, in Canada or abroad
For information on other forms of proof accepted, see:

acceptable language proof tool (wizard)
complete list of acceptable documents
You need to reach level 4 or higher to apply for citizenship. We use your documents to determine if you have reached this level for speaking and listening in English or French.

We will review the language proof you send us. We won’t process your application and will return it to you if your proof:

can’t be read
can’t be verified
isn’t included with the application
is in a language other than English or French (without a certified translation)
What third-party language tests will you accept as proof I have adequate knowledge of English or French when I apply for citizenship?
A third-party test is a test done by an organization that isn’t Immigration, Refugees and Citizenship Canada (IRCC).

We accept third-party test results as proof of your language ability from organizations including:

Canadian English Language Proficiency Index Program:
CELPIP General
CELPIP General-LS: a 2 skills (listening and speaking) version
International English Language Testing System General training (IELTS - General)
Test d'Évaluation de Français (TEF) (in French)
Test d'Évaluation de Français (TEFAQ) (in French)
TEF pour la naturalisation: a 2 skills (listening and speaking) version
We will accept tests that you previously submitted for immigration purposes to Quebec, including:

Diplôme approfondi de langue française (DALF) (in French)
Diplôme d'études en langue française (DELF) (in French)
Test de connaissance du français (TCF)
Test de connaissance du français pour le Québec (TCFQ)
We don’t accept any other third-party test results, even if they’re similar.

Visit each organization’s website to learn how to write the exams. Since we don’t run them, we don’t track when and where they’re offered.

In some cases, you may send test results that you already sent to us or the Ministère de l’Immigration, de la Diversité et de l’Inclusion (MIDI). We’ll accept the test results that you sent with your application for:

Federal Skilled Worker
Canadian Experience Class
Quebec-selected Skilled Worker
See the complete list of acceptable documents.

I graduated from an English-or French-language high school/college/university. What can I use to show that I can communicate in one of the official languages when I apply for citizenship?
You may send a transcript, diploma or certificate showing that you graduated from a secondary school or from a post-secondary program in Canada or abroad. These materials must show that the program was in English or French. A single course in an official language is not enough to meet this requirement.

See the complete list of acceptable documents.

Can the government-funded language program I took be used as proof I meet the citizenship language requirement?
Yes. You may submit a certificate from a federally-funded Language Instruction for Newcomers Course (LINC) or Cours de langue pour les immigrants au Canada (CLIC) program with your citizenship application if you have reached CLB/NCLC 4 in speaking and listening. If you took LINC/CLIC classes between January 1, 2008 and October 31, 2012, you can indicate on the citizenship application form that you have attended a Language Instruction for Newcomers Course and reached the Canadian Language Benchmark (CLB)/Niveau de compétence linguistique canadien (NCLC) level 4 or higher in speaking and listening.

We will also accept results from some provincially-funded language training programs. If you attended language training delivered by British Columbia, Saskatchewan, Manitoba, Ontario, Quebec’s Ministère de l’Immigration, de la Diversité et de l’Inclusion (in French only) or Quebec’s Ministère de l’Éducation, de l’Enseignement supérieur et de la Recherche (in French only), you can provide a certificate or report card that shows that you have completed language training at a Canadian Language Benchmark (CLB)/Niveau de compétence linguistique canadien (NCLC) level 4 or higher or equivalent.

See the complete list of acceptable documents.

Can I provide my LINC/CLIC placement test as a proof that I meet the citizenship language requirement?
No. You must provide evidence that you have reached CLB/NCLC 4 or higher in speaking and listening as part of a LINC/CLIC course to meet the language ability requirement for your citizenship. A placement test done by a LINC/CLIC assessment center is not accepted as evidence.

I’ve lost my certificate or transcript showing I meet the citizenship language requirement. What can I do?
If you have lost your certificate, most third-party testing bodies and provincially-funded language training programs will send you a copy of your certificate. Contact the organization where you completed the language training or testing.

Can I submit the results from a third-party language test that I took when I first applied to immigrate to Canada as proof I meet the citizenship language requirement?
Yes. You may send the same third-party language test results from your immigration application with your application for citizenship. There is no expiration date for third-party language test results for citizenship applicants.

Do you accept certificates from private language schools as proof I meet the citizenship language requirement?
No. If you have taken private language classes, those classes are not enough to prove that you speak French or English well enough to apply for Canadian citizenship. You must take an IRCC-approved third-party language test. If you achieve CLB/NCLC 4 or above on this test, submit the results with your citizenship application.

I’ve lost my citizenship card/certificate. How do I replace it?
To replace your citizenship certificate, follow the steps to apply for proof of citizenship. You must use this process if your certificate was lost, stolen, damaged or destroyed.

If your card/certificate was lost or stolen, you should report it to your local police department. You do not need to tell us it was lost or stolen.

We stopped issuing the plastic wallet sized citizenship cards with the commemorative certificates in February 2012. If you lost your card or need to make a change to it, you must apply for a citizenship certificate. We will not send you a new card.

The commemorative certificates that were given out with the plastic citizenship cards cannot be used as proof of citizenship. We will not replace a commemorative certificate.

If you are not sure if you have a commemorative certificate or not, see the examples of citizenship certificates. If your certificate does not look like these examples, you have a commemorative certificate.

What documents should I send with my application for a citizenship certificate (also known as proof of citizenship)?
When you apply for a citizenship certificate, you must include supporting documents. See Documents You Must Send With Your Application for the complete list.

If you are applying for a citizenship certificate for the first time, you must send original documents or certified photocopies. If you are applying for a replacement certificate, you can send photocopies of your documents.

If you are a Canadian citizen because you were born outside Canada to a Canadian parent, you will have to provide:

A birth certificate that was issued by the government in the country where you were born and that lists your parents’ names;
Evidence that one parent was a Canadian citizen at the time of your birth.
If you were born in Canada, the birth certificate issued by the province or territory where you were born is your proof of Canadian citizenship.

Birth certificates issued by the Government of Quebec before January 1, 1994, are no longer accepted when you apply for a citizenship certificate. For more information, contact the Directeur de l’état civil du Québec.

Can I replace my citizenship certificate if there is a spelling or other mistake on it?
Yes. We will replace your citizenship certificate if:

we made a mistake in processing it, and
it has been 90 days or less since you received your citizenship certificate
You must resubmit an application for a citizenship certificate and pay the processing fee if it has been more than 90 days since:

you received your certificate at a citizenship ceremony,
your certificate was mailed to you, or
you picked it up from a Canadian embassy, high commission or consulate
You must also follow this process to replace your citizenship certificate for another reason.

We have stopped issuing citizenship cards
As of February 1, 2012, the citizenship certificate replaced the plastic wallet sized citizenship card as proof of citizenship. We no longer give out citizenship cards or the commemorative certificates that came with them. If you apply to update or replace your citizenship card, we will send you a citizenship certificate.

How to request a replacement if there is a mistake on your certificate
If it has been 90 days or less since you received your citizenship certificate, send us:

the citizenship certificate with the mistake,
a note explaining what needs to be fixed, and
if your request is urgent:
write “Urgent” in large, dark letters on the envelope,
include an explanation of why your request is urgent, and
include any documents that support your explanation.
We will replace your certificate free of charge.

Where to mail your request
If you live in Canada or the United States, mail your request to:

If you are sending your request by regular mail
Request for replacement certificate
CPC-Sydney
P.O. Box 10000
Sydney, NS
B1P 7C1
If you are sending your request by a courier company
Request for replacement certificate
CPC-Sydney
49 Dorchester Street
Sydney, NS
B1P 5Z2
If you live outside Canada and the United States, send your request to the Canadian embassy, high commission or consulate responsible for your region.

If your request is not approved
If your request for a replacement certificate is not approved (e.g., if it was determined that a processing error was not made), we will return your documents to you. We will also explain why we did not approve your request.

How do I get a citizenship certificate (proof of citizenship) for someone under 18 years old?
To prove a minor (under 18 years old) is a Canadian citizen, apply to get a citizenship certificate (adults and minors). Do not use the application form for Canadian citizenship (minors).

You must be their parent or legal guardian to apply for them. When answering the questions, fill in the form with the minor's information.

I legally changed my name. How do I change the name on my citizenship certificate/card?
To change the name on your citizenship certificate:

follow the same steps to apply for a citizenship certificate
send us documents showing you legally changed your name
If you need to change your name on a plastic citizenship card, you must also apply for a citizenship certificate. We stopped issuing citizenship cards in February 2012. If your application is approved, you will receive an updated citizenship certificate instead.

How do I fill out my application for a citizenship certificate if I don’t know everything about my parents or grandparents?
If you don’t know the information we ask for on the form, enter ‘unknown’ in the spaces provided. If it doesn’t apply to your parents or grandparents, enter ‘not applicable’ or ‘NA’.

We collect information about your parents and your grandparents, because it helps us:

determine what section of the Citizenship Act describes your claim to citizenship
search for citizenship records
If we don’t have enough information about your parents or grandparents, your application may be delayed and/or we may not be able to assess your claim.

What is a hearing conducted by videoconference?
A hearing conducted by videoconference is the same as an in-person hearing except you speak to an IRCC official or Citizenship judge through one of our computers in an IRCC office. An IRCC official will be with you to make sure you can see and hear the interviewer properly. We use videoconferences so you have your hearing as quickly as possible.

Prepare for a videoconference hearing the same way that you would any other hearing. Review your Notice to Appear to make sure you bring everything you need. You do not need to bring any computer equipment of your own.

I sent a citizenship application for a minor under subsection 5(1) and paid $530. Will I get a refund?
On February 14, 2018, the fee for minors applying under subsection 5(1) was reduced from $530 to $100.

Yes. If a citizenship application for a minor under subsection 5(1) was made on or after June 19, 2017, the person who paid the $530 fee will get a refund of $430.

How will you refund the fee for my citizenship application for a minor under subsection 5(1)?
On February 14, 2018, the fee for minors applying under subsection 5(1) was reduced from $530 to $100.

The refund is automatic. You don’t need to apply for it. We’ll contact you directly if you submitted your application and paid the original fee. The person who paid the fee will get the refund.

If you paid the fee with a credit card, we’ll refund the $430 to the card used to pay the fee. If the card is expired or no longer valid, we’ll send you a cheque.

If you paid the fee with an online debit card, we’ll send you a cheque.

We’re committed to making the refunds within 12 weeks of February 14, 2018. If you don’t receive your refund by then, contact us.

I paid the $530 fee for a citizenship application for a minor under subsection 5(1), but didn’t send in my application. What do I do?
On February 14, 2018, the fee for minors applying under subsection 5(1) was reduced from $530 to $100.

If you paid the $530, but haven’t submitted your application yet, then you may request a refund for the fee. To request a refund, follow the instructions for those who paid online and applied on paper.

When you submit your application, you’ll need to pay the $100 fee. See pay your fees.

Date modified: 2019-10-29
About government
Contact us
Departments and agencies
Public service and military
News
Treaties, laws and regulations
Government-wide reporting
Prime Minister
How government works
Open government
About this site
Social mediaMobile applicationsAbout Canada.caTerms and conditionsPrivacy `

@devildani
Copy link

devildani commented Jan 29, 2020

Hi, I just wanted to ask what is the response function at line 137 after colored(response(u_input)), as I was not able to figure that part out. Would you mind explaining that thing to me?

@devildani
Copy link

Hi, I just wanted to ask what is the response function at line 137 after colored(response(u_input)), as I was not able to figure that part out. Would you mind explaining that thing to me?

Never I got it. You need to update your code the response function on line 137 should be change to match function.

@rishisidhu
Copy link
Author

Hi, I just wanted to ask what is the response function at line 137 after colored(response(u_input)), as I was not able to figure that part out. Would you mind explaining that thing to me?

Never I got it. You need to update your code the response function on line 137 should be change to match function.

Thanks @devildani. Corrected it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment