mirror of
https://github.com/kaiyuran/Emoji-translator-Server.git
synced 2024-11-24 01:53:39 +00:00
fix punctuation handling
This commit is contained in:
parent
d9edc071c6
commit
c9c29ffeec
1 changed files with 43 additions and 6 deletions
49
app.py
49
app.py
|
@ -5,6 +5,12 @@ import random
|
||||||
def emojify(message):
|
def emojify(message):
|
||||||
|
|
||||||
choiceWordDict = {
|
choiceWordDict = {
|
||||||
|
"hello": "👋",
|
||||||
|
"hi": "👋",
|
||||||
|
"hey": "👋",
|
||||||
|
"greetings": "👋",
|
||||||
|
"goodbye": "👋",
|
||||||
|
|
||||||
#happy face
|
#happy face
|
||||||
"happy": "😊",
|
"happy": "😊",
|
||||||
"joy": "😊",
|
"joy": "😊",
|
||||||
|
@ -253,8 +259,36 @@ def emojify(message):
|
||||||
"sunflower": "🌻",
|
"sunflower": "🌻",
|
||||||
"daisy": "🌼",
|
"daisy": "🌼",
|
||||||
"hibiscus": "🌺",
|
"hibiscus": "🌺",
|
||||||
|
"work": "🏢",
|
||||||
|
"office": "🏢",
|
||||||
|
"building": "🏢",
|
||||||
|
"construction": "🏗️",
|
||||||
|
"site": "🏗️",
|
||||||
|
"school": "🏫",
|
||||||
|
"university": "🏫",
|
||||||
|
"college": "🏫",
|
||||||
|
"hospital": "🏥",
|
||||||
|
"clinic": "🏥",
|
||||||
|
"doctor": "👩⚕️",
|
||||||
|
"nurse": "👩⚕️",
|
||||||
|
"therapist": "👩⚕️",
|
||||||
|
"healthcare": "👩⚕️",
|
||||||
|
"police": "👮",
|
||||||
|
"cop": "👮",
|
||||||
|
"law": "👮",
|
||||||
|
"enforcement": "👮",
|
||||||
|
"officer": "👮",
|
||||||
|
"movie": "🎥",
|
||||||
|
"film": "🎥",
|
||||||
|
"camera": "🎥",
|
||||||
|
"movies": "🎥",
|
||||||
|
"cinema": "🎥",
|
||||||
|
"theater": "🎭",
|
||||||
|
"drama": "🎭",
|
||||||
|
"acting": "🎭",
|
||||||
|
"perform": "🎭",
|
||||||
}
|
}
|
||||||
|
puncList = [".",",","!","?",";"]
|
||||||
message = message.strip('"')
|
message = message.strip('"')
|
||||||
message = message.strip("'")
|
message = message.strip("'")
|
||||||
finalMessage = []
|
finalMessage = []
|
||||||
|
@ -263,9 +297,12 @@ def emojify(message):
|
||||||
for word in message:
|
for word in message:
|
||||||
try:
|
try:
|
||||||
formWord = word.lower()
|
formWord = word.lower()
|
||||||
if formWord[-1] == ".":
|
done = False
|
||||||
finalMessage.append(word[:-1] + (choiceWordDict[formWord[:-1]] * random.randint(1,3)) +".")
|
for punctuation in puncList:
|
||||||
else:
|
if formWord[-1] == punctuation:
|
||||||
|
finalMessage.append(word[:-1] + (choiceWordDict[formWord[:-1]] * random.randint(1,3)) +punctuation)
|
||||||
|
done = True
|
||||||
|
if not done:
|
||||||
finalMessage.append(word + choiceWordDict[word.lower()])
|
finalMessage.append(word + choiceWordDict[word.lower()])
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,5 +340,5 @@ def get_random_emoji():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#app.run(debug=True)
|
#app.run(debug=True)
|
||||||
app.run(port=33303)
|
# app.run(port=33303)
|
||||||
# app.run(host='0.0.0.0', port=33303)
|
app.run(host='0.0.0.0', port=33303)
|
Loading…
Reference in a new issue