def build_tweet(mention, grade): print grade seeds = [] mentions = [] mentions1 = [] for m in api.morphs(api.sentences(r['text'])['sentences'][0])['morphs']: mentions1.append(to_chainform(m).split(':')[0]) r_now = ' '.join(mentions1)[4:-4] SV = w2v_dialog.sentence_vectorizer('matrix25.w7.model') w2v_list = SV.use_database('NTCIR.wakati.u20', r_now.encode('utf-8')) seeds.append(''.join(w2v_list[0].split())) seeds.append(''.join(w2v_list[1].split())) seeds.append(''.join(w2v_list[2].split())) #print r['text'] print "w2v_list", '\n'.join(w2v_list) #api.send_reply(name, r['mention_id'], r['user_name'], ''.join(w2v_list[0].split())) for sent in api.sentences(mention)['sentences']: for m in api.morphs(sent)['morphs']: mentions.append(to_chainform(m)) if m['pos'][-2] == u'名' and m['pos'] != u'代名詞' : #print m seeds.append(m) #print seeds texts = [] for _ in range(0, 5): if not seeds: seeds = [{ u'norm_surface': u'BOS', u'pos': u'BOS' }] for s in seeds: pass #print s[u'norm_surface'] #c = api.markov_chain(s) #texts.append(to_string(api.rewrite(c, grade))) print " ".join(mentions) trigger_result = api.trigger(mentions, grade) texts += trigger_result texts += trigger_result texts += trigger_result print '\n'.join(trigger_result) for s in seeds: pass #print api.search_tweet(s[u'norm_surface']) #for t in api.search_tweet(s[u'norm_surface'])[u'texts']: # for sent in api.sentences(t)['sentences']: # texts.append(to_string(api.rewrite([to_chainform(m) for m in api.morphs(sent)['morphs']], grade))) # #print to_string(api.rewrite([to_chainform(m) for m in api.morphs(sent)['morphs']])) #for t in api.search_reply(s[u'norm_surface'])[u'texts']: # for sent in api.sentences(t)['sentences']: # texts.append(to_string(api.rewrite([to_chainform(m) for m in api.morphs(sent)['morphs']], grade))) #print to_string(api.rewrite([to_chainform(m) for m in api.morphs(sent)['morphs']])) texts = seeds random.shuffle(texts) print texts[0] return texts[0]
#!/usr/bin/python # coding:utf-8 from api import API import w2v_dialog import MeCab from crontab import CronTab with API() as api: # ツイートする # api.tweet('tweet test2') SV = w2v_dialog.sentence_vectorizer('/work/asakura/bot/matrix50.model') # リプを取得 for mention in api.get_mentions(): text = mention['text'] tweet_id = mention['id_str'] screen_name = mention['user']['screen_name'] # ユーザ情報(プロフィール) name = mention['user']['name'] zone = mention['user']['time_zone'] location = mention['user']['location'] description = mention['user']['description'] print mention #print text, tweet_id, screen_name, name, zone, location, description tagger = MeCab.Tagger('-Owakati') #result = tagger.parse(' '.join(text.split()[1:]).decode('utf-8')) result = tagger.parse(' '.join(text.split()[1:]).encode('utf-8'))