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

Function clean_relations

ToG/utils.py:65–85  ·  view source on GitHub ↗
(string, entity_id, head_relations)

Source from the content-addressed store, hash-verified

63
64
65def clean_relations(string, entity_id, head_relations):
66 pattern = r"{\s*(?P<relation>[^()]+)\s+\(Score:\s+(?P<score>[0-9.]+)\)}"
67 relations=[]
68 for match in re.finditer(pattern, string):
69 relation = match.group("relation").strip()
70 if ';' in relation:
71 continue
72 score = match.group("score")
73 if not relation or not score:
74 return False, "output uncompleted.."
75 try:
76 score = float(score)
77 except ValueError:
78 return False, "Invalid score"
79 if relation in head_relations:
80 relations.append({"entity": entity_id, "relation": relation, "score": score, "head": True})
81 else:
82 relations.append({"entity": entity_id, "relation": relation, "score": score, "head": False})
83 if not relations:
84 return False, "No relations found"
85 return True, relations
86
87
88def if_all_zero(topn_scores):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected