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

Function entity_search

ToG/wiki_func.py:103–124  ·  view source on GitHub ↗
(entity, relation, wiki_client, head)

Source from the content-addressed store, hash-verified

101
102
103def entity_search(entity, relation, wiki_client, head):
104 rid = wiki_client.query_all("label2pid", relation)
105 if not rid or rid == "Not Found!":
106 return [], []
107
108 rid_str = rid.pop()
109
110 entities = wiki_client.query_all("get_tail_entities_given_head_and_relation", entity, rid_str)
111
112 if head:
113 entities_set = entities['tail']
114 else:
115 entities_set = entities['head']
116
117 if not entities_set:
118 values = wiki_client.query_all("get_tail_values_given_head_and_relation", entity, rid_str)
119 return [], list(values)
120
121 id_list = [item['qid'] for item in entities_set]
122 name_list = [item['label'] if item['label'] != "N/A" else "Unname_Entity" for item in entities_set]
123
124 return id_list, name_list
125
126
127def entity_score(question, entity_candidates_id, entity_candidates, score, relation, 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