<jupyter_start><jupyter_text>importing reqired modules<jupyter_code>from collections import Counter
import matplotlib.pyplot as plt
import string<jupyter_output><empty_output><jupyter_text>rading text from the file<jupyter_code>with open('read.txt', 'r') as f:
  article_text = f.read()
# printing it
article_text<jupyter_output><empty_output><jupyter_text>clearning the text, and lowercaseing<jupyter_code>article_text = article_text.replace('\n', ' ')
cleaned_text = article_text.translate(str.maketrans('', '', string.punctuation)).lower()
# printing it
cleaned_text<jupyter_output><empty_output><jupyter_text>tokenize<jupyter_code>tokenize_words = cleaned_text.split(' ')
print(tokenize_words)<jupyter_output>['i', 'dropped', 'out', 'of', 'reed', 'college', 'after', 'the', 'first', '6', 'months', 'but', 'then', 'stayed', 'around', 'as', 'a', 'dropin', 'for', 'another', '18', 'months', 'or', 'so', 'before', 'i', 'really', 'quit', 'so', 'why', 'did', 'i', 'drop', 'out', '', 'it', 'started', 'before', 'i', 'was', 'born', 'my', 'biological', 'mother', 'was', 'a', 'young', 'unwed', 'college', 'graduate', 'student', 'and', 'she', 'decided', 'to', 'put', 'me', 'up', 'for', 'adoption', 'she', 'felt', 'very', 'strongly', 'that', 'i', 'should', 'be', 'adopted', 'by', 'college', 'graduates', 'so', 'everything', 'was', 'all', 'set', 'for', 'me', 'to', 'be', 'adopted', 'at', 'birth', 'by', 'a', 'lawyer', 'and', 'his', 'wife', 'except', 'that', 'when', 'i', 'popped', 'out', 'they', 'decided', 'at', 'the', 'last', 'minute', 'that', 'they', 'really', 'wanted', 'a', 'girl', 'so', 'my', 'parents', 'who', 'were', 'on', 'a', 'waiting', 'list', 'got', 'a', 'call', 'in', 'the', 'middle', 'of', 'the', 'night', 'a[...]<jupyter_text>stop words from nltk library<jupyter_code>stop_words = {'i', 'with', 'he', 'down', 'itself', 'm', 'shan', 'no', 'yourself', 'but', 'the', 'y', 'again', 'more', 'o', "she's", 'theirs', 'my', "isn't", 'are', 're', 'their', 'own', 'during', 'don', 'such', 'me', "you'll", 'have', 'has', 'an', 'isn', 'wouldn', 'between', 'just', 'this', 'himself', 'very', 'further', 'by', 'doing', 'so', "it's", "won't", 'out', 'not', 'ours', 'didn', 'on', 'were', 'that', 's', 'which', "don't", 'll', 'nor', "needn't", 'some', 'above', 'any', "shouldn't", "hadn't", "mightn't", 'needn', 'after', 'ourselves', 'a', "didn't", 'hers', 'until', "that'll", 'once', 'mustn', 'mightn', 'hadn', 'in', 'being', 'few', 'or', "doesn't", 't', 'been', "wasn't", 'can', 'themselves', 'up', 'to', 'it', 'for', 'had', 'haven', 'am', 'through', 'she', 'too', 'herself', 'than', 'as', 'yourselves', 'before', 'and', 'because', 'where', 'doesn', 'weren', 'under', 'whom', 'same', 'ain', 'was', 'should', 'there', 'hasn', 'shouldn', 'off', 'other', 'couldn', 'at', 'those', 'over', 'myself', "hasn't", 'your', 'be', 'do', 'why', 'does', 'below', "you've", 'd', 'aren', 'who', "should've", "mustn't", 'from', 'of', 've', "haven't", 'will', 'its', 'what', 'did', 'won', 'yours', 'you', 'him', 'if', 'each', 'both', 'while', 'how', 'they', 'about', 'we', "you'd", 'most', "couldn't", "weren't", "you're", 'here', 'wasn', 'all', 'them', 'now', "shan't", 'against', 'ma', "wouldn't", 'his', 'is', 'then', 'only', 'when', 'having', "aren't", 'into', 'these', 'our', 'her'}<jupyter_output><empty_output><jupyter_text>getting all emotions word<jupyter_code>word_and_emotions = dict()
with open('emotions.txt', 'r') as f:
  for emotion in f.readlines():
    emotion = emotion.replace('\n', '').replace("'", '').replace(',', '').replace(' ', '')
    word, emot = emotion.split(':')
    word_and_emotions[word] = emot
  
print(word_and_emotions)<jupyter_output>{'victimized': 'sad', 'accused': 'cheated', 'acquitted': 'singledout', 'adorable': 'loved', 'adored': 'loved', 'affected': 'attracted', 'afflicted': 'sad', 'aghast': 'fearful', 'agog': 'attracted', 'agonized': 'sad', 'alarmed': 'fearful', 'amused': 'happy', 'angry': 'angry', 'anguished': 'sad', 'animated': 'happy', 'annoyed': 'angry', 'anxious': 'attracted', 'apathetic': 'apathetic', 'appalled': 'angry', 'appeased': 'singledout', 'appreciated': 'esteemed', 'apprehensive': 'anxious', 'approvedof': 'loved', 'ardent': 'lustful', 'aroused': 'lustful', 'attached': 'attached', 'attracted': 'attracted', 'autonomous': 'free', 'awed': 'fearful', 'awkward': 'embarrassed', 'beatendown': 'powerless', 'beatific': 'happy', 'belonging': 'attached', 'bereaved': 'sad', 'betrayed': 'cheated', 'bewildered': 'surprise', 'bitter': 'angry', 'blissful': 'happy', 'blithe': 'happy', 'blocked': 'powerless', 'blue': 'sad', 'boiling': 'angry', 'bold': 'fearless', 'bored': 'bored', 'brave': 'fearless', 'bright': '[...]<jupyter_text>adding emotional_words from tokenized words to a list<jupyter_code>emotioal_words = []
for word in tokenize_words:
  if word in word_and_emotions:
    emotioal_words.append(word)
    
print(emotioal_words)<jupyter_output>['loved', 'great', 'great', 'down', 'lucky', 'loved', 'released', 'down', 'loved', 'rejected', 'replaced', 'animated', 'needed', 'loved', 'satisfied', 'great', 'great', 'great', 'important', 'important', 'down']<jupyter_text>counting frequency of each word and plotting the graph<jupyter_code>words_counts = Counter(emotioal_words)
print(f'words_counts: {dict(words_counts)}')
# plotting
fig, ax1 = plt.subplots()
ax1.bar(words_counts.keys(), words_counts.values(), color='lightyellow', edgecolor='black')
fig.autofmt_xdate()
plt.show()<jupyter_output>words_counts: {'loved': 4, 'great': 5, 'down': 3, 'lucky': 1, 'released': 1, 'rejected': 1, 'replaced': 1, 'animated': 1, 'needed': 1, 'satisfied': 1, 'important': 2}<jupyter_text>checking sentinmental analysis using nltk<jupyter_code>from nltk.sentiment.vader import SentimentIntensityAnalyzer
import nltk
nltk.download('vader_lexicon')
def sentiment_analyse(sentiment_text):
  score = SentimentIntensityAnalyzer().polarity_scores(sentiment_text)
  if score['neg'] > score['pos']:
    print(f'Negative Sentiment')
  elif score['neg'] < score['pos']:
    print(f'Positive Sentiment')
  else:
    print(f'Neutral Sentiment')
sentiment_analyse(cleaned_text)<jupyter_output>Positive Sentiment
{'fraction_non_alphanumeric': 0.2635507951963648, 'fraction_numerical': 0.002596559558584875, 'mean_word_length': 7.5835654596100275, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '477104', 'license': 'MIT', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2344, 'n_words': 570, 'path': 'Notebooks/Sentimental-Analysis/Sentimental.ipynb', 'repo_name': 'Bhagyashri2000/Grokking-Machine-Learning', 'size': '6162'}