I don't have that much experience programming in python, so my question might be very simple. I am working on a project for school, where we need to create an output from a user input (we want to emulate Eliza, but in a very simple way). Right now, the only thing the program does is look for keywords and respond accordingly. However, since I go to a french school and everything is in french, I need to use accents (e.g. é, è, à, á). And this is where the problem arrives: I cannot use accents in my predefined list of keywords (so it's not the keywords from the user input, but in my own program :/ )
Here you have the entire program:
#Greeting from bot
print("Salut!")
(Here are the predefined keyword we use to know if there is a negation and if there are any demeaning adjectives in the user's sentence - we'll need to make it a lot bigger in order to make our bot more humanlike but it's just the principle)
negation = ("ne", "n'", "pas", "guere", "ne", "plus", "jamais")
AnD = ("artificiel", "cree", "mecanique", "invente", "concu", "construit", "programme", "innove", "fabrique")
But here is the problem: in order to run our program, we had to remove all the accents. So words like guère, créé, mécanique, inventé, programmé become guere, cree, mecanique, invente, programme, and in some cases it changes the meaning of the word (e.g. programme becomes a noun instead of an adjective)
adj_neg_decl = None
nega = None
#FONCTION: phrase declarative, pas de negations, adjectif pejoratif
def decl_non_neg_adj_neg(statement):
if (statement.endswith('.')) and (nega == False) and (adj_neg_decl == True):
print(AnD_ici + '? Mais moi je suis humain. Ca se voit pas?')
else:
#Only for testing
print('tralalalala')
while True:
statement = raw_input("> ").lower()
if statement == "au revoir":
print("Au revoir!")
break
(Here we simply look for negations, and adjectives - if you have another (more efficient) way of doing it, I would love to hear your suggestions! I might as well learn some new stuff :) )
for i in negation:
if i in statement:
nega = True
break
else:
nega = False
for i in AnD:
if i in statement:
adj_neg_decl = True
AnD_ici = i
break
else:
adj_nej_decl = False
decl_non_neg_adj_neg(statement)
#Reset variables
for var in (adj_neg_decl, nega):
var = None
I had thought of maybe using unicode or utf-8, but I don't really know how to use it... Is that the right way to go? Or is there something else I can do?
Thank you so much for your help :)