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