UCDP-AEC

Models and data for the UCDP Abstractive Event analysis Corpus paper
git clone https://esimon.eu/repos/UCDP-AEC.git
Log | Files | Refs | README | LICENSE

json2table.py (1104B)


      1 import json
      2 
      3 
      4 MAIN_ORDER = [
      5     "actor accuracy", "date accuracy", "location accuracy", "deaths accuracy", "aggregate accuracy",
      6     "actor semantic p@1", "location semantic p@1",
      7 ]
      8 
      9 
     10 APPENDIX_ORDER = [
     11     "side_a_name accuracy",
     12     "side_b_name accuracy",
     13     "start_date accuracy",
     14     "end_date accuracy",
     15     "location_root_name accuracy",
     16     "location_adm1_name accuracy",
     17     "location_adm2_name accuracy",
     18     "location_where_name accuracy",
     19     "deaths_side_a accuracy",
     20     "deaths_side_b accuracy",
     21     "deaths_civilian accuracy",
     22     "deaths_unknown accuracy",
     23     "deaths_low accuracy",
     24     "deaths_high accuracy",
     25 ]
     26 
     27 
     28 def format_key(results, key):
     29     if "p@1" in key:
     30         return f"{100*results[key]:.1f}"
     31     else:
     32         return f"{results[key]:.1f}"
     33 
     34 
     35 def main() -> None:
     36     results = json.loads(input())
     37     main = " & ".join(format_key(results, key) for key in MAIN_ORDER)
     38     appendix = " & ".join(format_key(results, key) for key in APPENDIX_ORDER)
     39     print(f"MAIN TABLE & {main} \\\\")
     40     print(f"APPENDIX TABLE & {appendix} \\\\")
     41 
     42 
     43 if __name__ == "__main__":
     44     main()