本文整理汇总了Python中textblob.TextBlob.classify方法的典型用法代码示例。如果您正苦于以下问题:Python TextBlob.classify方法的具体用法?Python TextBlob.classify怎么用?Python TextBlob.classify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类textblob.TextBlob
的用法示例。
在下文中一共展示了TextBlob.classify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_sentiment
# 需要导入模块: from textblob import TextBlob [as 别名]
# 或者: from textblob.TextBlob import classify [as 别名]
def find_sentiment(string):
# train the classifier
cl = NaiveBayesClassifier(train)
# load the classifier
blob = TextBlob(string, classifier=cl)
print "\n\n\n\t\t\t{}".format(blob.classify())
return
示例2: analyze_tweets
# 需要导入模块: from textblob import TextBlob [as 别名]
# 或者: from textblob.TextBlob import classify [as 别名]
def analyze_tweets(cl):
file = 'consumer.json'
f = open(file, 'r')
data = f.read()
blob = TextBlob(data,classifier=cl)
a = blob.classify()
print 'The product have an overall ' + a + ' rating\n'
#print 'The majority of the tweets that were positive are ' + str(b) + '\n'
#print 'The percent of the tweets that were negative are ' + str(c) + '\n'
return 'The product have an overall ' + a + ' rating\n'
示例3: NaiveBayesClassifier
# 需要导入模块: from textblob import TextBlob [as 别名]
# 或者: from textblob.TextBlob import classify [as 别名]
('My boss is horrible.', 'neg')]
test = [
('The beer was good.', 'pos'),
('I do not enjoy my job', 'neg'),
("I ain't feeling dandy today.", 'neg'),
("I feel amazing!", 'pos'),
('Gary is a friend of mine.', 'pos'),
("I can't believe I'm doing this.", 'neg')]
cl = NaiveBayesClassifier(train)
# Classify some text
# print(cl.classify("Their burgers are amazing.")) # "pos"
# print(cl.classify("I don't like their pizza.")) # "neg"
# Classify a TextBlob
blob = TextBlob("The beer was amazing. But the hangover was horrible. "
"My boss was not pleased.", classifier=cl)
print(blob)
print(blob.classify())
for sentence in blob.sentences:
print(sentence)
print(sentence.classify())
# Compute accuracy
print("Accuracy: {0}".format(cl.accuracy(test)))
# Show 5 most informative features
cl.show_informative_features(5)
示例4: NaiveBayesClassifier
# 需要导入模块: from textblob import TextBlob [as 别名]
# 或者: from textblob.TextBlob import classify [as 别名]
cl = NaiveBayesClassifier(train)
print cl.classify(tx_cl)
print cl.classify("El subte funciona bien")
prob_dist = cl.prob_classify(tx_prob)
print prob_dist.max()
print round(prob_dist.prob("pos"), 2)
print round(prob_dist.prob("neg"), 2)
print cl.accuracy(data_sets.en_test)
print cl.show_informative_features(5)
#Using TextBlob
blob = TextBlob("No funca por que hay obras para mejorar la cosa", classifier=cl)
print blob.sentiment
print blob.classify()
blob = TextBlob("El subte funciona normal", classifier=cl)
print blob.sentiment
print blob.classify()
blob = TextBlob("Se realizan obras en el subte A", classifier=cl)
print blob.sentiment
print blob.classify()
blob = TextBlob("No funciona, anda averiguar por que. Quizas hay un accidente", classifier=cl)
print blob.sentiment
print blob.classify()
blob = TextBlob(u"El subte funciona ok", classifier=cl)
print blob.sentiment
示例5: testSentence
# 需要导入模块: from textblob import TextBlob [as 别名]
# 或者: from textblob.TextBlob import classify [as 别名]
def testSentence(self,sentence,classifier):
filtered_word_list = [word for word in sentence.lower().split() if word not in stopwords.words('english')]
refinedText = " ".join(filtered_word_list)
blob = TextBlob(refinedText, classifier=classifier)
return blob.classify()