MCPcopy Create free account
hub / github.com/DataArcTech/ToG / entity_prune

Function entity_prune

ToG/wiki_func.py:178–191  ·  view source on GitHub ↗
(total_entities_id, total_relations, total_candidates, total_topic_entities, total_head, total_scores, args, wiki_client)

Source from the content-addressed store, hash-verified

176
177
178def entity_prune(total_entities_id, total_relations, total_candidates, total_topic_entities, total_head, total_scores, args, wiki_client):
179 zipped = list(zip(total_entities_id, total_relations, total_candidates, total_topic_entities, total_head, total_scores))
180 sorted_zipped = sorted(zipped, key=lambda x: x[5], reverse=True)
181 sorted_entities_id, sorted_relations, sorted_candidates, sorted_topic_entities, sorted_head, sorted_scores = [x[0] for x in sorted_zipped], [x[1] for x in sorted_zipped], [x[2] for x in sorted_zipped], [x[3] for x in sorted_zipped], [x[4] for x in sorted_zipped], [x[5] for x in sorted_zipped]
182
183 entities_id, relations, candidates, topics, heads, scores = sorted_entities_id[:args.width], sorted_relations[:args.width], sorted_candidates[:args.width], sorted_topic_entities[:args.width], sorted_head[:args.width], sorted_scores[:args.width]
184 merged_list = list(zip(entities_id, relations, candidates, topics, heads, scores))
185 filtered_list = [(id, rel, ent, top, hea, score) for id, rel, ent, top, hea, score in merged_list if score != 0]
186 if len(filtered_list) ==0:
187 return False, [], [], [], []
188 entities_id, relations, candidates, tops, heads, scores = map(list, zip(*filtered_list))
189 tops = [wiki_client.query_all("qid2label", entity_id).pop() if (entity_name := wiki_client.query_all("qid2label", entity_id)) != "Not Found!" else "Unname_Entity" for entity_id in tops]
190 cluster_chain_of_entities = [[(tops[i], relations[i], candidates[i]) for i in range(len(candidates))]]
191 return True, cluster_chain_of_entities, entities_id, relations, heads
192
193
194def reasoning(question, cluster_chain_of_entities, args):

Callers 2

main_freebase.pyFile · 0.70
main_wiki.pyFile · 0.70

Calls 1

query_allMethod · 0.45

Tested by

no test coverage detected