def get_polarity(word, is_neg): if util.is_in_file('lists/positive-words.txt', word, False): polarity = '+' elif util.is_in_file('lists/negative-words.txt', word, False): polarity = '-' elif util.is_in_file('lists/swear-words.txt', word, False): polarity = '-' else: polarity = '0' if is_neg: polarity = switch(polarity) return polarity
def get_polarity(word,is_neg): if util.is_in_file('lists/positive-words.txt',word,False): polarity='+' elif util.is_in_file('lists/negative-words.txt',word,False): polarity='-' elif util.is_in_file('lists/swear-words.txt',word,False): polarity='-' else : polarity='0' if is_neg : polarity=switch(polarity) return polarity
def left_adjective_sentiment(aspect,pos_tweet,is_neg) : sentiment=['NULL']*3 sentiment[0]=aspect ctr=util.get_index(pos_tweet,aspect,0)-1 while(pos_tweet[ctr][1]!='A' and ctr>=0) : ctr=ctr-1 else : if(pos_tweet[ctr][1]=='A' and ctr>=0) : adj=pos_tweet[ctr][0] sentiment[1]=adj if util.is_in_file('lists/comparative-words.txt',adj,False) or util.is_in_file('lists/superlative-words.txt',adj,False) : sentiment[2]=switch(get_polarity(adj,is_neg)) else : sentiment[2]=get_polarity(adj,is_neg) ctr=TERMINATE return sentiment
def found_negation(aspect,pos_tweet,wsize=NEGATION_WINDOW): is_neg=False if len(pos_tweet)<wsize : wsize=len(pos_tweet) ind=util.get_index(pos_tweet,aspect,0) if ind<wsize : start=0 end=wsize-1 else : start=wsize-ind+1 end=ind for i in range(start,end+1): word=pos_tweet[i][0] if util.is_in_file('lists/negative-words.txt',word,False) or util.is_in_file('lists/swear-words.txt',word,False): is_neg=True return is_neg
def right_verb_sentiment(aspect,pos_tweet,is_neg) : sentiment=['NULL']*3 sentiment[0]=aspect ctr=util.get_index(pos_tweet,aspect,0)+1 while(ctr>=0 and ctr<len(pos_tweet) and pos_tweet[ctr][1]!='V') : ctr=ctr+1 else : if(ctr>=0 and ctr<len(pos_tweet) and pos_tweet[ctr][1]=='R') : verb=pos_tweet[ctr][0] sentiment[1]=verb if not(util.is_in_file('lists/copulative.txt',verb,False)) and not(util.is_in_file('lists/intensifier.txt',verb,False)) : sentiment[2]=get_polarity(verb,is_neg) else : sentiment[2]=str('0') ctr=TERMINATE return sentiment
def right_adjective_sentiment(aspect,pos_tweet,is_neg) : sentiment=['NULL']*3 sentiment[0]=aspect ctr=util.get_index(pos_tweet,aspect,0)+1 while(ctr>=0 and ctr<len(pos_tweet) and pos_tweet[ctr][1]!='A') : ctr=ctr+1 else : if(ctr>=0 and ctr<len(pos_tweet) and pos_tweet[ctr][1]=='A') : adj=pos_tweet[ctr][0] sentiment[1]=adj if not(util.is_in_file('lists/intensifier.txt',adj,False)) : if util.is_in_file('lists/comparative-words.txt',adj,False) or util.is_in_file('lists/superlative-words.txt',adj,False) : sentiment[2]=switch(get_polarity(adj,is_neg)) else : sentiment[2]=get_polarity(adj,is_neg) ctr=TERMINATE return sentiment
def found_negation(aspect, pos_tweet, wsize=NEGATION_WINDOW): is_neg = False if len(pos_tweet) < wsize: wsize = len(pos_tweet) ind = util.get_index(pos_tweet, aspect, 0) if ind < wsize: start = 0 end = wsize - 1 else: start = wsize - ind + 1 end = ind for i in range(start, end + 1): word = pos_tweet[i][0] if util.is_in_file('lists/negative-words.txt', word, False) or util.is_in_file( 'lists/swear-words.txt', word, False): is_neg = True return is_neg
def left_adjective_sentiment(aspect, pos_tweet, is_neg): sentiment = ['NULL'] * 3 sentiment[0] = aspect ctr = util.get_index(pos_tweet, aspect, 0) - 1 while (pos_tweet[ctr][1] != 'A' and ctr >= 0): ctr = ctr - 1 else: if (pos_tweet[ctr][1] == 'A' and ctr >= 0): adj = pos_tweet[ctr][0] sentiment[1] = adj if util.is_in_file('lists/comparative-words.txt', adj, False) or util.is_in_file( 'lists/superlative-words.txt', adj, False): sentiment[2] = switch(get_polarity(adj, is_neg)) else: sentiment[2] = get_polarity(adj, is_neg) ctr = TERMINATE return sentiment
def right_verb_sentiment(aspect, pos_tweet, is_neg): sentiment = ['NULL'] * 3 sentiment[0] = aspect ctr = util.get_index(pos_tweet, aspect, 0) + 1 while (ctr >= 0 and ctr < len(pos_tweet) and pos_tweet[ctr][1] != 'V'): ctr = ctr + 1 else: if (ctr >= 0 and ctr < len(pos_tweet) and pos_tweet[ctr][1] == 'R'): verb = pos_tweet[ctr][0] sentiment[1] = verb if not (util.is_in_file('lists/copulative.txt', verb, False)) and not (util.is_in_file( 'lists/intensifier.txt', verb, False)): sentiment[2] = get_polarity(verb, is_neg) else: sentiment[2] = str('0') ctr = TERMINATE return sentiment
def right_adjective_sentiment(aspect, pos_tweet, is_neg): sentiment = ['NULL'] * 3 sentiment[0] = aspect ctr = util.get_index(pos_tweet, aspect, 0) + 1 while (ctr >= 0 and ctr < len(pos_tweet) and pos_tweet[ctr][1] != 'A'): ctr = ctr + 1 else: if (ctr >= 0 and ctr < len(pos_tweet) and pos_tweet[ctr][1] == 'A'): adj = pos_tweet[ctr][0] sentiment[1] = adj if not (util.is_in_file('lists/intensifier.txt', adj, False)): if util.is_in_file('lists/comparative-words.txt', adj, False) or util.is_in_file( 'lists/superlative-words.txt', adj, False): sentiment[2] = switch(get_polarity(adj, is_neg)) else: sentiment[2] = get_polarity(adj, is_neg) ctr = TERMINATE return sentiment