0

我正在创建一个谈论国际象棋的机器人,现在我正在预处理。问题是,当 Python 程序对字符串中的单词进行词干处理时,除非该单词是最终单词,否则它不会做任何事情。那就是输出。我所期望的是词干分析器能够阻止用户输入的句子中的每个单词。我做错了什么?这是代码:

import re
from nltk.stem import PorterStemmer
port = PorterStemmer()

print("Hello! I am the ChessBot. I will talk about chess, but can only talk     about chess. Nothing else. I can't even understand a greeting! Now, initiate this conversation!")

while True:
    userinput = input('> ')
    userinput = re.sub('(\?|\.|!|,)', '', userinput)
    userinput = str.lower(userinput)
    userinput = userinput.split('\s')
    userinput = " ".join([port.stem(word) for word in userinput])
    print(userinput)
4

0 回答 0