TEXT to AMR to RDF/OWL translator.
Project description
py_amr2fred
From Text to Abstract Meaning Representation to RDF/OWL Knowledge Graph
Python library version of Text2AMR2FRED incorporating the core functions of amr2fred. It enables seamless transformation of natural language text into RDF/OWL Knowledge Graphs through Abstract Meaning Representation (AMR), according to FRED's formal semantics and ontology design patterns.
Install:
pip install py_amr2fred
Use:
import os
from pathlib import Path
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)
Amr2fred class parameters:
Parameter [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.
Parameter [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:
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 (default)
Parameter [multilingual]
- [True] the library will use multilingual API
- [False] the library will use "English only" API (default)
Parameter [graphic]
- [svg] return a svg string
- [png] returns a png tmp_file
Parameter [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.
!!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.
For full documentation, visit: Read the Docs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_amr2fred-0.5.0.tar.gz.
File metadata
- Download URL: py_amr2fred-0.5.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56300ebbc81570bc7bfb13892e340faf95cd65c33fbadd831e7e5058e7a9b017
|
|
| MD5 |
3fae8a9d09b7337f6b7424acac616c8d
|
|
| BLAKE2b-256 |
2740f1c6a9d7c71baef9cb97edf2be9aad621211b5ffd094474cea55bc74c631
|
File details
Details for the file py_amr2fred-0.5.0-py3-none-any.whl.
File metadata
- Download URL: py_amr2fred-0.5.0-py3-none-any.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3805114a1cdf2883f1e391d4509eabbc54e526375105f9cba0571862dec40562
|
|
| MD5 |
0ded712da76fc8d8634865d68a01f550
|
|
| BLAKE2b-256 |
f66624590b5e464308ee061cea73292099385448891960f70ff4823a0f5d59a0
|