0

I have implementing (in my understanding) analyzer.py. I am confused after dividing a tweet into tokens how to check them if they are available in "negative" or "positive", my question is "Is there a function used to check"? Kindly view my code there might be more errors I have taken help from google to implement it like this.

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
0

I found the answer I have to open a new file and then iterate over it to check for them.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .