Пример #1
0
    def test_save_and_load(self):
        indexer = Indexer()
        indexer.add("1", ["今日", "天気", "晴れ", "今日"])
        indexer.add("2", ["今日", "天気", "雨"])

        indexer.save("./tests/index.pkl")
        indexer.load("./tests/index.pkl")

        tweet_ids = indexer.search("今日")
        eq_(tweet_ids[0][0], "1")
        eq_(tweet_ids[0][1], 2)
        eq_(tweet_ids[1][0], "2")
        eq_(tweet_ids[1][1], 1)

        tweet_ids = indexer.search("雨")
        eq_(len(tweet_ids), 1)
        eq_(tweet_ids[0][0], "2")
Пример #2
0
from subnetwork import SubNetwork
from index import Indexer
from six.moves import cPickle
from sqltostc import all_tweets
import sqlconfig


net = SubNetwork()
print "load tweet pairs....."
with open('tweet_dic.pkl', 'r') as f:
    source_dic = cPickle.load(f)
net.set_source(source_dic)
print "Tweet Pairs loaded: len(pairs) -> " + str(len(source_dic))
print "load index....."
indexer = Indexer()
indexer.load("./index.pkl")
print "Index loaded"
print "word count / tweet dic....."
with open('./word_count.pkl', 'r') as f:
    wc_dic = cPickle.load(f)
print "dic loaded"


def retrieve_replies(input):
  text = input
  noun_list = md.noun_list(text)

  net.gen_sub_network(noun_list)
  queries = net.page_rank()
  
  results = {}