amr2fred module

class py_amr2fred.amr2fred.Amr2fred(txt2amr_uri: str = None, m_txt2amr_uri: str = None)

Bases: object

A class for transforming AMR (Abstract Meaning Representation) into RDF (Resource Description Framework) representations compliant with OWL ontologies.

Parameters:
  • txt2amr_uri – Custom URI for the text-to-AMR service.

  • m_txt2amr_uri – Custom URI for the multilingual text-to-AMR service.

get_amr(text: str, alt_api: bool, multilingual: bool) str | None

Retrieves the AMR representation of the given text using the appropriate API. :param text: Input text to convert into AMR. :param alt_api: Whether to use the predefined alternative API or a custom one provided during class instantiation. :param multilingual: Whether to use the multilingual text-to-AMR service. :return: The AMR representation as a string.

translate(amr: str | None = None, mode: RdflibMode = RdflibMode.NT, serialize: bool = True, text: str | None = None, alt_api: bool = False, multilingual: bool = False, graphic: str | None = None, post_processing: bool = True, alt_fred_ns: str | None = None) str | Graph | IO

Transforms an AMR representation or input text into an RDF graph or serialized format.

Parameters:
  • amr – The AMR graph representation as a string.

  • mode – The serialization format for RDF output (e.g., NT, TTL, RDF/XML).

  • serialize – Whether to return the serialized RDF graph.

  • text – The input text to be converted into AMR if amr is not provided.

  • alt_api – Whether to use an alternative text-to-AMR API.

  • multilingual – Whether to use the multilingual text-to-AMR service.

  • graphic – If specified, returns a graphical representation (‘png’ or ‘svg’).

  • post_processing – Whether to apply post-processing to enhance the RDF graph.

  • alt_fred_ns – Alternative namespace for FRED RDF generation.

Returns:

Serialized RDF graph, RDFLib Graph object, or graphical representation.

Amr2fred class parameters

txt2amr_uri

Specifies the API URI of an alternative Spring-based “txt2amr” translator. This parameter is optional and only required if users wish to override the default resource. It should be used in conjunction with the alt_api parameter of the translate method.

m_txt2amr_uri

Specifies the API URI of an alternative multilingual USeA-based “txt2amr” translator. This parameter is optional and only required if users wish to override the default multilingual resource. It should be used in conjunction with the multilingual parameter of the translate method.

translate method parameters

amr

AMR string in Penman format.

serialize
  • True returns a string.

  • False returns an rdflib Graph.

mode
  • Glossary.RdflibMode.TURTLE

  • Glossary.RdflibMode.NT

  • Glossary.RdflibMode.XML

  • Glossary.RdflibMode.N3

  • Glossary.RdflibMode.JSON_LD

alt_fred_ns

Alternate URI for base Fred namespace.

text

Natural Language text to translate.

alt_api
  • True: The library will use the alternative API.

  • False: The library will use the default API (default).

multilingual
  • True: The library will use the multilingual API.

  • False: The library will use the “English only” API (default).

graphic
  • svg: Returns an SVG string.

  • png: Returns a PNG temporary file.

post_processing
  • True: Perform WSD and KG enrichment (default).

  • False: Do not perform WSD and KG enrichment.

The post-processing feature requires a database file for mapping Wikipedia IDs to WikiData IDs. The system will automatically download the required file (index_enwiki-latest.db, ~1815 MB uncompressed, ~832 MB compressed) during its first run. Ensure you have sufficient disk space and a stable internet connection before running the system for the first time.

get_amr method parameters

text

Input text to convert into AMR.

alt_api
  • True: Uses the predefined alternative API or a custom one provided during class instantiation.

  • False: Uses the default API.

multilingual
  • True: Uses the multilingual text-to-AMR service.

  • False: Uses the default English-only text-to-AMR service.

!! Attention !!

  • In order to generate graphical output (such as PNG or SVG files), you must have Graphviz installed on your system. You can download and install it from Graphviz’s Official Website. If Graphviz is not installed, the library will return a String containing the graph translated into the .dot graphic language instead of generating the PNG or SVG graphical output.

  • When a PNG file is generated, the temporary file will not be automatically deleted. You need to manually manage or delete the file after using it.