#!/usr/bin/env python
#encoding=utf-8
import redis,codecs,sys
reload(sys)
sys.setdefaultencoding('utf-8')
class Unbuffered:
def __init__(self, stream):
self.stream = stream
def write(self, data):
self.stream.write(data)
self.stream.flush()
def __getattr__(self, attr):
return getattr(self.stream, attr)
r=redis.Redis(host='localhost',db=6)
sys.stdout = Unbuffered(sys.stdout)
keys=r.keys()
print len(keys)
def read_keys():
f=codecs.open("query_keys.txt","w","utf-8")
#print r.info()
for key in keys:
print key
#print type(key)
f.write("%s\n"%(key,))
f.close()
def read_relevent_words():
f=codecs.open("query_relevent_words.txt","w","utf-8")
for key in keys:
# print r.get(key)
f.write("%s\n"%(r.get(key),))
f.close()
def parser_one_line_one_words():
ff=codecs.open("parser_one_line_one_words.txt","w","utf-8")
f=codecs.open("query_relevent_words.txt","r","utf-8")
for line in f.readlines():
li=line.strip().split("*")
for elem in li:
ff.write("%s\n"%(elem,))
ff.close()
def parser_one_line_one_words2():
s=set()
ff=codecs.open("parser_one_line_one_words.txt","w","utf-8")
f=codecs.open("query_relevent_words.txt","r","utf-8")
for line in f.readlines():
li=line.strip().split("*")
for elem in li:
s.add(elem.strip())
ff.write("%s\n"%(elem,))
ff.close()
print len(s)
if __name__=="__main__":
# read_relevent_words()
parser_one_line_one_words2()