当前位置: 首页>>代码示例>>Python>>正文


Python TextBlob.classify方法代码示例

本文整理汇总了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
开发者ID:rajaselvan,项目名称:sherlock,代码行数:13,代码来源:sentiment_analysis.py

示例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'
开发者ID:varun50,项目名称:Produc_Recommendation_Twitter,代码行数:15,代码来源:query.py

示例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)
开发者ID:muhammadhabibi,项目名称:CBS01,代码行数:33,代码来源:NaiveBayesTextblob.py

示例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
开发者ID:duneding,项目名称:gensory,代码行数:32,代码来源:classifier.py

示例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()
开发者ID:CS223-YelpReview,项目名称:Yelp-NLP,代码行数:7,代码来源:naiveBayes.py


注:本文中的textblob.TextBlob.classify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。