import nltk
nltk.download('punkt')
import numpy as np
from nltk.stem.porter import PorterStemmer 

stemmer = PorterStemmer()

def Tokenize(sentence):
    return nltk.word_tokenize(sentence)

def Stemmer(word):
    return stemmer.stem(word.lower())

def bag_of_words(tokenize_sentence,all_words):
    tokenize_sentence = [Stemmer(w) for w in tokenize_sentence]
    bag = np.zeros(len(all_words),dtype = np.float32)
    for idx,w in enumerate(all_words):
        if w in tokenize_sentence:
            bag[idx] = 1.0       
    return bag            
    
    
    

