SocialDictionary


NameSocialDictionary JSON
Version 1.2 PyPI version JSON
download
home_pageNone
SummaryThis package is used to analyse sentiment, and emojis are also included in this sentiment analysis. The package uses a pre-trained model to assign an emotion to the emojis
upload_time2024-06-17 18:49:11
maintainerNone
docs_urlNone
authorGoncalo Silva
requires_pythonNone
licenseNone
keywords python text emoroberta sentiment analysis emojis
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SocialDictionary

## Introduction

This package aims to account for emojis in sentiment analysis, making sentiment analysis better when emojis are included in the text. First we take the emojis from the 'https://getemoji.com/' website, then we create a csv with information about each emoji taken, such as the unicode and description, then we calculate the score of the emoji description and assign a sentiment, which can be positive, neutral or negative. After this information we use the EmoRoBERTa model, which uses GoEmotions to recognise emotions, so we then assign an emotion to each of the emojis on the list. Next we place an input containing emojis and then the text is returned with the emoji replaced by the emotion, the sentiment of the text and information about the emoji/s used in the input.

#### The following dependencies must be installed to use the package.

1. pandas- pip install pandas
2. nltk- pip install nltk
3. emoji-pip install emoji
4. googletrans- pip install googletrans==4.0.0-rc1

## Where to get it
You can install the package using pip:
```sh
pip install SocialDictionary
```

## Functions

#### 1. __init__(self)
Function: Constructor of the class, initialises the instance.
Description:
Gets the full path to the CSV file in the 'Dados' folder.
Reads the CSV file using pandas and stores it in the DataFrame self.df.
Starts the SentimentIntensityAnalyzer sentiment analyser.
Initialises the Google Translator.

#### 2. substituir_emoji_por_emocao(self, texto)
Function: Replaces emoticons in the text with the corresponding emotions.
Description:
Creates a dictionary that maps emoticons to their corresponding emotions using the Design and Emotion columns of the DataFrame.
Replaces each emoji in the text with its corresponding emotion.
Returns the changed text.

#### 3. analise_sentimentos(self, texto)
Function: Analyses the sentiment of the given text.
Description:
Uses SentimentIntensityAnalyzer to calculate the sentiment score of the text.
Returns the composite sentiment score.

#### 4. extrair_emojis(self, texto)
Function: Extracts all the emoticons present in the text.
Description:
Goes through each character in the text and checks if it is an emoji using emoji.EMOJI_DATA.
Returns a list of the emoji found in the text.

#### 5. traduzir_texto(self, texto, idioma_destino)
Function: Translate text to the target language.
Description:
Uses Translator to translate the text into the specified language.
Returns the translated text.

#### 6. traduzir_campos(self, campos, idioma_destino)
Function: Translates the fields of a dictionary into the target language.
Description:
Loops through each key-value in the dictionary fields.
Translates the value into the given language.
Returns a new dictionary containing the translated values.

#### 7. analisar_texto(self, texto)
Function: Analyses the supplied text, including emoticons and sentiment.
Description:
Detects the language of the input text.
Extracts emoticons from the original text.
Replaces emoticons with the corresponding emotion.
Performs sentiment analysis on the modified text.
Translates the modified text back to the original language.
Gathers detailed information about the emoticons used and translates this information into the input language.
Returns a dictionary with the modified text, the sentiment of the text and information about the emoji used.

### csv file with emoji data
This file was created by collecting the emoji that are available in a list on the website 'https://getemoji.com/', in this file we have 6 columns, the first one is called 'Design' where we have the graphical representation of the emoji, in the second column we have the 'Unicode' through a function, in the third column we have the 'Description' which is discovered through the emoji library, once we have the description of each emoji in the 'Description' column we calculate the score for each one and then assign a sentiment: If it's below 0 to -1 it's negative, if it's 0 it's neutral and if it's above 0 to 1 it's positive, then using the EmoRoBERTa model we assign an emotion to each emoji using its description, creating the 'emotion' column.

## Usage
#### Guide to use the functions

The SentimentAnalyzer class allows you to analyse text to replace emojis with corresponding emotions, perform sentiment analysis and translate text. Here is a detailed guide to using each function:

1. Initialisation (__init__):

	Initialises the instance of the class, loading a CSV file with emojis and emotions, and initialises the sentiment analyser (SentimentIntensityAnalyzer) and the translator (Translator).


2. Replace Emojis with Emotions ('substituir_emoji_por_emocao'):

	2.1.Replaces emojis in text with their corresponding emotions based on CSV data.
	Parameters: text (str) - Text containing emojis.
	Return: modified_text (str) - Text with emojis replaced by emotions.


3. Sentiment Analysis ('analise_sentimentos'):

	Performs sentiment analysis on the supplied text and returns the composite score.
	Parameters: text (str) - Text for sentiment analysis.
	Return: sentiment (float) - Sentiment analysis composite score.



4. Extract Emojis ('extrair_emojis'):

	Extracts all the emojis present in the text.
	Parameters: text (str) - Text containing emojis.
	Return: emojis (list) - List of emojis found in the text.



5. Translate Text ('traduzir_texto'):

	Translate the text into the target language.
	Parameters: text (str) - Text to be translated; target_language (str) - Target language code 	(e.g. ‘en’ for English).
	Return: translated (str) - Translated text.


6. Translate fields ('traduzir_campos'):

	Translates the fields of a dictionary into the target language.
	Parameters: fields (dict) - Dictionary with fields to translate; target_language (str) - 	Target language code.
	Return: translated_fields (dict) - Dictionary with the translated fields.


7. Parse text ('analisar_texto'):

	Parses the given text, replaces emoticons with their corresponding emotions, performs 	sentiment analysis and translates the modified text.
	Parameters: text (str) - text to analyse.
	Return: translated_results (dict) - Dictionary containing the modified text, the sentiment 	of the text and information about the emoticons used.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "SocialDictionary",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, text, EmoRoBERTa, sentiment analysis, emojis",
    "author": "Goncalo Silva",
    "author_email": "gresi2001@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/00/32/8b3ea88b27814cb7f69e37dd31db397157b76ab22c638e78ec0e65cc0479/SocialDictionary-1.2.tar.gz",
    "platform": null,
    "description": "# SocialDictionary\r\n\r\n## Introduction\r\n\r\nThis package aims to account for emojis in sentiment analysis, making sentiment analysis better when emojis are included in the text. First we take the emojis from the 'https://getemoji.com/' website, then we create a csv with information about each emoji taken, such as the unicode and description, then we calculate the score of the emoji description and assign a sentiment, which can be positive, neutral or negative. After this information we use the EmoRoBERTa model, which uses GoEmotions to recognise emotions, so we then assign an emotion to each of the emojis on the list. Next we place an input containing emojis and then the text is returned with the emoji replaced by the emotion, the sentiment of the text and information about the emoji/s used in the input.\r\n\r\n#### The following dependencies must be installed to use the package.\r\n\r\n1. pandas- pip install pandas\r\n2. nltk- pip install nltk\r\n3. emoji-pip install emoji\r\n4. googletrans- pip install googletrans==4.0.0-rc1\r\n\r\n## Where to get it\r\nYou can install the package using pip:\r\n```sh\r\npip install SocialDictionary\r\n```\r\n\r\n## Functions\r\n\r\n#### 1. __init__(self)\r\nFunction: Constructor of the class, initialises the instance.\r\nDescription:\r\nGets the full path to the CSV file in the 'Dados' folder.\r\nReads the CSV file using pandas and stores it in the DataFrame self.df.\r\nStarts the SentimentIntensityAnalyzer sentiment analyser.\r\nInitialises the Google Translator.\r\n\r\n#### 2. substituir_emoji_por_emocao(self, texto)\r\nFunction: Replaces emoticons in the text with the corresponding emotions.\r\nDescription:\r\nCreates a dictionary that maps emoticons to their corresponding emotions using the Design and Emotion columns of the DataFrame.\r\nReplaces each emoji in the text with its corresponding emotion.\r\nReturns the changed text.\r\n\r\n#### 3. analise_sentimentos(self, texto)\r\nFunction: Analyses the sentiment of the given text.\r\nDescription:\r\nUses SentimentIntensityAnalyzer to calculate the sentiment score of the text.\r\nReturns the composite sentiment score.\r\n\r\n#### 4. extrair_emojis(self, texto)\r\nFunction: Extracts all the emoticons present in the text.\r\nDescription:\r\nGoes through each character in the text and checks if it is an emoji using emoji.EMOJI_DATA.\r\nReturns a list of the emoji found in the text.\r\n\r\n#### 5. traduzir_texto(self, texto, idioma_destino)\r\nFunction: Translate text to the target language.\r\nDescription:\r\nUses Translator to translate the text into the specified language.\r\nReturns the translated text.\r\n\r\n#### 6. traduzir_campos(self, campos, idioma_destino)\r\nFunction: Translates the fields of a dictionary into the target language.\r\nDescription:\r\nLoops through each key-value in the dictionary fields.\r\nTranslates the value into the given language.\r\nReturns a new dictionary containing the translated values.\r\n\r\n#### 7. analisar_texto(self, texto)\r\nFunction: Analyses the supplied text, including emoticons and sentiment.\r\nDescription:\r\nDetects the language of the input text.\r\nExtracts emoticons from the original text.\r\nReplaces emoticons with the corresponding emotion.\r\nPerforms sentiment analysis on the modified text.\r\nTranslates the modified text back to the original language.\r\nGathers detailed information about the emoticons used and translates this information into the input language.\r\nReturns a dictionary with the modified text, the sentiment of the text and information about the emoji used.\r\n\r\n### csv file with emoji data\r\nThis file was created by collecting the emoji that are available in a list on the website 'https://getemoji.com/', in this file we have 6 columns, the first one is called 'Design' where we have the graphical representation of the emoji, in the second column we have the 'Unicode' through a function, in the third column we have the 'Description' which is discovered through the emoji library, once we have the description of each emoji in the 'Description' column we calculate the score for each one and then assign a sentiment: If it's below 0 to -1 it's negative, if it's 0 it's neutral and if it's above 0 to 1 it's positive, then using the EmoRoBERTa model we assign an emotion to each emoji using its description, creating the 'emotion' column.\r\n\r\n## Usage\r\n#### Guide to use the functions\r\n\r\nThe SentimentAnalyzer class allows you to analyse text to replace emojis with corresponding emotions, perform sentiment analysis and translate text. Here is a detailed guide to using each function:\r\n\r\n1. Initialisation (__init__):\r\n\r\n\tInitialises the instance of the class, loading a CSV file with emojis and emotions, and initialises the sentiment analyser (SentimentIntensityAnalyzer) and the translator (Translator).\r\n\r\n\r\n2. Replace Emojis with Emotions ('substituir_emoji_por_emocao'):\r\n\r\n\t2.1.Replaces emojis in text with their corresponding emotions based on CSV data.\r\n\tParameters: text (str) - Text containing emojis.\r\n\tReturn: modified_text (str) - Text with emojis replaced by emotions.\r\n\r\n\r\n3. Sentiment Analysis ('analise_sentimentos'):\r\n\r\n\tPerforms sentiment analysis on the supplied text and returns the composite score.\r\n\tParameters: text (str) - Text for sentiment analysis.\r\n\tReturn: sentiment (float) - Sentiment analysis composite score.\r\n\r\n\r\n\r\n4. Extract Emojis ('extrair_emojis'):\r\n\r\n\tExtracts all the emojis present in the text.\r\n\tParameters: text (str) - Text containing emojis.\r\n\tReturn: emojis (list) - List of emojis found in the text.\r\n\r\n\r\n\r\n5. Translate Text ('traduzir_texto'):\r\n\r\n\tTranslate the text into the target language.\r\n\tParameters: text (str) - Text to be translated; target_language (str) - Target language code \t(e.g. \u00e2\u20ac\u02dcen\u00e2\u20ac\u2122 for English).\r\n\tReturn: translated (str) - Translated text.\r\n\r\n\r\n6. Translate fields ('traduzir_campos'):\r\n\r\n\tTranslates the fields of a dictionary into the target language.\r\n\tParameters: fields (dict) - Dictionary with fields to translate; target_language (str) - \tTarget language code.\r\n\tReturn: translated_fields (dict) - Dictionary with the translated fields.\r\n\r\n\r\n7. Parse text ('analisar_texto'):\r\n\r\n\tParses the given text, replaces emoticons with their corresponding emotions, performs \tsentiment analysis and translates the modified text.\r\n\tParameters: text (str) - text to analyse.\r\n\tReturn: translated_results (dict) - Dictionary containing the modified text, the sentiment \tof the text and information about the emoticons used.\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This package is used to analyse sentiment, and emojis are also included in this sentiment analysis. The package uses a pre-trained model to assign an emotion to the emojis",
    "version": "1.2",
    "project_urls": null,
    "split_keywords": [
        "python",
        " text",
        " emoroberta",
        " sentiment analysis",
        " emojis"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7ad6942cb75e79e24be1475ce5fdc535441da32f621851c18f7fa65bdb0b8bb",
                "md5": "adc6ea39b7929407270231864d8e30c7",
                "sha256": "ec308f458a5a07a71880e7b1467a161506f155bda33d6c8520726a5d96d4319f"
            },
            "downloads": -1,
            "filename": "SocialDictionary-1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "adc6ea39b7929407270231864d8e30c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 53331,
            "upload_time": "2024-06-17T18:49:03",
            "upload_time_iso_8601": "2024-06-17T18:49:03.239675Z",
            "url": "https://files.pythonhosted.org/packages/f7/ad/6942cb75e79e24be1475ce5fdc535441da32f621851c18f7fa65bdb0b8bb/SocialDictionary-1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "00328b3ea88b27814cb7f69e37dd31db397157b76ab22c638e78ec0e65cc0479",
                "md5": "e08263073fbafcc7054c7b356773fa6f",
                "sha256": "dc95d60e4eea7cb56b89de3b6a5a6aca3960444f5668b8b1734f7ef6fd4d4dff"
            },
            "downloads": -1,
            "filename": "SocialDictionary-1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e08263073fbafcc7054c7b356773fa6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 54142,
            "upload_time": "2024-06-17T18:49:11",
            "upload_time_iso_8601": "2024-06-17T18:49:11.281022Z",
            "url": "https://files.pythonhosted.org/packages/00/32/8b3ea88b27814cb7f69e37dd31db397157b76ab22c638e78ec0e65cc0479/SocialDictionary-1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-17 18:49:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "socialdictionary"
}
        
Elapsed time: 0.71532s