def group_same(aspects): for i in range(0, len(aspects)): print i aspects[i][0] = aspects[i][0].strip("#@") token = aspects[i][0].rstrip("'s") j = 0 nf = True while j < i and nf: if token.lower() in aspects[j][0].lower(): print("entered 1") aspects[j][1] = aspects[j][1] + aspects[i][1] aspects[i][1] = 0 nf = False elif aspects[j][0].lower() in token.lower(): print("entered 1") aspects[j][0] = token aspects[j][1] = aspects[j][1] + aspects[i][1] aspects[i][1] = 0 nf = False else: j = j + 1 aspects = sorted(aspects, key=lambda x: int(x[1]), reverse=True) aspects = util.filter_rlist(aspects, 1, 1) print aspects return aspects
def group_same(aspects) : for i in range(0,len(aspects)) : print i aspects[i][0]=aspects[i][0].strip("#@") token=aspects[i][0].rstrip("'s") j=0 nf=True while j<i and nf : if token.lower() in aspects[j][0].lower() : print("entered 1") aspects[j][1]=aspects[j][1]+aspects[i][1] aspects[i][1]=0 nf=False elif aspects[j][0].lower() in token.lower() : print("entered 1") aspects[j][0]=token aspects[j][1]=aspects[j][1]+aspects[i][1] aspects[i][1]=0 nf=False else : j=j+1 aspects=sorted(aspects,key=lambda x: int(x[1]),reverse=True) aspects=util.filter_rlist(aspects,1,1) print aspects return aspects
def GreedyAspectRanking(outfile,tweets,topic,k) : pos_tweets=tagger.runtagger_parse(tweets) aspects_tweet=get_aspect(pos_tweets) # tweetwise aspects [[asp1,asp2],[],[asp1]] """ aspect_freq=ranking.get_freq(aspects_tweet) aspect_freq=sorted(aspect_freq,key=lambda x: int(x[1]),reverse=True) aspect_freq=error.correct(aspect_freq) aspects_sel=util.filter_rlist(aspect_freq,10,1) util.listTocsv(outfile1,aspects_sel) aspects=util.listfromlist(aspects_sel,0) #aspect_hits=ranking.pmi_list(aspects,topic,"results/pmi_"+topic+".csv") """ aspect_hits=util.csvTolist("results/pmi_"+topic+".csv") aspect_hits=sorted(aspect_hits,key=lambda x: float(x[1]),reverse=True) #util.listTocsv(outfile,aspect_hits) asp_hits=util.filter_rlist(aspect_hits,6,1) aspects1=util.listfromlist(asp_hits,0) results=algo.GreedyNormal(outfile,aspects_tweet,aspects1,tweets,k) return results
def GreedyAspectRanking(outfile, tweets, topic, k): pos_tweets = tagger.runtagger_parse(tweets) aspects_tweet = get_aspect( pos_tweets) # tweetwise aspects [[asp1,asp2],[],[asp1]] """ aspect_freq=ranking.get_freq(aspects_tweet) aspect_freq=sorted(aspect_freq,key=lambda x: int(x[1]),reverse=True) aspect_freq=error.correct(aspect_freq) aspects_sel=util.filter_rlist(aspect_freq,10,1) util.listTocsv(outfile1,aspects_sel) aspects=util.listfromlist(aspects_sel,0) #aspect_hits=ranking.pmi_list(aspects,topic,"results/pmi_"+topic+".csv") """ aspect_hits = util.csvTolist("results/pmi_" + topic + ".csv") aspect_hits = sorted(aspect_hits, key=lambda x: float(x[1]), reverse=True) #util.listTocsv(outfile,aspect_hits) asp_hits = util.filter_rlist(aspect_hits, 6, 1) aspects1 = util.listfromlist(asp_hits, 0) results = algo.GreedyNormal(outfile, aspects_tweet, aspects1, tweets, k) return results