Reads annotations from a file in either the gold or predicted format. Args: diffqg_fi: Path to the input file. Returns: Dictionary mapping a unique string identifier of the annotation to an Annotation object.
(diffqg_fi: str)
| 90 | |
| 91 | |
| 92 | def _read_annotations(diffqg_fi: str) -> Dict[str, Annotation]: |
| 93 | """Reads annotations from a file in either the gold or predicted format. |
| 94 | |
| 95 | Args: |
| 96 | diffqg_fi: Path to the input file. |
| 97 | |
| 98 | Returns: |
| 99 | Dictionary mapping a unique string identifier of the annotation to an |
| 100 | Annotation object. |
| 101 | """ |
| 102 | with open(diffqg_fi, "rt") as fr: |
| 103 | json_dics = [json.loads(s) for s in fr.readlines()] |
| 104 | print(f"Read {len(json_dics)} jsons from {diffqg_fi}") |
| 105 | overall_dic = {} |
| 106 | |
| 107 | for json_dic in json_dics: |
| 108 | anno = Annotation(json_dic) |
| 109 | key = anno.key_annotation() |
| 110 | if key in overall_dic: |
| 111 | print(f"Possible repeated annotation for {key}") |
| 112 | if anno.question != overall_dic[key].question: |
| 113 | print("Error! Different questions.") |
| 114 | print(f"--\n{anno.question}\n{overall_dic[key].question}\n--") |
| 115 | overall_dic[key] = anno |
| 116 | |
| 117 | return overall_dic |
| 118 | |
| 119 | |
| 120 | def make_paired_annotations( |
no test coverage detected
searching dependent graphs…