<filename>process.py<gh_stars>0
from redis import StrictRedis
from tqdm import tqdm
from fuzzywuzzy import process

print("init db")
db = StrictRedis(host='localhost', port=6379, db=0)


def read_wiki(path):
    db.flushall()
    with open(path) as f:
        for line in tqdm(f):
            mid, name, text = line.split("\t")
            db.rpush(mid+"###name", name.strip())
            db.rpush(mid+"###text", text.strip())
            db.rpush("mid", mid.strip())


def read_graph(path):
    rel_dict = {}
    with open(path) as f:
        for line in f:
            e1, r, e2 = line.strip().split("\t")
            rel_dict[e1+"###"+e2] = r


def read_path_data(path):
    graph = {}
    reverse_graph = {}
    with open(path) as f:
        for line in tqdm(f):
            e1, e2, r = line.strip().split("\t")
            graph[e1+"#"+e2] = r
            reverse_graph[e2+"#"+e1] = r
    return graph, reverse_graph


read_wiki("id_name_text.txt")

<filename>process.py<gh_stars>0
from redis import StrictRedis
from tqdm import tqdm
from fuzzywuzzy import process

print("init db")
db = StrictRedis(host='localhost', port=6379, db=0)


def read_wiki(path):
    db.flushall()
    with open(path) as f:
        for line in tqdm(f):
            mid, name, text = line.split("\t")
            db.rpush(mid+"###name", name.strip())
            db.rpush(mid+"###text", text.strip())
            db.rpush("mid", mid.strip())


def read_graph(path):
    rel_dict = {}
    with open(path) as f:
        for line in f:
            e1, r, e2 = line.strip().split("\t")
            rel_dict[e1+"###"+e2] = r


def read_path_data(path):
    graph = {}
    reverse_graph = {}
    with open(path) as f:
        for line in tqdm(f):
            e1, e2, r = line.strip().split("\t")
            graph[e1+"#"+e2] = r
            reverse_graph[e2+"#"+e1] = r
    return graph, reverse_graph


read_wiki("id_name_text.txt")

##name", name.strip()) ##text", text.strip()) ##"+e2] = r