[英]How to know whether an username belongs to a group or a user in telegram using python? If yes, get the Group Title
[英]Need help determining whether a user has answered “yes” or “no” using Python
我正在編寫一個微型聊天機器人,但似乎無法找出確定用戶是否回答“是”或“否”的方法。 例如,如果用戶鍵入“確定”,我想知道他們實際上回答了“是”。 或者,如果他們寫的是“不”,我想知道他們實際上回答了“不”。
使用nltk的wordnet並沒有多大幫助。 這是我嘗試過的:
import nltk
from nltk.corpus import wordnet as wn
for syn in wn.synsets('yes'):
print(syn.name(), syn.lemma_names())
我希望能得到像yes.n.01 ['yes', 'okay', 'sure', 'yup', 'yeah']
,但是我得到的只是yes.n.01 ['yes']
。 我正在尋找Python中的解決方案,盡管不一定需要通過nltk軟件包。
因此,我不確定如何使用NLP來執行此操作,但是對於您的目的而言,這可能會顯得有些過頭。 您可以只創建一個包含所有“是”和“否”字詞的字詞集。
no_words = set(['no', 'nope', 'nah'])
yes_words = set('yes', 'yea', 'yeah', 'ok', 'okay', 'sure'])
user_input = input('Please type in your answer')
if user_input in yes_words:
print('user says yes')
elif user_input in no_words:
print('user says no')
我認為可以選擇使用PyDictionary
https://pypi.org/project/PyDictionary/
如果您執行以下操作:
from PyDictionary import PyDictionary
dictionary=PyDictionary()
yes_synonyms = dictionary.synonym("yes")
no_synonyms = dictionary.synonym("no")
user_input = input('yes or no')
if user_input in yes_synonyms:
print("yes")
elif user_input in input('yes or no'):
print("no")
那可能很好
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.