def get_name_by_mid(): mid = request.args.get('mid').strip() print "[get_name_by_mid]", mid name, name_info = DBManager.get_name(mid) print name, name_info aliases, alias_info = DBManager.get_alias(mid) res = { 'name': name if name else name_info, 'alias': '<br>'.join(aliases) if aliases else alias_info } return json.dumps(res)
def get_subgraph(): mid = request.args.get('mid').strip() print '[get_subgraph]', mid subgraph = self.freebase.client.get_subgraph(mid) print "subgraph", subgraph links = [] nodes_ = {} for path in subgraph: if len(path) == 1: p1 = path[0] if p1[0] not in nodes_: nodes_[p1[0]] = { 'category': 0, 'name': p1[0], 'value': 10 } if p1[2] not in nodes_: nodes_[p1[2]] = { 'category': 2, 'name': p1[2], 'value': 4 } else: p1 = path[0] if p1[0] not in nodes_: nodes_[p1[0]] = { 'category': 0, 'name': p1[0], 'value': 10 } if p1[2] not in nodes_: nodes_[p1[2]] = { 'category': 1, 'name': p1[2], 'value': 4 } p2 = path[1] if p2[2] not in nodes_: nodes_[p2[2]] = { 'category': 2, 'name': p2[2], 'value': 4 } for m in nodes_.keys(): name, name_info = DBManager.get_name(m) nodes_[m]['label'] = name nodes = nodes_.values() for path in subgraph: if len(path) == 1: t = path[0] links.append({ 'source': nodes_[t[0]]['name'], 'target': nodes_[t[2]]['name'], 'weight': 2, 'name': t[1] }) else: t = path[0] links.append({ 'source': nodes_[t[0]]['name'], 'target': nodes_[t[2]]['name'], 'weight': 2, 'name': t[1] }) t = path[1] links.append({ 'source': nodes_[t[0]]['name'], 'target': nodes_[t[2]]['name'], 'weight': 2, 'name': t[1] }) print 'node', nodes print 'links', links return json.dumps({'nodes': nodes, 'links': links})