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


Python vaderSentiment.SentimentIntensityAnalyzer方法代码示例

本文整理汇总了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] 
开发者ID:h2oai,项目名称:driverlessai-recipes,代码行数:26,代码来源:sentiment_score_vader.py

示例2: __init__

# 需要导入模块: from vaderSentiment import vaderSentiment [as 别名]
# 或者: from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer [as 别名]
def __init__(self):
        self.analyzer = SentimentIntensityAnalyzer()
        # self.test() 
开发者ID:Drakkar-Software,项目名称:OctoBot-Tentacles,代码行数:5,代码来源:text_analysis.py

示例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'] 
开发者ID:h2oai,项目名称:driverlessai-recipes,代码行数:6,代码来源:vader_text_sentiment_transformer.py

示例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 
开发者ID:AutoViML,项目名称:Auto_ViML,代码行数:31,代码来源:Auto_NLP.py

示例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) 
开发者ID:Azure-Samples,项目名称:azure-python-labs,代码行数:8,代码来源:__init__.py

示例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() 
开发者ID:asyml,项目名称:forte,代码行数:6,代码来源:sentiment_analysis.py


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