MCPcopy Create free account
hub / github.com/google-research/language / _read_annotations

Function _read_annotations

language/diffqg/annotation.py:92–117  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

90
91
92def _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
120def make_paired_annotations(

Callers 1

make_paired_annotationsFunction · 0.85

Calls 2

key_annotationMethod · 0.95
AnnotationClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…