Skip to main content

AMR to RDF translator.

Project description

py_amr2fred

From Abstract Meaning Representation AMR (https://amr.isi.edu/) to RDF, according to the syntax of FRED (http://wit.istc.cnr.it/stlab-tools/fred/)

Python version of amr2fred's core functions

Install:

pip install py_amr2fred

Use:

from py_amr2fred import *
amr2fred = Amr2fred()
mode = Glossary.RdflibMode.N3
amr_text = """
    (c / charge-05 :ARG1 (h / he) :ARG2 (a / and :op1 (i / intoxicate-01 :ARG1 h 
	:location (p / public)) :op2 (r / resist-01 :ARG0 h 
	:ARG1 (a2 / arrest-01 :ARG1 h))))
"""
# translate from AMR
print(amr2fred.translate(amr_text, serialize=True, mode=mode))

# translate from natural language
mode = Glossary.RdflibMode.TURTLE
print(amr2fred.translate(text="Four boys making pies", serialize=True, mode=mode))

# multilingual
print(amr2fred.translate(text="Quattro ragazzi preparano torte", 
                         serialize=True, 
                         mode=Glossary.RdflibMode.TURTLE,  
                         multilingual=True))

# PNG image output !!Attention!! Graphviz must be installed! The temporary file will not be automatically deleted
png_file = amr2fred.translate(text="Four boys making pies", graphic="png")

save_path = "output_image.png"
with open(save_path, 'wb') as f:
    f.write(png_file.read())
png_file.close()
os.remove(Path(png_file.name))

# SVG image output !!Attention!! Graphviz must be installed!
svg = amr2fred.translate(text="Four boys making pies", graphic="svg")

save_path = "output_image.svg"
with open(save_path, 'w') as f:
    f.write(svg)      

Parameter [amr]:

amr string in penman format

Parameter [serialize]:

  • [True] returns a string
  • [False] returns a rdflib Graph

Parameter [mode]:

  • Glossary.RdflibMode.TURTLE
  • Glossary.RdflibMode.NT
  • Glossary.RdflibMode.XML
  • Glossary.RdflibMode.N3
  • Glossary.RdflibMode.JSON_LD

Parameter [alt_fred_ns]:

Alternate Uri for base Fred NS

Parameter [text]

NL text to translate

Parameter [alt_api]

  • [True] the library will use alt. API
  • [False] the library will use default API

Parameter [multilingual]

  • [True] the library will use multilingual API
  • [False] the library will use "English only" API

Parameter [graphic]

  • [svg] return a svg string
  • [png] returns a png tmp_file

!!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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_amr2fred-0.1.4.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

py_amr2fred-0.1.4-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file py_amr2fred-0.1.4.tar.gz.

File metadata

  • Download URL: py_amr2fred-0.1.4.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for py_amr2fred-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e2360d601df434948a41d470c887d7d3c128c4625a7dafe40dc992679e0bee9f
MD5 f9017757978fcefb3b949b144a3af4ed
BLAKE2b-256 d67b110dca7c30efb8f773bd47e623f0e268c00ee35fa847b39526f63c18f539

See more details on using hashes here.

File details

Details for the file py_amr2fred-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: py_amr2fred-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for py_amr2fred-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b86158ba090c9f4542e3bb1da6492418174e0a1728ec9d9897f23706990b206b
MD5 661f1b96924be9004be3e6cdcc0fcf86
BLAKE2b-256 d3e26472da231b694a859ced598992a4e7c237c17fc46bf387837712ccf13abe

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page