Skip to content

AMR Reader class

Austin Blodgett edited this page Feb 10, 2021 · 3 revisions

AMR_Reader supports loading AMRs from a variety of different formats

from amr_utils.amr_readers import AMR_Reader

reader = AMR_Reader()
amrs = reader.load(amr_file, remove_wiki=True)
reader = AMR_Reader()
amrs, alignments = reader.load(amr_file, remove_wiki=True, output_alignments=True)
reader = AMR_Reader()
amrs, alignments = reader.load_from_dir(amr_dir, remove_wiki=True, output_alignments=True)

Note that alignments is a dictionary mapping AMR ids to lists of AMR_Alignment objects, which can easily be stored as or read from JSON.

AMR_Reader takes a parameter

  • style can take values 'isi', 'jamr', or 'letters' (default is 'isi') to set the style of node ids. See the wiki on input formats for further details.

The main usages supported are

  • reader.load(amr_file, remove_wiki=False, output_alignments=False) loads AMRs from a file, optionally removing wiki information and optionally returning alignments if the AMR file includes alignment data.
  • reader.load_from_dir(amr_dir, remove_wiki=False, output_alignments=False) loads AMRs from all .txt files in a directory, optionally removing wiki information and optionally returning alignments if the AMR files include alignment data.
  • reader.load_alignments_from_json(align_file) loads alignments stored as a JSON file.
  • reader.save_alignments_to_json(align_file, alignments) saves alignments as a JSON file.
  • reader.write_to_file(output_file, amrs) writes AMRs to a .txt file with graph metadata.
Clone this wiki locally