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

Function clean_relations

ToG/wiki_func.py:13–34  ·  view source on GitHub ↗
(string, entity_id, head_relations)

Source from the content-addressed store, hash-verified

11
12
13def clean_relations(string, entity_id, head_relations):
14 pattern = r"{\s*(?P<relation>[^()]+)\s+\(Score:\s+(?P<score>[0-9.]+)\)}"
15 relations=[]
16 for match in re.finditer(pattern, string):
17 relation = match.group("relation").strip()
18 relation = transform_relation(relation)
19 if ';' in relation:
20 continue
21 score = match.group("score")
22 if not relation or not score:
23 return False, "output uncompleted.."
24 try:
25 score = float(score)
26 except ValueError:
27 return False, "Invalid score"
28 if relation in head_relations:
29 relations.append({"entity": entity_id, "relation": relation, "score": score, "head": True})
30 else:
31 relations.append({"entity": entity_id, "relation": relation, "score": score, "head": False})
32 if not relations:
33 return False, "No relations found"
34 return True, relations
35
36
37def construct_relation_prune_prompt(question, entity_name, total_relations, args):

Callers 1

relation_search_pruneFunction · 0.70

Calls 1

transform_relationFunction · 0.85

Tested by

no test coverage detected