0
$\begingroup$

I have some text files containing moview reviews I need to find out whether the review is good or bad. I tried the following code but its not working:

import nltk
with open("c:/users/user/desktop/datascience/moviesr/movies-1-32.txt", 'r') as m11:
    mov_rev = m11.read()
mov_review1=nltk.word_tokenize(mov_rev)
bon="crap aweful horrible terrible bad bland trite sucks unpleasant boring dull moronic dreadful disgusting distasteful flawed ordinary slow senseless unoriginal weak wacky uninteresting unpretentious "
bag_of_negative_words=nltk.word_tokenize(bon)
bop="Absorbing Big-Budget Brilliant Brutal Charismatic Charming Clever Comical Dazzling Dramatic Enjoyable Entertaining Excellent Exciting  Expensive Fascinating Fast-Moving First-Rate Funny Highly-Charged Hilarious Imaginative Insightful Inspirational Intriguing Juvenile Lasting Legendary Pleasant Powerful Ripping Riveting Romantic Sad  Satirical Sensitive  Sentimental Surprising Suspenseful Tender Thought Provoking Tragic Uplifting Uproarious"
bop.lower()
bag_of_positive_words=nltk.word_tokenize(bop)
vec=[]
for i in bag_of_negative_words:
    if i in mov_review1:
        vec.append(1)
    else:
        for w in bag_of_positive_words:
            if w in moview_review1:
                vec.append(5)

so i am trying to check whether the review contains a positive word or a negative word. If it contains negative word then a value 1 will be assigned to the vector vec else a value of 5 will be assigned. but the output i am getting is an empty vector.

please help.. Also please suggest others way of solving this problem. thanks in advance

$\endgroup$
  • 1
    $\begingroup$ What debugging have you done? This sounds like a pure code review question, and there are other SE sites for that. $\endgroup$ – Sean Owen Dec 3 '14 at 14:31
1
$\begingroup$

Try to search from the database's of officials "bad words" that google publish in this link Goolgles official list of bad words... Also here is the link for the good words Not official list of good words...

For the code i would do it like this...

textArray = file('dir_to_your_text','r').read().split()

#Bad words should be listed like this for the split function to work
# "*** ****** **** ****" the stars are for the cenzuration :P
badArray = file('dir_to_your_bad_word_file).read().split()
goodArray = file('dir_to_your_good_word_file).read().split()

#Than you use maching algoritem from difflib on good and bad word for ewery word in array of words
import difflib

goodMachingCouter = 0;
badMacihngCouter = 0;


for iGood in range(0, len(goodArray)):
    for iWord in range(0, len(textArray)):
        goodMachingCounter += difflib.SequenceMatcher(None, goodArray[iGood], textArray[iWord]).ratio()

for iBad in range(0, len(badArray)):
    for iWord in range(0, len(textArray)):
        badMachingCounter += difflib.SequenceMatcher(None, badArray[ibad], textArray[iWgoodord]).ratio()

goodMachingCouter *= 100/(len(goodArray)*len(textArray))
badMacihngCouter *= 100/(len(badArray)*len(textArray))

print('Show the good measurment of the text in %: '+goodMachingCouter)
print('Show the bad measurment of the text in %: '+badMacihngCouter)
print('Show the hootnes of the text: ' + len(textArray)*goodMachingCounter)

The code will be slow but accurate :) I didn't run and test it pls do it for me and post the correct code :) because i wana test it too :)

|improve this answer|||||
$\endgroup$
1
$\begingroup$

Following link contains a list of positive and negative polarised emotions on the scale of [-5, 5]. Just try to count up the scores based on the word matches and you can get overall movie review score.

http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6010

|improve this answer|||||
$\endgroup$
0
$\begingroup$

try

vec =[]

for word in bag_of_negative_words:
    if word in mov_review1:
        vec.append(1)

for word in bag_of_positive_words:
    if word in moview_review1:
         vec.append(5)
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.