(string, entity_id, head_relations)
| 11 | |
| 12 | |
| 13 | def 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 | |
| 37 | def construct_relation_prune_prompt(question, entity_name, total_relations, args): |
no test coverage detected