本文整理汇总了Python中vaderSentiment.vaderSentiment.SentimentIntensityAnalyzer方法的典型用法代码示例。如果您正苦于以下问题:Python vaderSentiment.SentimentIntensityAnalyzer方法的具体用法?Python vaderSentiment.SentimentIntensityAnalyzer怎么用?Python vaderSentiment.SentimentIntensityAnalyzer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vaderSentiment.vaderSentiment
的用法示例。
在下文中一共展示了vaderSentiment.SentimentIntensityAnalyzer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_data
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def create_data(X: dt.Frame = None) -> Union[str, List[str],
dt.Frame, List[dt.Frame],
np.ndarray, List[np.ndarray],
pd.DataFrame, List[pd.DataFrame]]:
# exit gracefully if method is called as a data upload rather than data modify
if X is None:
return []
import os
from h2oaicore.systemutils import config
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
X = dt.Frame(X).to_pandas()
for text_colname in text_colnames:
X["sentiment_vader_dai_" + text_colname] = X[text_colname].astype(str).fillna("NA").apply(
lambda x: SentimentIntensityAnalyzer().polarity_scores(x)['compound'])
temp_path = os.path.join(config.data_directory, config.contrib_relative_directory)
os.makedirs(temp_path, exist_ok=True)
# Save files to disk
file_train = os.path.join(temp_path, output_dataset_name + ".csv")
X.to_csv(file_train, index=False)
return [file_train]
示例2: __init__
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def __init__(self):
self.analyzer = SentimentIntensityAnalyzer()
# self.test()
示例3: sentimentAnalysis
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def sentimentAnalysis(s):
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
return analyzer.polarity_scores(s)['compound']
示例4: add_sentiment
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def add_sentiment(data, nlp_column):
"""
############ Parts of SPeech Tagging using Spacy ################################
### We will now use the text column to calculate the sentiment in each to
### assign an average objectivity score and positive vs. negative scores.
### If a word cannot be found in the dataset we can ignore it. If a
### text has no words that match something in our dataset, we can
### assign an overall neutral score of 'objectivity = 1' and 'pos_vs_neg of 0'.
####### This is to be done only where data sets are small <10K rows. ####
"""
start_time = time.time()
print('Using Vader to calculate objectivity and pos-neg-neutral scores')
analyzer = SentimentIntensityAnalyzer()
data[nlp_column+'_vader_neg'] = 0
data[nlp_column+'_vader_pos'] = 0
data[nlp_column+'_vader_neu'] = 0
data[nlp_column+'_vader_compound'] = 0
data[nlp_column+'_vader_neg'] = data[nlp_column].map(
lambda txt: analyzer.polarity_scores(txt)['neg']).fillna(0)
data[nlp_column+'_vader_pos'] = data[nlp_column].map(
lambda txt: analyzer.polarity_scores(txt)['pos']).fillna(0)
data[nlp_column+'_vader_neutral'] = data[nlp_column].map(
lambda txt: analyzer.polarity_scores(txt)['neu']).fillna(0)
data[nlp_column+'_vader_compound'] = data[nlp_column].map(
lambda txt: analyzer.polarity_scores(txt)['compound']).fillna(0)
cols = [nlp_column+'_vader_neg',nlp_column+'_vader_pos',nlp_column+'_vader_neu',nlp_column+'_vader_compound']
print(' Created %d new columns using SentinmentIntensityAnalyzer. Time taken = %d seconds' %(len(cols),time.time()-start_time))
return data, cols
######### Create new columns that provide summary stats of NLP string columns
示例5: main
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def main(req: func.HttpRequest) -> func.HttpResponse:
analyzer = SentimentIntensityAnalyzer()
text = req.params.get("text")
scores = analyzer.polarity_scores(text)
sentiment = "positive" if scores["compound"] > 0 else "negative"
return func.HttpResponse(sentiment)
示例6: __init__
# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def __init__(self):
super().__init__()
self.sentence_component = None
self.analyzer = SentimentIntensityAnalyzer()