Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nltk
- import re
- from nltk.tokenize import tokenize
- class Analyzer():
- """Implements sentiment analysis."""
- def __init__(self, positives, negatives):
- """Initialize Analyzer."""
- #loading positive.txt as dict
- self.positives = []
- #opening file for reading as fpos
- with open('positive-words.txt', 'r') as fpos:
- #iterate over every line
- for line in fpos:
- #if line don,t start with ";" load it
- if (line.startswith(";") != True):
- self.positives.append(eval(line.strip()))
- #loading negative.txt as dict
- self.negatives = []
- #opening file for reading as fneg
- with open('negative-words.txt', 'r') as fneg:
- #iterate over every line
- for line in fneg:
- #if line don,t start with ";" load it
- if (line.startswith(";") != True):
- self.positives.append(eval(line.strip()))
- def analyze(self, text):
- tokenizer = nltk.tokenize.TweetTokenizer()
- tokens = tokenizer.tokenize(text)
- score = 0
- return 0
Add Comment
Please, Sign In to add comment