(string, entity_id, head_relations)
| 63 | |
| 64 | |
| 65 | def 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 | |
| 88 | def if_all_zero(topn_scores): |
nothing calls this directly
no outgoing calls
no test coverage detected