def load(self): tree_json = loadJson(tree_path) for _id in tree_json: node_data = tree_json[_id] node = self.get(_id) node.parent = self.get(node_data['parent']) node.childs = [ self.get(child_id) for child_id in node_data['childs'] ] node.child_num = node_data['child_num'] if node.parent is None: self.root_node = node
def load(self): tree_json = loadJson(cat_tree_path) for _id in tree_json: node_data = tree_json[_id] node = self.get(_id) node.parent = self.get(node_data['parent']) node.childs = [self.get(n_id) for n_id in node_data['childs']] # if node.parent is not None: # node.parent.childs.append(node) node.potery_ids = node_data['potery_ids'] node.is_leave = len(node.potery_ids) > 0 if node.parent is None: self.root_node = node
def loads(self): files = os.listdir(poem_dir) #列出文件夹下所有的目录与文件 count = 0 for file in files: path = os.path.join(poem_dir, file) if os.path.isfile(path): file = loadJson(path) for potery_id in file: file[potery_id]['id'] = +potery_id self.createPotery(file[potery_id]) count += 1 if count % 100000 == 0: print(count) self.poteries = sorted(self.poteries, key=lambda potery: potery.id) print('加载完成')
def getImpIds(num=10000): global imp_ids if imp_ids is not None: return list(imp_ids) ids = getAllIds() potery_rank = loadJson(potery_rank_path) def getRank(_id): if _id in potery_rank: return potery_rank[_id] else: return -999 ids = sorted(ids, key=lambda _id: getRank(_id), reverse=True) imp_ids = ids[0:num] return list(imp_ids)
if node.parent is None: self.root_node = node def getNodeAtLevel(self, level): nodes = [self.root_node] for index in range(level): children = [] for node in nodes: children += node.childs nodes = children return nodes imp_ids = getImpIds(imp_ids_num) cat2poteries = loadJson(cat_path) nodeCompany = NodeCompany() nodeCompany.load() # test = nodeCompany.get(831) # print(test.id) # print(test.parent.id) # print(test.vec3d, test.getChildIds()) # print(len(nodeCompany.root_node.getAllPoteries()), len(getAllIds())) def getCenterVec(vecs): vecs = np.array(vecs) # size = len(vecs[0].tolist())
import json import os import copy from commonFunction import writeJson, loadJson poem_dir = './data/poem/' potery_rank_path = './data/potery_rank.json' p_id2rank = loadJson(potery_rank_path) class Comments: def __init__(self, json_object, sentence): # print(json_object['Content']) try: self.content = json.loads(json_object['Content']) except: self.content = json_object['Content'] self.index = json_object['Index'] self.Type = json_object["Type"] #WordDictInJson是json以外其他全是text self.sentence = sentence class Author: def __init__(self, author_name): self.name = author_name class Sentence: def __init__(self, json_object, potery, index): if 'Content' in json_object: