<jupyter_start><jupyter_text>Sample Emotion Analysis<jupyter_code>!pip install nest_asyncio
from logging.handlers import TimedRotatingFileHandler
import logging.config
from psenti import SentimentAnalysis, SentimentConnection, Document
from sklearn import metrics
from datetime import datetime
import socket
import json

user_name = socket.gethostname()
host = '127.0.0.1'
port = 5000

import nest_asyncio
import asyncio
nest_asyncio.apply(loop=asyncio.get_event_loop())

logger = logging.getLogger('JupyterUI')
logFormatter = logging.Formatter('%(asctime)s - [%(thread)s] [%(threadName)s]- %(name)s - %(levelname)s - %(message)s')
logger.setLevel(logging.DEBUG)

console = logging.StreamHandler()
console.setFormatter(logFormatter)
console.setLevel(logging.DEBUG)

logger.addHandler(console)

connection = SentimentConnection(host=host, port=port, client_id=user_name)<jupyter_output>Requirement already satisfied: nest_asyncio in c:\users\andrius.wikiled\.conda\envs\tensor-gpu\lib\site-packages (1.3.3)<jupyter_text>Setup results Processing<jupyter_code>reviews = ['I love this hello kitty decal! I like that the bow is pink instead of red. Only bad thing is that after putting it on the window theres a few air bubbles, but that most likely my fault. Shipped fast too.']

def process_result(result):
    
    if 'Attributes' in result:
        for key, value in result['Attributes'].items():
            logger.info(f'Document emotion [{key}]: {float(value):1.2f}')    
    
    logger.info('=' * 20)    
    logger.info('Emotion Words:')    
    logger.info('=' * 20)    
    for sentence in result['Sentences']:
        for word in sentence['Words']:
            if 'Emotions' in word and word['Emotions'] != ['None']:
                logger.info(f"Word [{word['Text']}] Emotions: {word['Emotions']}")            
                
    logger.info('=' * 20)    
    logger.info('Word Attributes:')    
    logger.info('=' * 20)    
    for sentence in result['Sentences']:
        for word in sentence['Words']:            
            if 'Attributes' in word and len(word['Attributes']) > 0:
                logger.info(f"Word [{word['Text']}] Attributes: {word['Attributes']}")<jupyter_output><empty_output><jupyter_text>Analyse<jupyter_code>analysis = SentimentAnalysis(connection, extract_emotions=True)
analysis.on_message.subscribe(lambda result: process_result(result))
analysis.detect_sentiment_text(reviews)<jupyter_output>2020-06-02 16:14:28,061 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Anger]: 0.02
2020-06-02 16:14:28,061 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Anticipation]: 0.02
2020-06-02 16:14:28,061 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Disgust]: 0.02
2020-06-02 16:14:28,062 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Fear]: 0.02
2020-06-02 16:14:28,062 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Joy]: 0.02
2020-06-02 16:14:28,063 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Sadness]: 0.05
2020-06-02 16:14:28,063 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Surprise]: 0.00
2020-06-02 16:14:28,064 - [122124] [MainThread]- JupyterUI - INFO - Document emotion [Trust]: 0.00
2020-06-02 16:14:28,064 - [122124] [MainThread]- JupyterUI - INFO - ====================
2020-06-02 16:14:28,065 - [122124] [MainThread]- JupyterUI - INFO - Emotion Words:
2020-06-02 16:14:28,065 -[...]
{'fraction_non_alphanumeric': 0.14497385241138872, 'fraction_numerical': 0.08570598489250436, 'mean_word_length': 4.193061840120664, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '539354', 'license': 'Apache-2.0', 'n_tokens_mistral': 1369, 'n_tokens_neox': 1137, 'n_words': 274, 'path': 'src/Python.Client/Notebooks/Emotions.ipynb', 'repo_name': 'AndMu/Wikiled.Sentiment.Service', 'size': '3442'}