ahmedraza

analyzer.py

Jan 19th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import nltk
  2. import re
  3. from nltk.tokenize import tokenize
  4. class Analyzer():
  5.     """Implements sentiment analysis."""
  6.  
  7.     def __init__(self, positives, negatives):
  8.         """Initialize Analyzer."""
  9.         #loading positive.txt as dict
  10.         self.positives = []
  11.         #opening file for reading as fpos
  12.         with open('positive-words.txt', 'r') as fpos:
  13.             #iterate over every line
  14.                 for line in fpos:
  15.                     #if line don,t start with ";" load it
  16.                     if (line.startswith(";") != True):
  17.                         self.positives.append(eval(line.strip()))
  18.         #loading negative.txt as dict
  19.         self.negatives = []
  20.         #opening file for reading as fneg
  21.         with open('negative-words.txt', 'r') as fneg:
  22.             #iterate over every line
  23.             for line in fneg:
  24.                 #if line don,t start with ";" load it
  25.                 if (line.startswith(";") != True):
  26.                     self.positives.append(eval(line.strip()))
  27.  
  28.     def analyze(self, text):
  29.         tokenizer = nltk.tokenize.TweetTokenizer()
  30.         tokens = tokenizer.tokenize(text)
  31.         score = 0
  32.        
  33.        
  34.    
  35.  
  36.        
  37.         return 0
Add Comment
Please, Sign In to add comment