def check_for_noun_adj(depend_dict, pos_dict,final_score,neg_words): # getting the score and stopwords dictionary sd,stopwords = get_dict() flag = 0 stemmer3 = WordNetLemmatizer() for value in depend_dict.values(): for j in range(len(value)): score1 = 100 score2 = 100 li = value[j] if "nsubj" in li[0] or "mod" in li[0]: meaning = 0.2 n1 = li[1] n2 = li[3] m1, m2 = check_for_negative(n1,n2,li[2],li[4],neg_words) try: t1 = pos_dict[n1] except KeyError: # print n1 + ' is not there!!' flag = 1 try: t2 = pos_dict[n2] except KeyError: # print n2 + ' is not there!!' flag = 1 if (flag != 1 and n1.lower() not in stopwords and n2.lower() not in stopwords): score1 = getting_sentiment(n1.lower(),t1) if score1 != 100: score1 = float(score1) * float(m1) score2 = getting_sentiment(n2.lower(),t2) if score2 != 100: score2 = float(score2) * float(m2) if score1 != 100 or score2 != 100: if 'NN' in t1 or 'NN' in t2: if 'JJ' in t1 or 'JJ' in t2: meaning = 1 # print n1 + ' and ' + n2 + ' appear to be meaningful...' elif ('VB' in t1 or 'VB' in t2 or ('NN' in t1 and 'NN' in t2)): # print n1 + ' and ' + n2 + ' appear to be less meaningful...' meaning = 0.8 else: meaning = 0.2 if score1 != 100 and score2 == 100: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) print n1,n2 if score2 != 100 and score1 == 100: print n2,n1 apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) elif score2 != 100 and score1 != 100: if 'NN' in t1 and 'JJ' in t2: # print n1,n2 apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) elif 'JJ' in t1 and 'NN' in t2: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) # print n1,n2 elif 'NN' in t1: apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) # print n1,n2 elif 'NN' in t2: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) # print n1,n2 else: # print 'The scores are not present for ' + n1 + ' and ' + n2 pass # checking for direct object or dependency... if 'dobj' in li[0] or 'dep' in li[0]: n1 = li[1] n2 = li[3] m1, m2 = check_for_negative(n1,n2,li[2],li[4],neg_words) t1 = pos_dict[n1] t2 = pos_dict[n2] score1 = 100 score2 = 100 score1 = getting_sentiment(n1.lower(),t1) if score1 != 100: score1 = float(score1) * float(m1) score2 = getting_sentiment(n2.lower(),t2) if score2 != 100: score2 = float(score2) * float(m2) if score1 != 100 or score2 != 100: if (n1.lower() not in stopwords and n2.lower() not in stopwords): if 'NN' in t1 or 'NN' in t2: if 'JJ' in t1 or 'JJ' in t2: meaning = 1 # print n1,t1 + ' and ' + n2,t2 + ' adjective-noun as direct object...' else: if ('VB' in t1 or 'VB' in t2 or ('NN' in t1 and 'NN' in t2)): meaning = 0.8 # print n1,t1 + ' and ' + n2,t2 + ' as direct object...' else: meaning = 0.2 # print 'no noun occurance' if score2 != 100 and score1 == 100: apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) elif score1 != 100 and score2 == 100: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) elif score1 != 100 and score2 != 100: if 'NN' in t1 and 'JJ' in t2: apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) elif 'JJ' in t1 and 'NN' in t2: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) elif score1 > score2: apply_score(li,n2,score1,final_score,meaning,n1,t2,t1) elif score2 >= score1: apply_score(li,n1,score2,final_score,meaning,n2,t1,t2) else: print '-----------stopwords-----------'
def check_for_noun_adj(depend_dict, pos_dict, final_score, neg_words): # getting the score and stopwords dictionary sd, stopwords = get_dict() flag = 0 stemmer3 = WordNetLemmatizer() for value in depend_dict.values(): for j in range(len(value)): score1 = 100 score2 = 100 li = value[j] if "nsubj" in li[0] or "mod" in li[0]: meaning = 0.2 n1 = li[1] n2 = li[3] m1, m2 = check_for_negative(n1, n2, li[2], li[4], neg_words) try: t1 = pos_dict[n1] except KeyError: # print n1 + ' is not there!!' flag = 1 try: t2 = pos_dict[n2] except KeyError: # print n2 + ' is not there!!' flag = 1 if (flag != 1 and n1.lower() not in stopwords and n2.lower() not in stopwords): score1 = getting_sentiment(n1.lower(), t1) if score1 != 100: score1 = float(score1) * float(m1) score2 = getting_sentiment(n2.lower(), t2) if score2 != 100: score2 = float(score2) * float(m2) if score1 != 100 or score2 != 100: if 'NN' in t1 or 'NN' in t2: if 'JJ' in t1 or 'JJ' in t2: meaning = 1 # print n1 + ' and ' + n2 + ' appear to be meaningful...' elif ('VB' in t1 or 'VB' in t2 or ('NN' in t1 and 'NN' in t2)): # print n1 + ' and ' + n2 + ' appear to be less meaningful...' meaning = 0.8 else: meaning = 0.2 if score1 != 100 and score2 == 100: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) print n1, n2 if score2 != 100 and score1 == 100: print n2, n1 apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) elif score2 != 100 and score1 != 100: if 'NN' in t1 and 'JJ' in t2: # print n1,n2 apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) elif 'JJ' in t1 and 'NN' in t2: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) # print n1,n2 elif 'NN' in t1: apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) # print n1,n2 elif 'NN' in t2: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) # print n1,n2 else: # print 'The scores are not present for ' + n1 + ' and ' + n2 pass # checking for direct object or dependency... if 'dobj' in li[0] or 'dep' in li[0]: n1 = li[1] n2 = li[3] m1, m2 = check_for_negative(n1, n2, li[2], li[4], neg_words) t1 = pos_dict[n1] t2 = pos_dict[n2] score1 = 100 score2 = 100 score1 = getting_sentiment(n1.lower(), t1) if score1 != 100: score1 = float(score1) * float(m1) score2 = getting_sentiment(n2.lower(), t2) if score2 != 100: score2 = float(score2) * float(m2) if score1 != 100 or score2 != 100: if (n1.lower() not in stopwords and n2.lower() not in stopwords): if 'NN' in t1 or 'NN' in t2: if 'JJ' in t1 or 'JJ' in t2: meaning = 1 # print n1,t1 + ' and ' + n2,t2 + ' adjective-noun as direct object...' else: if ('VB' in t1 or 'VB' in t2 or ('NN' in t1 and 'NN' in t2)): meaning = 0.8 # print n1,t1 + ' and ' + n2,t2 + ' as direct object...' else: meaning = 0.2 # print 'no noun occurance' if score2 != 100 and score1 == 100: apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) elif score1 != 100 and score2 == 100: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) elif score1 != 100 and score2 != 100: if 'NN' in t1 and 'JJ' in t2: apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) elif 'JJ' in t1 and 'NN' in t2: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) elif score1 > score2: apply_score(li, n2, score1, final_score, meaning, n1, t2, t1) elif score2 >= score1: apply_score(li, n1, score2, final_score, meaning, n2, t1, t2) else: print '-----------stopwords-----------'
from operator import itemgetter import itertools import collections import dpath.util from classifier import get_lookup_dict,get_trained_classifier,check_in_dic from final_scores import final_scores java_path = "/usr/lib/jvm/java-8-oracle/jre/bin/java" # replace this os.environ['JAVAHOME'] = java_path os.environ['STANFORD_PARSER'] = '/home/farhan/Recommendation-system/stanford-ner-2015-12-09' os.environ['STANFORD_MODELS'] = '/home/farhan/Recommendation-system/stanford-ner-2015-12-09/classifiers' # defining global parameters score_dic,stopwords = get_dict() neg_prefix = ['not','none','nor','n\'t'] # final_score = {} # compound_word_dic = {} # compound_word_list = [] # neg_words = [] # checking for any dish present... # combine compound word def compound_word(li): # print li word = [] st = ''
import itertools import collections import dpath.util from classifier import get_lookup_dict, get_trained_classifier, check_in_dic from final_scores import final_scores java_path = "/usr/lib/jvm/java-8-oracle/jre/bin/java" # replace this os.environ['JAVAHOME'] = java_path os.environ[ 'STANFORD_PARSER'] = '/home/farhan/Recommendation-system/stanford-ner-2015-12-09' os.environ[ 'STANFORD_MODELS'] = '/home/farhan/Recommendation-system/stanford-ner-2015-12-09/classifiers' # defining global parameters score_dic, stopwords = get_dict() neg_prefix = ['not', 'none', 'nor', 'n\'t'] # final_score = {} # compound_word_dic = {} # compound_word_list = [] # neg_words = [] # checking for any dish present... # combine compound word def compound_word(li): # print li word = [] st = ''