Question

In: Computer Science

Perform a sentiment analysis of a big text file in python Extract each word from the...

Perform a sentiment analysis of a big text file in python

Extract each word from the file, transform the words to lower case, and remove special characters from the words using code similar to the following line:w=w.replace(':','').replace('?','').replace(',','').replace('.','').replace('"','').replace('!','').replace('(','').replace(')','').replace('\'','').replace('\\','').replace('/','')

Utilize the lists of positive words, found in positive.txt to perform a sentiment analysis on the file (count how many positive words there are in a file)

positive.txt

crisp
crisper
cure
cure-all
cushy
cute
cuteness
danke
danken
daring
...

file.txt

...has a new campaign song. \nNot sure why they chose this one but, wow!\xf0\x9f\x98\x82 \xf0\x9f\xa4\xb7\xe2\x80\x8d\xe2\x99\x82\xef\xb8\x8f \xf0\x9f\xa4\xaf\n\nHey @JoeBob you may want to replac\xe2\x80\xa6\n'b"RT @EdZipperer: .@AriFlish is 100% correct about the debate....

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

def fileContain(s,filename):
    f = open(filename,'r')
    for i in f:
        if(i==s):
            return True
    return False

count = 0
f = open("file.txt", 'r')
for i in f:
    s = i.split(" ")
    for w in s:
        w = w.replace(':', '').replace('?', '').replace(',', '').replace('.', '').replace('"', '').replace(
            '!', '').replace('(', '').replace(')', '').replace('\'', '').replace('\\', '').replace('/', '')
        if(fileContain(w,"positive.txt")):
            count+=1

print(count)


Related Solutions

I have a Python code that reads the text file, creates word list then calculates word...
I have a Python code that reads the text file, creates word list then calculates word frequency of each word. Please see below: #Open file f = open('example.txt', 'r') #list created with all words data=f.read().lower() list1=data.split() #empty dictionary d={} # Adding all elements of the list to a dictionary and assigning it's value as zero for i in set(list1):     d[i]=0 # checking and counting the values for i in list1:     for j in d.keys():        if i==j:           d[i]=d[i]+1 #Return all non-overlapping...
This is a python file Reads information from a text file into a list of sublists....
This is a python file Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
how to count the word of occurance in the text file example input text file :...
how to count the word of occurance in the text file example input text file : "test1.txt hello : 1 good : 1 morning: 1 how : 1 are : 2 you : 2 good : 1 example output text file : "test2.txt" 1 : 4 2 : 2 3 : 0 4 : 0 5 : 0
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE:...
in PYTHON given a specific text file containing a list of numbers on each line (numbers...
in PYTHON given a specific text file containing a list of numbers on each line (numbers on each line are different) write results to a new file after the following tasks are performed: Get rid of each line of numbers that is not 8 characters long Get rid of lines that don't begin with (478, 932, 188, 642, 093)
Assignment in C programming class: read the text file line by line, and place each word,...
Assignment in C programming class: read the text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. Assume tgat you will use no more than 1000 words in the text, and no more than the first 10 characters in a...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import load_iris”. Split the dataset into two sets: 20% of samples for training, and 80% of samples for testing. NOTE 1: Please use “from sklearn.model_selection import train_test_split” with “random_state=N” and “test_size=0.80”. NOTE 2: The offset/bias column is not needed here for augmenting the input features. (b) Generate the target output using one-hot encoding for both the training set and the test set. (c) Using the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT