Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import json
import nltk
from nltk.stem import WordNetLemmatizer
from nltk.tokenize import word_tokenize # importing some libraries so i can tokenize and lemmatize the inputs from the user to make the bot "more human" as well ass json to be able to access the json file
from nltk import wordnet
intents = json.loads(open("intents.json").read()) # accesseing the json file and stored it in a vatiable called intents
wnl = WordNetLemmatizer()
q1 = "what are your hobbies and intrests " #here are a few questions the bot asks the user in order to try to predict
print(q1) #what type of news theyre intrested in
in_1 = input()
q2 = "do you study or work?\nif yes what do you do? "
print(q2)
in_2 = input()
q3 = "do you play video games if yes what type of games?"
print(q3)
in_3 = input()
in_11 = word_tokenize(in_1) #tokinizing the inputs
in_22 = word_tokenize(in_2)
in_33 = word_tokenize(in_3)
in_11 = [wnl.lemmatize(word) for word in in_11]
in_22 = [wnl.lemmatize(word) for word in in_22] #looping over the user input to lemmatize it
in_33 = [wnl.lemmatize(word) for word in in_33]
kw1 = intents["intents"][0]["key_words"]
kw2 = intents["intents"][1]["key_words"]
kw3 = intents["intents"][2]["key_words"] #accesing the keywords for each type of news
kw4 = intents["intents"][3]["key_words"]
kw5 = intents["intents"][4]["key_words"]
kw1 = [wnl.lemmatize(word) for word in kw1]
kw2 = [wnl.lemmatize(word) for word in kw2] #looping over the keywords for each type of news to lemmatize them
kw3 = [wnl.lemmatize(word) for word in kw3]
kw4 = [wnl.lemmatize(word) for word in kw4]
kw5 = [wnl.lemmatize(word) for word in kw5]
sportscomparing_1=list(set(in_11).intersection(set(kw1)))
sportscomparing_2 = list(set(in_22).intersection(set(kw1)))
sportscomparing_3 = list(set(in_33).intersection(set(kw1)))
factscomparing_1 = list(set(in_11).intersection(set(kw2)))
factscomparing_2 = list(set(in_22).intersection(set(kw2)))
factscomparing_3 = list(set(in_33).intersection(set(kw2))) #comparing the similarities between the users responses and the key words and putting them in a list
hotnewscomparing_1 = list(set(in_11).intersection(set(kw3)))
hotnewscomparing_2 = list(set(in_22).intersection(set(kw3)))
hotnewscomparing_3 = list(set(in_33).intersection(set(kw3)))
whcomparing_1 = list(set(in_11).intersection(set(kw4)))
whcomparing_2 = list(set(in_22).intersection(set(kw4)))
whcomparing_3 = list(set(in_33).intersection(set(kw4)))
techcomparing_1 = list(set(in_11).intersection(set(kw5)))
techcomparing_2 = list(set(in_22).intersection(set(kw5)))
techcomparing_3 = list(set(in_33).intersection(set(kw5)))
spclen = len(sportscomparing_1)+len(sportscomparing_2)+len(sportscomparing_3)
factlen = len(factscomparing_1)+len(factscomparing_2)+len(factscomparing_3)
HNlen = len(hotnewscomparing_1) + len(hotnewscomparing_2) + len(hotnewscomparing_3) #creating variables to save the amont of similar words between the user response and the actual keyword
whlen = len(whcomparing_1) + len(whcomparing_2) + len(whcomparing_3)
techlen = len(techcomparing_1) + len(techcomparing_2) + len(techcomparing_3)
most_prbable=max(spclen, factlen, HNlen, whlen, techlen) # accesing the highest variable of similarity from the 5 news so it could be suggested to the user
def questions()# function to choose the type of news after highest variable of similarity was choosen and returns the appropriate news
if most_prbable == spclen:
print("eggy thinks you'd be interested in sports news")
import mybot
elif most_prbable == factlen:
print("eggy thinks you'd be interested in facts!")
import facts
elif most_prbable == HNlen:
print("eggy thinks you'd be interested in Hotnews!")
import HotNews
elif most_prbable == whlen:
print("eggy thinks you'd be interested in whether conditions ")
import whether
elif most_prbable == techlen:
print("eggy thinks you'd be interested in tech news")
import techNews
else:
return "seems like your unpredictable maybe choose news on your own!"
print(questions())