到目前为止,我有下面的代码
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上尝试过,但也得到了同样的结果。
发布于 2019-03-26 02:05:59
之所以会发生这种情况,是因为causing的大写导致它被视为Bob名字的一部分。这不一定是一个不正确的分析,但如果你想强制进行形容词分析,你可以去掉下面的text2和text4中的“below”的大写。
text = "Handsome Bob's dog is a beautiful chihuahua"
BrinBot(text)
[('Handsome', 'NNP'), ('Bob', 'NNP'), ("'s", 'POS'), ('dog', 'NN'), ('is', 'VBZ'), ('a', 'DT'), ('beautiful', 'JJ'), ('Chihuahua', 'NNP')]
text2 = "handsome bob's dog is a beautiful chihuahua"
BrinBot(text2)
[('handsome', 'JJ'), ('bob', 'NN'), ("'s", 'POS'), ('dog', 'NN'), ('is', 'VBZ'), ('a', 'DT'), ('beautiful', 'JJ'), ('chihuahua', 'NN')]
text3 = "That beautiful chihuahua is handsome Bob's dog"
BrinBot(text3)
[('That', 'DT'), ('beautiful', 'JJ'), ('chihuahua', 'NN'), ('is', 'VBZ'), ('handsome', 'JJ'), ('Bob', 'NNP'), ("'s", 'POS'), ('dog', 'NN')]
text4 = "That beautiful chihuahua is Handsome Bob's dog"
BrinBot(text4)
[('That', 'DT'), ('beautiful', 'JJ'), ('chihuahua', 'NN'), ('is', 'VBZ'), ('Handsome', 'NNP'), ('Bob', 'NNP'), ("'s", 'POS'), ('dog', 'NN')]https://stackoverflow.com/questions/55326993
复制相似问题