Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. def load_words(filename):
  2. word_list = []
  3. with open(filename, 'r') as f:
  4. for line in f:
  5. word_list.append(line.strip())
  6. return word_list
  7.  
  8. positive_text = load_words("NYC3-pos.txt")
  9. negative_text = load_words("NYC3-neg.txt")
  10. score = 0
  11. print("Sentiment Analyzer 2.0")
  12. while True:
  13. input_text = input("Enter a sentence containing a positive or negative word or ENTER to quit: ")
  14. if input_text == "quit":
  15. break
  16. text = input_text.split(" ")
  17. for word in text:
  18. if word in positive_text:
  19. score = score + 1
  20. if word in negative_text:
  21. score = score - 1
  22. if (score > 0):
  23. print("Score: ", score, "is positive.")
  24. elif (score < 0):
  25. print("Score: ", score, "is negative.")
  26. else:
  27. print("Score: ", score, "is neutral.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement