到目前为止,我有下面的代码
from textblob import TextBlob
class BrinBot:
def __init__(self, message): #Accepts the message from the user as the argument
parse(message)
class parse:
def __init__(self, message):
self.message = message
blob = TextBlob(self.message)
print(blob.tags)
BrinBot("Handsome Bob's dog is a beautiful Chihuahua")
这是输出:
[('Handsome', 'NNP'), ('Bob', 'NNP'), ("'s", 'POS'), ('dog', 'NN'), ('is', 'VBZ'), ('a', 'DT'), ('beautiful', 'JJ'), ('Chihuahua', 'NNP')]
我的问题是,显然TextBlob认为“帅哥”是一个单数专有名词,这是不正确的,因为“帅哥”应该是一个形容词。有没有办法解决这个问题,我在NLTK上也尝试过,但得到了相同的结果
这种情况之所以发生,是因为帅哥的大写使其成为鲍勃名字的一部分。这不一定是一个不正确的分析,但如果你想强制形容词分析,你可以删除大写'帅'如下面的文本2和文本4
相关问题 更多 >
编程相关推荐