diff --git a/.gitignore b/.gitignore index 954ce3850f30395b1289dd03afef33ae2650f06a..2e4487884c789aae4b71746b0f4535160c1faf0f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ *.todo *.ttl.tbc *catalog-v001.xml +venv/* diff --git a/README.md b/README.md index ad601ef43e885bd5efaaf549750d2d474f074e2d..5fc94690d20a90e878b7aa5df0e2b76e944629a4 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,48 @@ AMR Batch is a python library to parse natural language sentences in order to bu This library is currently under development, and therefore in unstable state. -## Environment Setup -The python code has been tested under Python 3.7 and Linux Manjaro, but should be run on most common systems (Linux, Windows, Mac). + +### Installation +This project was developp under Python 3.7 and Manjaro Linux system, but should be run on most common systems (Linux, Windows, Mac). All dependencies are listed in requirements.txt. +First, it is recommended to use a [virtual environment](https://docs.python.org/fr/3/tutorial/venv.html). +For example, 'venv' can be create and use with the following commands: + + python3 -m venv venv + + source venv/bin/activate + +The necessary libraries are defined in the file 'requirements.txt', and can be installed in the virtual environment using package installer as pip: + + pip install -r requirements.txt + +See specific installation instructions about amrlib +([amrlib-install](https://amrlib.readthedocs.io/en/latest/install/)). + +So, it is necessary to install the models used by amrlib library. +Models can be downloaded from +[amrlib-models](https://github.com/bjascob/amrlib-models). + +These files need to be extracted and reside in a directory. The path to this directory can then be passed as a parameter of the main method. The model STOG 'xfm_bart_large-v0_1_0' (from source dir 'amrbatch/models/') is used by default if no model is given. + + ## Usage The script **test_amrbatch_main.py** (test directory) gives an example of using the library. +# References +------------------------------------------------------------------------------- + +[amrlib](https://github.com/bjascob/amrlib): +A python library that makes AMR parsing, generation and visualization simple. + + +[amr-ld](https://github.com/BMKEG/amr-ld/): +A Python library for mapping AMRs to linked data formats (such as RDF and JSON-LD). + +Burns, G.A., Hermjakob, U., Ambite, J.L. (2016). +Abstract Meaning Representations as Linked Data. +In: , et al. The Semantic Web – ISWC 2016. ISWC 2016. +Lecture Notes in Computer Science(), vol 9982. Springer, Cham. +https://doi.org/10.1007/978-3-319-46547-0_2 diff --git a/amrbatch/amrld/.gitignore b/amrbatch/amrld/.gitignore deleted file mode 100644 index ee142b2ea10db3bb931ee60ca3550e9b1b6317d6..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.project -.pydevproject -.history -.settings -*.pyc -out.rdf -.DS_Store diff --git a/amrbatch/amrld/test/bio_ras_0001_1.json b/amrbatch/amrld/test/bio_ras_0001_1.json deleted file mode 100644 index c790bd5f66a83a3d4e97f8ae7dd2d6f99c5f4e07..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/bio_ras_0001_1.json +++ /dev/null @@ -1,61 +0,0 @@ -[ - { - "root": { - "domain": { - "op1": { - "@id": "g", - "@type": "gene", - "name": { - "@id": "n", - "@type": "name", - "op1": "KRAS" - } - }, - "@id": "a", - "@type": "and", - "op2": { - "@id": "g2", - "@type": "gene", - "name": { - "@id": "n2", - "@type": "name", - "op1": "PIK3CA" - } - }, - "op3": { - "@id": "g3", - "@type": "gene", - "name": { - "@id": "n3", - "@type": "name", - "op1": "BRAF" - } - } - }, - "@id": "o", - "@type": "oncogene", - "location": { - "@id": "c", - "@type": "cancer" - } - }, - "has-date": "2014-08-13T14:22:25", - "@context": { - "and": "http://amr.isi.edu/rdf/core-amr#and", - "oncogene": "http://amr.isi.edu/rdf/core-amr#oncogene", - "kill-01": "https://verbs.colorado.edu/propbank#kill-01", - "name": "http://amr.isi.edu/rdf/core-amr#name", - "cancer": "http://amr.isi.edu/rdf/core-amr#cancer", - "most": "http://amr.isi.edu/rdf/core-amr#most", - "@base": "http://amr.isi.edu/amr_data/bio.ras_0001_1#", - "human": "http://amr.isi.edu/rdf/core-amr#human", - "gene": "http://amr.isi.edu/entity-types#gene", - "root": "http://amr.isi.edu/rdf/core-amr#root", - "frequent": "http://amr.isi.edu/rdf/core-amr#frequent", - "mutate-01": "https://verbs.colorado.edu/propbank#mutate-01" - }, - "@id": "bio.ras_0001_1", - "@type": "http://amr.isi.edu/rdf/core-amr#AMR", - "has-sentence": "The most frequently mutated oncogenes in the deadliest cancers responsible for human mortality are KRAS , PIK3CA and BRAF ." - } -] \ No newline at end of file diff --git a/amrbatch/amrld/test/bio_ras_0001_1.rdf b/amrbatch/amrld/test/bio_ras_0001_1.rdf deleted file mode 100644 index 642dab5647904d0780b0f86f8ffb8b18831edb5a..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/bio_ras_0001_1.rdf +++ /dev/null @@ -1,39 +0,0 @@ -<http://amr.isi.edu/amr_data/bio.ras_0001_1#k> <http://amr.isi.edu/rdf/core-amr#ARG1> <http://amr.isi.edu/amr_data/bio.ras_0001_1#h> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "The most frequently mutated oncogenes in the deadliest cancers responsible for human mortality are KRAS , PIK3CA and BRAF ." . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#f> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#frequent> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#name> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#gene> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#a> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#and> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#o> <http://amr.isi.edu/rdf/core-amr#location> <http://amr.isi.edu/amr_data/bio.ras_0001_1#c> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "bio.ras_0001_1" . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#m> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#most> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#f> <http://amr.isi.edu/rdf/core-amr#degree> <http://amr.isi.edu/amr_data/bio.ras_0001_1#m3> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#name> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#name> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#a> <http://amr.isi.edu/rdf/core-amr#op3> <http://amr.isi.edu/amr_data/bio.ras_0001_1#g3> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#k> <http://amr.isi.edu/rdf/core-amr#ARG0> <http://amr.isi.edu/amr_data/bio.ras_0001_1#c> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#a> <http://amr.isi.edu/rdf/core-amr#op1> <http://amr.isi.edu/amr_data/bio.ras_0001_1#g> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n2> <http://amr.isi.edu/rdf/core-amr#op1> "PIK3CA" . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g> <http://amr.isi.edu/rdf/core-amr#name> <http://amr.isi.edu/amr_data/bio.ras_0001_1#n> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#m3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#most> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#o> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#oncogene> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#m2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://verbs.colorado.edu/propbank#mutate-01> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#k> <http://amr.isi.edu/rdf/core-amr#degree> <http://amr.isi.edu/amr_data/bio.ras_0001_1#m> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#m2> <http://amr.isi.edu/rdf/core-amr#frequency> <http://amr.isi.edu/amr_data/bio.ras_0001_1#f> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#k> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://verbs.colorado.edu/propbank#kill-01> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#h> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#human> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#gene> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/bio.ras_0001_1#o> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#c> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#cancer> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n3> <http://amr.isi.edu/rdf/core-amr#op1> "BRAF" . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#o> <http://amr.isi.edu/rdf/core-amr#TOP> <http://amr.isi.edu/amr_data/bio.ras_0001_1#o> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#o> <http://amr.isi.edu/rdf/core-amr#domain> <http://amr.isi.edu/amr_data/bio.ras_0001_1#a> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g2> <http://amr.isi.edu/rdf/core-amr#name> <http://amr.isi.edu/amr_data/bio.ras_0001_1#n2> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#gene> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#n> <http://amr.isi.edu/rdf/core-amr#op1> "KRAS" . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#m2> <http://amr.isi.edu/rdf/core-amr#ARG1> <http://amr.isi.edu/amr_data/bio.ras_0001_1#o> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#g3> <http://amr.isi.edu/rdf/core-amr#name> <http://amr.isi.edu/amr_data/bio.ras_0001_1#n3> . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#root01> <http://amr.isi.edu/rdf/core-amr#has-date> "2014-08-13T14:22:25" . -<http://amr.isi.edu/amr_data/bio.ras_0001_1#a> <http://amr.isi.edu/rdf/core-amr#op2> <http://amr.isi.edu/amr_data/bio.ras_0001_1#g2> . - diff --git a/amrbatch/amrld/test/bio_ras_0001_1.txt b/amrbatch/amrld/test/bio_ras_0001_1.txt deleted file mode 100644 index c79b0e4ddfe28e231301dc4d18b3b6dd7cc3861e..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/bio_ras_0001_1.txt +++ /dev/null @@ -1,15 +0,0 @@ -# ::id bio.ras_0001_1 ::date 2014-08-13T14:22:25 -# ::snt The most frequently mutated oncogenes in the deadliest cancers responsible for human mortality are KRAS , PIK3CA and BRAF . - -(o / oncogene - :domain (a / and - :op1 (g / gene :name (n / name :op1 "KRAS")) - :op2 (g2 / gene :name (n2 / name :op1 "PIK3CA")) - :op3 (g3 / gene :name (n3 / name :op1 "BRAF"))) - :location (c / cancer - :ARG0-of (k / kill-01 - :ARG1 (h / human) - :degree (m / most))) - :ARG1-of (m2 / mutate-01 - :frequency (f / frequent - :degree (m3 / most)))) diff --git a/amrbatch/amrld/test/pmid-11777939-32_amr.rdf b/amrbatch/amrld/test/pmid-11777939-32_amr.rdf deleted file mode 100644 index 9c69ec8bb482e1298d2f5274fe959f1150d4ce88..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/pmid-11777939-32_amr.rdf +++ /dev/null @@ -1,70 +0,0 @@ -@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . -@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . -@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . -@prefix xml: <http://www.w3.org/XML/1998/namespace> . -@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#root01> a ns1:AMR ; - ns1:has-date "2015-02-27T00:14:25" ; - ns1:has-id "pmid_1177_7939.32" ; - ns1:has-sentence "In previous studies, we showed that Sos-1, E3b1, and Eps8 could form a trimeric complex in vivo upon concomitant overexpression of the three proteins." ; - ns1:root <http://amr.isi.edu/amr_data/pmid_1177_7939.32#s> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#c> a ns1:concomitant . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#e2> a <http://amr.isi.edu/entity-types#enzyme> ; - ns1:name <http://amr.isi.edu/amr_data/pmid_1177_7939.32#n3> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#f> a <https://verbs.colorado.edu/propbank#form-01> ; - ns1:ARG0 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#a> ; - ns1:ARG1 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#m> ; - ns1:condition <http://amr.isi.edu/amr_data/pmid_1177_7939.32#o> ; - ns1:manner <http://amr.isi.edu/amr_data/pmid_1177_7939.32#i> ; - ns1:mod <http://amr.isi.edu/amr_data/pmid_1177_7939.32#p> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#i> a ns1:in-vivo . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#m> a <http://amr.isi.edu/entity-types#macro-molecular-complex> ; - ns1:mod <http://amr.isi.edu/amr_data/pmid_1177_7939.32#t> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#n> a ns1:name ; - ns1:op1 "Sos-1" . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#n2> a ns1:name ; - ns1:op1 "E3b1" . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#n3> a ns1:name ; - ns1:op1 "Eps8" . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#o> a <https://verbs.colorado.edu/propbank#overexpress-00> ; - ns1:ARG2 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#a> ; - ns1:manner <http://amr.isi.edu/amr_data/pmid_1177_7939.32#c> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#p> a ns1:possible . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#p2> a <http://amr.isi.edu/entity-types#protein> ; - ns1:name <http://amr.isi.edu/amr_data/pmid_1177_7939.32#n> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#p3> a <http://amr.isi.edu/entity-types#protein> ; - ns1:name <http://amr.isi.edu/amr_data/pmid_1177_7939.32#n2> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#p5> a ns1:previous . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#s2> a ns1:study ; - ns1:time <http://amr.isi.edu/amr_data/pmid_1177_7939.32#p5> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#t> a ns1:trimeric . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#w> a ns1:we . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#a> a ns1:and ; - ns1:op1 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#p2> ; - ns1:op2 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#p3> ; - ns1:op3 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#e2> . - -<http://amr.isi.edu/amr_data/pmid_1177_7939.32#s> a <https://verbs.colorado.edu/propbank#show-01> ; - ns1:ARG0 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#w> ; - ns1:ARG1 <http://amr.isi.edu/amr_data/pmid_1177_7939.32#f> ; - ns1:TOP <http://amr.isi.edu/amr_data/pmid_1177_7939.32#s> ; - ns1:medium <http://amr.isi.edu/amr_data/pmid_1177_7939.32#s2> . - diff --git a/amrbatch/amrld/test/pmid-11777939-32_amr.txt b/amrbatch/amrld/test/pmid-11777939-32_amr.txt deleted file mode 100755 index d53255b738b30acfc3071a4f10da9b00ac92ab0c..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/pmid-11777939-32_amr.txt +++ /dev/null @@ -1,20 +0,0 @@ -# ::id pmid_1177_7939.32 ::date 2015-02-27T00:14:25 ::authors mrizea -# ::snt In previous studies, we showed that Sos-1, E3b1, and Eps8 could form a trimeric complex in vivo upon concomitant overexpression of the three proteins. -# ::note Sentence+ loaded by script SntLoaderUlf1.7.pl -# ::save-date Wed Apr 1, 2015 ::user bbadarau ::file pmid_1177_7939_32.txt -(s / show-01 - :ARG0 (w / we) - :ARG1 (f / form-01 - :ARG0 (a / and - :op1 (p2 / protein :name (n / name :op1 "Sos-1")) - :op2 (p3 / protein :name (n2 / name :op1 "E3b1")) - :op3 (e2 / enzyme :name (n3 / name :op1 "Eps8"))) - :ARG1 (m / macro-molecular-complex - :mod (t / trimeric)) - :mod (p / possible) - :manner (i / in-vivo) - :condition (o / overexpress-00 - :ARG2 a - :manner (c / concomitant))) - :medium (s2 / study - :time (p5 / previous))) \ No newline at end of file diff --git a/amrbatch/amrld/test/test.amr.graph b/amrbatch/amrld/test/test.amr.graph deleted file mode 100644 index d374bd90a3e10e9e002c9326fbca7d4cfde8febc..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/test/test.amr.graph +++ /dev/null @@ -1,12 +0,0 @@ -# ::id test-1 -# ::snt The sun is a star. -(s / star - :domain (s2 / sun)) - -# ::id test-2 -# ::snt Earth is a planet. -(p / planet - :domain p - :name (n / name - :op1 "Earth")) - diff --git a/amrbatch/amrld/wk/__wk__.txt b/amrbatch/amrld/wk/__wk__.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d1c8b69c3fce7bea45c73efd06983e3c419a92f --- /dev/null +++ b/amrbatch/amrld/wk/__wk__.txt @@ -0,0 +1 @@ + diff --git a/amrbatch/amrld/wk/test-01.stog.amr.nt b/amrbatch/amrld/wk/test-01.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..49251ca49180547eab136189b4412131f20d16d6 --- /dev/null +++ b/amrbatch/amrld/wk/test-01.stog.amr.nt @@ -0,0 +1,22 @@ +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "The sun is a star." . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/amr_data/test-01#s> <http://amr.isi.edu/rdf/amr-terms#domain> <http://amr.isi.edu/amr_data/test-01#s2> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/entity-types#star> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-01" . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . +<http://amr.isi.edu/rdf/amr-terms#domain> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-01#s> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#star> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-01#s> . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-01#s2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/amr-terms#sun> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/rdf/amr-terms#sun> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . + diff --git a/amrbatch/amrld/wk/test-01.stog.amr.penman b/amrbatch/amrld/wk/test-01.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..4f70746db54a3ed8171f776190e3724f2e5c775b --- /dev/null +++ b/amrbatch/amrld/wk/test-01.stog.amr.penman @@ -0,0 +1,4 @@ +# ::id test-01 +# ::snt The sun is a star. +(s / star + :domain (s2 / sun)) \ No newline at end of file diff --git a/amrbatch/amrld/wk/test-02.stog.amr.nt b/amrbatch/amrld/wk/test-02.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..92e70c9870fd91c720dfe0271bac6077b9149d65 --- /dev/null +++ b/amrbatch/amrld/wk/test-02.stog.amr.nt @@ -0,0 +1,19 @@ +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/2000/01/rdf-schema#label> "Earth" . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-02#p> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/entity-types#planet> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#planet> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-02" . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "Earth is a planet." . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . + diff --git a/amrbatch/amrld/wk/test-02.stog.amr.penman b/amrbatch/amrld/wk/test-02.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..c43f2d1ea1775db6a372176df904adb4c732bc8a --- /dev/null +++ b/amrbatch/amrld/wk/test-02.stog.amr.penman @@ -0,0 +1,6 @@ +# ::id test-02 +# ::snt Earth is a planet. +(p / planet + :domain p + :name (n / name + :op1 "Earth")) \ No newline at end of file diff --git a/amrbatch/filepath_manager.py b/amrbatch/filepath_manager.py new file mode 100644 index 0000000000000000000000000000000000000000..4075cff51350a02f5a77297f9d79bcc89b240459 --- /dev/null +++ b/amrbatch/filepath_manager.py @@ -0,0 +1,112 @@ +#!/usr/bin/python3.10 +# -*-coding:Utf-8 -* + +#============================================================================== +# AMR Batch: Filepath Manager +#------------------------------------------------------------------------------ +# Handler to manage file paths. +#============================================================================== + +import sys, os, glob +import shutil + +# Reference Suffix +TEXT_SUFFIX = ".txt" +SENTENCE_SUFFIX = ".sentence.txt" +PENMAN_AMR_GRAPH_SUFFIX = ".stog.amr.penman" +DOT_AMR_GRAPH_SUFFIX = ".stog.amr.dot" +PNG_AMR_GRAPH_SUFFIX = ".stog.amr.png" +AMR_RDF_SUFFIX = ".stog.amr.nt" +AMR_TTL_SUFFIX = ".stog.amr.ttl" + +# AMRLD Parameters +LIB_PATH = os.path.dirname(os.path.abspath(__file__)) + '/' +AMRLD_DIR = f'{LIB_PATH}amrld/' +WK_DIR = 'wk/' +AMRLD_WORKDIR = AMRLD_DIR + WK_DIR + + +#============================================================================== +# Class +#============================================================================== + +class FilepathManager: + """ Class to handle filepaths. + """ + + #-------------------------------------------------------------------------- + # Constructor + #-------------------------------------------------------------------------- + + def __init__(self, input_filepath, output_dirpath=None): + + self.base_reference = os.path.splitext(os.path.basename(input_filepath))[0] + + self.input_filepath = input_filepath + self.input_dirpath = os.path.dirname(input_filepath) + + if output_dirpath is None: + self.output_dirpath = self._input_dirpath + else: + self.output_dirpath = output_dirpath + + + #-------------------------------------------------------------------------- + # Filepath Accessors + #-------------------------------------------------------------------------- + + def get_workdata_output_dirpath(self, data_ref): + return f'{self.output_dirpath}{data_ref}/' + + def get_sentence_output_filepath(self): + return f'{self.output_dirpath}{self.base_reference}{SENTENCE_SUFFIX}' + + def get_data_output_filepath(self, data): + return f'{self.output_dirpath}{data["output_data_dir"]}' + + def get_penman_amr_graph_output_filepath(self, data): + dirpath = self.get_data_output_filepath(data) + filename = f'{data["data_ref"]}{PENMAN_AMR_GRAPH_SUFFIX}' + return f'{dirpath}{filename}' + + def get_dot_amr_graph_output_filepath(self, data): + dirpath = self.get_data_output_filepath(data) + filename = f'{data["data_ref"]}{DOT_AMR_GRAPH_SUFFIX}' + return f'{dirpath}{filename}' + + def get_png_amr_graph_output_filepath(self, data): + dirpath = self.get_data_output_filepath(data) + filename = f'{data["data_ref"]}{PNG_AMR_GRAPH_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_rdf_triple_output_filepath(self, data): + dirpath = self.get_data_output_filepath(data) + filename = f'{data["data_ref"]}{AMR_RDF_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_rdf_turtle_output_filepath(self, data): + dirpath = self.get_data_output_filepath(data) + filename = f'{data["data_ref"]}{AMR_TTL_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_graph_amrld_filepath(self, data): + dirpath = f'{AMRLD_WORKDIR}' + filename = f'{data["data_ref"]}{PENMAN_AMR_GRAPH_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_rdf_amrld_filepath(self, data): + dirpath = f'{AMRLD_WORKDIR}' + filename = f'{data["data_ref"]}{AMR_RDF_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_graph_wk_filepath(self, data): + dirpath = f'{WK_DIR}' + filename = f'{data["data_ref"]}{PENMAN_AMR_GRAPH_SUFFIX}' + return f'{dirpath}{filename}' + + def get_amr_rdf_wk_filepath(self, data): + dirpath = f'{WK_DIR}' + filename = f'{data["data_ref"]}{AMR_RDF_SUFFIX}' + return f'{dirpath}{filename}' + + diff --git a/amrbatch/logging.conf b/amrbatch/logging.conf new file mode 100644 index 0000000000000000000000000000000000000000..6006ebdb9326b8685c3052002e107f9c74e5e967 --- /dev/null +++ b/amrbatch/logging.conf @@ -0,0 +1,39 @@ +[loggers] +keys=root + +[handlers] +keys=consoleSimpleHandler,consoleWarningHandler,fileHandler + +[formatters] +keys=simpleFormat,warningFormat,fileFormat + +[logger_root] +level=DEBUG +handlers=consoleWarningHandler,consoleSimpleHandler,fileHandler + +[handler_consoleSimpleHandler] +class=StreamHandler +level=INFO +formatter=simpleFormat +args=(sys.stdout,) + +[handler_consoleWarningHandler] +class=StreamHandler +level=WARNING +formatter=warningFormat +args=(sys.stdout,) + +[handler_fileHandler] +class=FileHandler +level=DEBUG +formatter=fileFormat +args=('amrbatch.log', 'w+', 'utf8') + +[formatter_simpleFormat] +format=%(message)s + +[formatter_warningFormat] +format=%(asctime)s - %(levelname)s (%(name)s, %(lineno)d) + +[formatter_fileFormat] +format= - %(levelname)s - %(message)s diff --git a/amrbatch/main.py b/amrbatch/main.py index a60a622b4affad71edb419ca98ba32de0c0ded5b..336a0df241e3eaa81d9e49226e57d487de984887 100644 --- a/amrbatch/main.py +++ b/amrbatch/main.py @@ -8,39 +8,278 @@ #============================================================================== import sys, os, glob -import shutil +import shutil, re +import subprocess +import amrlib from rdflib import Graph +import traceback +import logging.config +from amrlib.graph_processing.amr_plot import AMRPlot +from filepath_manager import FilepathManager +# -- Config File Path +LIB_PATH = os.path.dirname(os.path.abspath(__file__)) + '/' +LOGGING_CONF_FILE_PATH = f'{LIB_PATH}logging.conf' +CONFIG_FILE_PATH = f'{LIB_PATH}config.xml' + +# AMRLD Parameters +AMRLD_DIR = f'{LIB_PATH}amrld/' +AMRLD_WORKDIR = f'{AMRLD_DIR}wk/' + +# -- Logging +logging.config.fileConfig(LOGGING_CONF_FILE_PATH, disable_existing_loggers=True) +logger = logging.getLogger('root') + + + +#============================================================================== +# Functions to manage in-process data +#============================================================================== + +def is_valid_sentence(sentence): + """ True if the sentence is correct. + """ + is_empty = ((sentence == "") | (sentence == "\n")) + lang_mark_re = re.compile("\([a-z]+\)(.)*") + is_language_mark = lang_mark_re.match(sentence) is not None + return not (is_empty | is_language_mark) + + +def clean_sentence(sentence): + """ Sentence cleanup as needed """ + sentence = re.sub("(\.)*\\n", "", sentence) + return sentence + + +def define_new_data(base_ref, number, sentence): + + number_str = str(number).rjust(2,"0") + data_ref = base_ref + "-" + number_str + output_data_dir = data_ref + "/" + id_line_str = "# ::id " + data_ref + "\n" + sentence = clean_sentence(sentence) + sentence += "." + + new_data = { + "base_ref" : data_ref, + "number" : number, + "output_data_dir" : output_data_dir, + "data_ref" : data_ref, + "id_line_str" : id_line_str, + "sentence" : sentence, + "graph" : "" + } + return new_data + + +def get_amr_graph_list(workdata_list): + amr_graph_list = [] + for workdata in workdata_list: + amr_graph_list.append(workdata['graph']) + return amr_graph_list + #============================================================================== -# Steps +# Preparation Steps #============================================================================== -# TODO +def __prepare_workdata(filepath_manager): + logger.info('-- Reading input files to recover a list of sentences') + input_filepath = filepath_manager.input_filepath + base_reference = filepath_manager.base_reference + + workdata_list = list() + + sentence_number = 0 + with open(input_filepath, "r") as reading_file: # r = read + for line in reading_file.readlines(): + sentences = line.split(". ") + for sentence in sentences: + if is_valid_sentence(sentence): + sentence_number += 1 + new_data = define_new_data(base_reference, sentence_number, sentence) + workdata_list.append(new_data) + logger.debug(f' *** sentence {sentence_number} *** \n{new_data}') + + logger.info(f'----- number of sentences: {len(workdata_list)}') + return workdata_list + + +def __build_output_dir_tree(filepath_manager, workdata_list): + base_output_dirpath = filepath_manager.output_dirpath + logger.debug(f'-- Making output directory tree ({base_output_dirpath})') + os.makedirs(base_output_dirpath, exist_ok=True) + for data in workdata_list: + output_dir = filepath_manager.get_workdata_output_dirpath(data["output_data_dir"]) + os.makedirs(output_dir, exist_ok=True) + + +def __generate_sentence_file(filepath_manager, workdata_list): + sentence_filepath = filepath_manager.get_sentence_output_filepath() + logger.debug(f"-- Generating sentence file ") + with open(sentence_filepath, "w") as writing_file: # w = write + first = True + for workdata in workdata_list: + if not first: writing_file.write("\n") + writing_file.write(workdata["sentence"]) + first = False + + #============================================================================== -# AMR Main Methods +# Conversion Steps #============================================================================== -def parse_sentences_from_file(input_file_path, - output_penman_file_path=None, - technical_dir_path=None): +def __generate_penman_amr_graph(filepath_manager, data): + """ AMR graph generation in penman format """ + + graph = data["graph"] + output_filepath = filepath_manager.get_penman_amr_graph_output_filepath(data) + logger.debug(f"----- AMR Graph file (penman): {os.path.basename(output_filepath)}") + with open(output_filepath, "w") as writing_file: # w = write + writing_file.write(data["id_line_str"]) + writing_file.write(graph) + + + +def __generate_dot_amr_graph(filepath_manager, data): + """ AMR graph generation in dot and png format """ + + graph = data["graph"] + + try: + # -- generating dot/png files using AMRLib and GraphViz + dot_filename = filepath_manager.get_dot_amr_graph_output_filepath(data) + format = 'png' + logger.debug(f'----- AMR Graph file (dot): {os.path.basename(dot_filename)}') + plot = AMRPlot(dot_filename, format) + plot.build_from_graph(graph) + plot.graph.render() + + render_fn = dot_filename + '.' + format # -- renaming PNG file + good_png_fn = filepath_manager.get_png_amr_graph_output_filepath(data) + logger.debug(f'----- AMR Graph file (png): {{os.path.basename(good_png_fn)}}') + os.rename(render_fn, good_png_fn) + + except: + logger.warning('Exception when trying to plot') + traceback.print_exc() + + + + +def __convert_sentences_to_graphs(amr_model, workdata_list): + """ Converting text sentences to AMR graphs """ + + logger.info("-- Loading AMR model") + stog = amrlib.load_stog_model(model_dir=amr_model) + + logger.info("-- Converting sentences to AMR graphs") + wd_number = 0 + for data in workdata_list: + wd_number += 1 + stog_result = stog.parse_sents([data["sentence"]]) + logger.info(f'----- Sentence {wd_number} successfully processed') + logger.debug(stog_result) + data["graph"] = stog_result[0] + + logger.info(f'----- Total processed graph number: {wd_number}') + return workdata_list + + + +def __generate_amr_graph_files(filepath_manager, workdata_list): + logger.info("-- Generating AMR graph files") + for data in workdata_list: + __generate_penman_amr_graph(filepath_manager, data) + __generate_dot_amr_graph(filepath_manager, data) + + + +#============================================================================== +# Serialization Steps +#============================================================================== + +def __serialize_amr_graph_to_rdf_triple(filepath_manager, data): + """ Serialize AMR graph to AMR-RDF triple """ + + # -- Filepath + input_file = filepath_manager.get_penman_amr_graph_output_filepath(data) + input_amrld_file = filepath_manager.get_amr_graph_amrld_filepath(data) + output_amrld_file = filepath_manager.get_amr_rdf_amrld_filepath(data) + input_wk_file = filepath_manager.get_amr_graph_wk_filepath(data) + output_wk_file = filepath_manager.get_amr_rdf_wk_filepath(data) + amr_triple_file = filepath_manager.get_amr_rdf_triple_output_filepath(data) + + # -- AMR-LD processing + amrld_process = ["python3", "amr_to_rdf.py", + "-i", input_wk_file, + "-o", output_wk_file] + if (os.path.isfile(input_file)): + logger.info("-- Serialize AMR graphs to RDF using amr-ld library") + logger.debug(f'----- penman filepath: {input_file}') + logger.debug(f'----- AMRLD filepath: {input_amrld_file}') + shutil.copyfile(input_file, input_amrld_file) + current_dirpath = os.getcwd() + os.chdir(AMRLD_DIR) + subprocess.run(amrld_process) + os.chdir(current_dirpath) + + # -- Copy result + if (os.path.isfile(output_amrld_file)): + logger.info(f'-- Generating AMR RDF file (triple): {os.path.basename(amr_triple_file)}') + shutil.copyfile(output_amrld_file, amr_triple_file) + + +def __convert_rdf_triple_to_rdf_turtle(filepath_manager, data): + """ Converting AMR-RDF triple to AMR-RDF turtle """ + + # -- Filepath + amr_triple_file = filepath_manager.get_amr_rdf_triple_output_filepath(data) + amr_turtle_file = filepath_manager.get_amr_rdf_turtle_output_filepath(data) + + # -- Conversion + if (os.path.isfile(amr_triple_file)): + logger.info(f'-- Generating AMR RDF file (turtle): {os.path.basename(amr_turtle_file)}') + g = Graph() + g.parse(amr_triple_file) + g.serialize(destination=amr_turtle_file, format='turtle') + + + +def __convert_amr_graphs_to_rdf(filepath_manager, data_list): + """ Converting AMR graphs to AMR-RDF """ + + for data in data_list: + __serialize_amr_graph_to_rdf_triple(filepath_manager, data) + __convert_rdf_triple_to_rdf_turtle(filepath_manager, data) + + + +#============================================================================== +# Main Method(s) +#============================================================================== + +def parse_sentences_from_file(input_filepath, + amr_model_path, + output_dirpath=None, + amrld_serialization=False): """ Method to parse an input file containing natural language sentences and construct the corresponding AMR graphs (and their RDF serializations if required). The method returns an AMR graph string in PENMAN format. AMR graphs are also - serialized in RDF turtle format using the AMR-LD library if requested - (by defining output_turtle_file_path as a parameter). + serialized in RDF turtle format using the AMR-LD library if required + (by defining turtle_output_file_path as parameter). Parameters ---------- - input_file_path: a path to a text file. - output_penman_file_path: a file path where the output graphs is written in PENMAN format if defined (the function still outputs the string). - output_turtle_file_path: a file path where the output AMRLD representation is written in TURTLE format if defined. + input_filepath: a path to a text file. + output_dirpath: a directory path where the output data are written if defined (the function still outputs the string). + turtle_output_file_path: a file path where the output AMRLD representation is written in TURTLE format if defined. technical_dir_path: a dir path where some technical and log files are written if defined. Returns @@ -49,7 +288,35 @@ def parse_sentences_from_file(input_file_path, """ - pass + logger.info('[AMR Batch] NL Document Parsing') + + # -- Prepare the sentences to be converted + logger.info('\n === Preparation === ') + filepath_manager = FilepathManager(input_filepath, output_dirpath) + logger.info(f'-- base reference: {filepath_manager.base_reference}') + logger.info(f'-- input filepath: {filepath_manager.input_filepath}') + logger.info(f'-- output dirpath: {filepath_manager.output_dirpath}') + assert os.path.exists(input_filepath), f'input file does not exists ({input_filepath})' + workdata_list = __prepare_workdata(filepath_manager) + __build_output_dir_tree(filepath_manager, workdata_list) + __generate_sentence_file(filepath_manager, workdata_list) + + # -- Convert sentences to graphs + logger.info('\n === Text Convert to AMR Graphs === ') + logger.info(f'-- library: amrlib') + logger.debug(f' ({AMRLD_DIR})') + logger.info(f'-- model: {os.path.basename(amr_model_path)}') + logger.debug(f' ({amr_model_path})') + logger.debug(f'-- working directory: {AMRLD_WORKDIR}') + workdata_list = __convert_sentences_to_graphs(amr_model_path, workdata_list) + __generate_amr_graph_files(filepath_manager, workdata_list) + + if amrld_serialization==True: + # -- Convert graphs to RDF + logger.info('\n === AMR Graphs Serialization to AMR-RDF Representation === ') + logger.info("-- library: amrlk") + __convert_amr_graphs_to_rdf(filepath_manager, workdata_list) + - return '' + return get_amr_graph_list(workdata_list) diff --git a/tests/amrbatch.log b/tests/amrbatch.log new file mode 100644 index 0000000000000000000000000000000000000000..1c35a300cf9b008105159c603298fedabe629b13 --- /dev/null +++ b/tests/amrbatch.log @@ -0,0 +1,48 @@ +- INFO - [AMR Batch] NL Document Parsing +- INFO - + === Preparation === +- INFO - -- base reference: test +- INFO - -- input filepath: /home/lamenji/Workspace/Tetras/amrbatch/tests/input/test.txt +- INFO - -- output dirpath: /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230303/ +- INFO - -- Reading input files to recover a list of sentences +- DEBUG - *** sentence 1 *** +{'base_ref': 'test-01', 'number': 1, 'output_data_dir': 'test-01/', 'data_ref': 'test-01', 'id_line_str': '# ::id test-01\n', 'sentence': 'The sun is a star.', 'graph': ''} +- DEBUG - *** sentence 2 *** +{'base_ref': 'test-02', 'number': 2, 'output_data_dir': 'test-02/', 'data_ref': 'test-02', 'id_line_str': '# ::id test-02\n', 'sentence': 'Earth is a planet.', 'graph': ''} +- INFO - ----- number of sentences: 2 +- DEBUG - -- Making output directory tree (/home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230303/) +- DEBUG - -- Generating sentence file +- INFO - + === Text Convert to AMR Graphs === +- INFO - -- library: amrlib +- DEBUG - (/home/lamenji/Workspace/Tetras/amrbatch/amrbatch/amrld/) +- INFO - -- model: model_parse_xfm_bart_large-v0_1_0 +- DEBUG - (/home/lamenji/Workspace/Tetras/amrbatch/tests/../amr_models/model_parse_xfm_bart_large-v0_1_0) +- DEBUG - -- working directory: /home/lamenji/Workspace/Tetras/amrbatch/amrbatch/amrld/wk/ +- INFO - -- Loading AMR model +- INFO - -- Converting sentences to AMR graphs +- INFO - ----- Sentence 1 successfully processed +- DEBUG - ['# ::snt The sun is a star.\n(s / star\n :domain (s2 / sun))'] +- INFO - ----- Sentence 2 successfully processed +- DEBUG - ['# ::snt Earth is a planet.\n(p / planet\n :domain p\n :name (n / name\n :op1 "Earth"))'] +- INFO - ----- Total processed graph number: 2 +- INFO - -- Generating AMR graph files +- DEBUG - ----- AMR Graph file (penman): test-01.stog.amr.penman +- DEBUG - ----- AMR Graph file (dot): test-01.stog.amr.dot +- DEBUG - ----- AMR Graph file (png): {os.path.basename(good_png_fn)} +- DEBUG - ----- AMR Graph file (penman): test-02.stog.amr.penman +- DEBUG - ----- AMR Graph file (dot): test-02.stog.amr.dot +- DEBUG - ----- AMR Graph file (png): {os.path.basename(good_png_fn)} +- INFO - + === AMR Graphs Serialization to AMR-RDF Representation === +- INFO - -- library: amrlk +- INFO - -- Serialize AMR graphs to RDF using amr-ld library +- DEBUG - ----- penman filepath: /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230303/test-01/test-01.stog.amr.penman +- DEBUG - ----- AMRLD filepath: /home/lamenji/Workspace/Tetras/amrbatch/amrbatch/amrld/wk/test-01.stog.amr.penman +- INFO - -- Generating AMR RDF file (triple): test-01.stog.amr.nt +- INFO - -- Generating AMR RDF file (turtle): test-01.stog.amr.ttl +- INFO - -- Serialize AMR graphs to RDF using amr-ld library +- DEBUG - ----- penman filepath: /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230303/test-02/test-02.stog.amr.penman +- DEBUG - ----- AMRLD filepath: /home/lamenji/Workspace/Tetras/amrbatch/amrbatch/amrld/wk/test-02.stog.amr.penman +- INFO - -- Generating AMR RDF file (triple): test-02.stog.amr.nt +- INFO - -- Generating AMR RDF file (turtle): test-02.stog.amr.ttl diff --git a/tests/output/Test-20230302/test-01/test-01.stog.amr.dot b/tests/output/Test-20230302/test-01/test-01.stog.amr.dot new file mode 100644 index 0000000000000000000000000000000000000000..57af646621c9fcf8287fa241ef25aaaabbc02d89 --- /dev/null +++ b/tests/output/Test-20230302/test-01/test-01.stog.amr.dot @@ -0,0 +1,6 @@ +digraph amr_graph { + rankdir=LR size="12,8" + s [label="s/star" shape=circle] + s2 [label="s2/sun" shape=circle] + s -> s2 [label=":domain"] +} diff --git a/tests/output/Test-20230302/test-01/test-01.stog.amr.nt b/tests/output/Test-20230302/test-01/test-01.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..6ebc9919262cbd558cc1daa9de547c2bf5520743 --- /dev/null +++ b/tests/output/Test-20230302/test-01/test-01.stog.amr.nt @@ -0,0 +1,21 @@ +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/entity-types#star> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/amr-terms#sun> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "The sun is a star." . +<http://amr.isi.edu/amr_data/test-01#s2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/amr-terms#sun> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/amr_data/test-01#s> <http://amr.isi.edu/rdf/amr-terms#domain> <http://amr.isi.edu/amr_data/test-01#s2> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/amr-terms#domain> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/amr_data/test-01#s> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#star> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-01" . +<http://amr.isi.edu/amr_data/test-01#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-01#s> . diff --git a/tests/output/Test-20230302/test-01/test-01.stog.amr.penman b/tests/output/Test-20230302/test-01/test-01.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..4f70746db54a3ed8171f776190e3724f2e5c775b --- /dev/null +++ b/tests/output/Test-20230302/test-01/test-01.stog.amr.penman @@ -0,0 +1,4 @@ +# ::id test-01 +# ::snt The sun is a star. +(s / star + :domain (s2 / sun)) \ No newline at end of file diff --git a/tests/output/Test-20230302/test-01/test-01.stog.amr.png b/tests/output/Test-20230302/test-01/test-01.stog.amr.png new file mode 100644 index 0000000000000000000000000000000000000000..1184e154c13d623631e31e54b8ebd114be61aca3 Binary files /dev/null and b/tests/output/Test-20230302/test-01/test-01.stog.amr.png differ diff --git a/tests/output/Test-20230302/test-01/test-01.stog.amr.ttl b/tests/output/Test-20230302/test-01/test-01.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..4ad04c796b2fd5e64c41f71202163c76ca38c163 --- /dev/null +++ b/tests/output/Test-20230302/test-01/test-01.stog.amr.ttl @@ -0,0 +1,36 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix ns2: <http://amr.isi.edu/rdf/amr-terms#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/test-01#root01> a ns1:AMR ; + ns1:has-id "test-01" ; + ns1:has-sentence "The sun is a star." ; + ns1:root <http://amr.isi.edu/amr_data/test-01#s> . + +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns2:domain a ns1:Role . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +<http://amr.isi.edu/amr_data/test-01#s> a <http://amr.isi.edu/entity-types#star> ; + ns2:domain <http://amr.isi.edu/amr_data/test-01#s2> . + +<http://amr.isi.edu/amr_data/test-01#s2> a ns2:sun . + +<http://amr.isi.edu/entity-types#star> a ns1:NamedEntity . + +ns2:sun a ns1:Concept . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + diff --git a/tests/output/Test-20230302/test-02/test-02.stog.amr.dot b/tests/output/Test-20230302/test-02/test-02.stog.amr.dot new file mode 100644 index 0000000000000000000000000000000000000000..1b8f97f75734288ff356faf5c09ba53a14141181 --- /dev/null +++ b/tests/output/Test-20230302/test-02/test-02.stog.amr.dot @@ -0,0 +1,9 @@ +digraph amr_graph { + rankdir=LR size="12,8" + p [label="p/planet" shape=circle] + n [label="n/name" shape=circle] + p -> p [label=":domain"] + p -> n [label=":name"] + node_0 [label="\"Earth\"" shape=rectangle] + n -> node_0 [label=":op1"] +} diff --git a/tests/output/Test-20230302/test-02/test-02.stog.amr.nt b/tests/output/Test-20230302/test-02/test-02.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..2cdb95fe98f6dab905fb644d29a20109d89621d1 --- /dev/null +++ b/tests/output/Test-20230302/test-02/test-02.stog.amr.nt @@ -0,0 +1,18 @@ +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-02" . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-02#p> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#planet> . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/2000/01/rdf-schema#label> "Earth" . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . +<http://amr.isi.edu/entity-types#planet> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "Earth is a planet." . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . diff --git a/tests/output/Test-20230302/test-02/test-02.stog.amr.penman b/tests/output/Test-20230302/test-02/test-02.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..c43f2d1ea1775db6a372176df904adb4c732bc8a --- /dev/null +++ b/tests/output/Test-20230302/test-02/test-02.stog.amr.penman @@ -0,0 +1,6 @@ +# ::id test-02 +# ::snt Earth is a planet. +(p / planet + :domain p + :name (n / name + :op1 "Earth")) \ No newline at end of file diff --git a/tests/output/Test-20230302/test-02/test-02.stog.amr.png b/tests/output/Test-20230302/test-02/test-02.stog.amr.png new file mode 100644 index 0000000000000000000000000000000000000000..ccf17ae6265b900965bce09be359fa5500c2400f Binary files /dev/null and b/tests/output/Test-20230302/test-02/test-02.stog.amr.png differ diff --git a/tests/output/Test-20230302/test-02/test-02.stog.amr.ttl b/tests/output/Test-20230302/test-02/test-02.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..5f7d3d7f4e8bf37c29f7290956a19a621f90a03e --- /dev/null +++ b/tests/output/Test-20230302/test-02/test-02.stog.amr.ttl @@ -0,0 +1,29 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/test-02#root01> a ns1:AMR ; + ns1:has-id "test-02" ; + ns1:has-sentence "Earth is a planet." ; + ns1:root <http://amr.isi.edu/amr_data/test-02#p> . + +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +<http://amr.isi.edu/amr_data/test-02#p> a <http://amr.isi.edu/entity-types#planet> ; + rdfs:label "Earth" . + +<http://amr.isi.edu/entity-types#planet> a ns1:NamedEntity . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + diff --git a/tests/output/Test-20230302/test.sentence.txt b/tests/output/Test-20230302/test.sentence.txt new file mode 100644 index 0000000000000000000000000000000000000000..2bc85c3e85f9bf78d9d521ab35bd1ff85b3588c8 --- /dev/null +++ b/tests/output/Test-20230302/test.sentence.txt @@ -0,0 +1,2 @@ +The sun is a star. +Earth is a planet. \ No newline at end of file diff --git a/tests/output/Test-20230303/test-01/test-01.stog.amr.dot b/tests/output/Test-20230303/test-01/test-01.stog.amr.dot new file mode 100644 index 0000000000000000000000000000000000000000..57af646621c9fcf8287fa241ef25aaaabbc02d89 --- /dev/null +++ b/tests/output/Test-20230303/test-01/test-01.stog.amr.dot @@ -0,0 +1,6 @@ +digraph amr_graph { + rankdir=LR size="12,8" + s [label="s/star" shape=circle] + s2 [label="s2/sun" shape=circle] + s -> s2 [label=":domain"] +} diff --git a/tests/output/Test-20230303/test-01/test-01.stog.amr.nt b/tests/output/Test-20230303/test-01/test-01.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..49251ca49180547eab136189b4412131f20d16d6 --- /dev/null +++ b/tests/output/Test-20230303/test-01/test-01.stog.amr.nt @@ -0,0 +1,22 @@ +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "The sun is a star." . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/amr_data/test-01#s> <http://amr.isi.edu/rdf/amr-terms#domain> <http://amr.isi.edu/amr_data/test-01#s2> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/entity-types#star> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-01" . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . +<http://amr.isi.edu/rdf/amr-terms#domain> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-01#s> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#star> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-01#s> . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-01#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-01#s2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/amr-terms#sun> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/rdf/amr-terms#sun> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . + diff --git a/tests/output/Test-20230303/test-01/test-01.stog.amr.penman b/tests/output/Test-20230303/test-01/test-01.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..4f70746db54a3ed8171f776190e3724f2e5c775b --- /dev/null +++ b/tests/output/Test-20230303/test-01/test-01.stog.amr.penman @@ -0,0 +1,4 @@ +# ::id test-01 +# ::snt The sun is a star. +(s / star + :domain (s2 / sun)) \ No newline at end of file diff --git a/tests/output/Test-20230303/test-01/test-01.stog.amr.png b/tests/output/Test-20230303/test-01/test-01.stog.amr.png new file mode 100644 index 0000000000000000000000000000000000000000..1184e154c13d623631e31e54b8ebd114be61aca3 Binary files /dev/null and b/tests/output/Test-20230303/test-01/test-01.stog.amr.png differ diff --git a/tests/output/Test-20230303/test-01/test-01.stog.amr.ttl b/tests/output/Test-20230303/test-01/test-01.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..4ad04c796b2fd5e64c41f71202163c76ca38c163 --- /dev/null +++ b/tests/output/Test-20230303/test-01/test-01.stog.amr.ttl @@ -0,0 +1,36 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix ns2: <http://amr.isi.edu/rdf/amr-terms#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/test-01#root01> a ns1:AMR ; + ns1:has-id "test-01" ; + ns1:has-sentence "The sun is a star." ; + ns1:root <http://amr.isi.edu/amr_data/test-01#s> . + +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns2:domain a ns1:Role . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +<http://amr.isi.edu/amr_data/test-01#s> a <http://amr.isi.edu/entity-types#star> ; + ns2:domain <http://amr.isi.edu/amr_data/test-01#s2> . + +<http://amr.isi.edu/amr_data/test-01#s2> a ns2:sun . + +<http://amr.isi.edu/entity-types#star> a ns1:NamedEntity . + +ns2:sun a ns1:Concept . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + diff --git a/tests/output/Test-20230303/test-02/test-02.stog.amr.dot b/tests/output/Test-20230303/test-02/test-02.stog.amr.dot new file mode 100644 index 0000000000000000000000000000000000000000..1b8f97f75734288ff356faf5c09ba53a14141181 --- /dev/null +++ b/tests/output/Test-20230303/test-02/test-02.stog.amr.dot @@ -0,0 +1,9 @@ +digraph amr_graph { + rankdir=LR size="12,8" + p [label="p/planet" shape=circle] + n [label="n/name" shape=circle] + p -> p [label=":domain"] + p -> n [label=":name"] + node_0 [label="\"Earth\"" shape=rectangle] + n -> node_0 [label=":op1"] +} diff --git a/tests/output/Test-20230303/test-02/test-02.stog.amr.nt b/tests/output/Test-20230303/test-02/test-02.stog.amr.nt new file mode 100644 index 0000000000000000000000000000000000000000..92e70c9870fd91c720dfe0271bac6077b9149d65 --- /dev/null +++ b/tests/output/Test-20230303/test-02/test-02.stog.amr.nt @@ -0,0 +1,19 @@ +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/2000/01/rdf-schema#label> "Earth" . +<http://amr.isi.edu/rdf/core-amr#Concept> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Concept" . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#root> <http://amr.isi.edu/amr_data/test-02#p> . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Role> . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#Concept> . +<http://amr.isi.edu/entity-types#planet> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#NamedEntity> . +<http://amr.isi.edu/amr_data/test-02#p> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#planet> . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-02" . +<http://amr.isi.edu/amr_data/test-02#root01> <http://amr.isi.edu/rdf/core-amr#has-sentence> "Earth is a planet." . +<http://amr.isi.edu/rdf/core-amr#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<http://amr.isi.edu/rdf/core-amr#Role> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> . +<http://amr.isi.edu/rdf/core-amr#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Role" . + diff --git a/tests/output/Test-20230303/test-02/test-02.stog.amr.penman b/tests/output/Test-20230303/test-02/test-02.stog.amr.penman new file mode 100644 index 0000000000000000000000000000000000000000..c43f2d1ea1775db6a372176df904adb4c732bc8a --- /dev/null +++ b/tests/output/Test-20230303/test-02/test-02.stog.amr.penman @@ -0,0 +1,6 @@ +# ::id test-02 +# ::snt Earth is a planet. +(p / planet + :domain p + :name (n / name + :op1 "Earth")) \ No newline at end of file diff --git a/tests/output/Test-20230303/test-02/test-02.stog.amr.png b/tests/output/Test-20230303/test-02/test-02.stog.amr.png new file mode 100644 index 0000000000000000000000000000000000000000..ccf17ae6265b900965bce09be359fa5500c2400f Binary files /dev/null and b/tests/output/Test-20230303/test-02/test-02.stog.amr.png differ diff --git a/tests/output/Test-20230303/test-02/test-02.stog.amr.ttl b/tests/output/Test-20230303/test-02/test-02.stog.amr.ttl new file mode 100644 index 0000000000000000000000000000000000000000..5f7d3d7f4e8bf37c29f7290956a19a621f90a03e --- /dev/null +++ b/tests/output/Test-20230303/test-02/test-02.stog.amr.ttl @@ -0,0 +1,29 @@ +@prefix ns1: <http://amr.isi.edu/rdf/core-amr#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + +ns1:Concept a rdfs:Class ; + rdfs:label "AMR-Concept" . + +ns1:Role a rdfs:Class ; + rdfs:label "AMR-Role" . + +<http://amr.isi.edu/amr_data/test-02#root01> a ns1:AMR ; + ns1:has-id "test-02" ; + ns1:has-sentence "Earth is a planet." ; + ns1:root <http://amr.isi.edu/amr_data/test-02#p> . + +<http://amr.isi.edu/frames/ld/v1.2.2/FrameRole> a ns1:Role ; + rdfs:label "AMR-PropBank-Role" . + +ns1:Frame a ns1:Concept ; + rdfs:label "AMR-PropBank-Frame" . + +<http://amr.isi.edu/amr_data/test-02#p> a <http://amr.isi.edu/entity-types#planet> ; + rdfs:label "Earth" . + +<http://amr.isi.edu/entity-types#planet> a ns1:NamedEntity . + +ns1:NamedEntity a ns1:Concept ; + rdfs:label "AMR-EntityType", + "AMR-Term" . + diff --git a/tests/output/Test-20230303/test.sentence.txt b/tests/output/Test-20230303/test.sentence.txt new file mode 100644 index 0000000000000000000000000000000000000000..2bc85c3e85f9bf78d9d521ab35bd1ff85b3588c8 --- /dev/null +++ b/tests/output/Test-20230303/test.sentence.txt @@ -0,0 +1,2 @@ +The sun is a star. +Earth is a planet. \ No newline at end of file diff --git a/tests/test_amrbatch_main.py b/tests/test_amrbatch_main.py index f5d67831f97a28503bf7fca7c1dbeb6d65ffba57..5da50414cae6c7ee20dff5fe23e69a998b2a41be 100644 --- a/tests/test_amrbatch_main.py +++ b/tests/test_amrbatch_main.py @@ -10,9 +10,10 @@ import subprocess, os from datetime import datetime -FILE_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' -INPUT_DIR_PATH = f'{FILE_PATH}/input/' -OUTPUT_DIR_PATH = f'{FILE_PATH}/output/' +TESTS_PATH = f'{os.path.dirname(os.path.abspath(__file__))}' +INPUT_DIR_PATH = f'{TESTS_PATH}/input/' +OUTPUT_DIR_PATH = f'{TESTS_PATH}/output/' +AMR_MODEL_PATH = f'{TESTS_PATH}/../amr_models/model_parse_xfm_bart_large-v0_1_0' from context import amrbatch @@ -23,14 +24,15 @@ from context import amrbatch #============================================================================== # -- Input Data -amrld_file_path = f'{INPUT_DIR_PATH}test.txt' +input_filename = f'test.txt' +input_filepath = f'{INPUT_DIR_PATH}{input_filename}' # -- Output references base_output_name = f'Test' time_ref = f'{datetime.now().strftime("%Y%m%d")}' -out_dir_path = f'{OUTPUT_DIR_PATH}{base_output_name}-{time_ref}/' -os.makedirs(out_dir_path, exist_ok=True) +output_dirpath = f'{OUTPUT_DIR_PATH}{base_output_name}-{time_ref}/' +os.makedirs(output_dirpath, exist_ok=True) penman_output_file = f'{base_output_name}.pnm' turtle_output_file = f'{base_output_name}.ttl' @@ -41,5 +43,10 @@ turtle_output_file = f'{base_output_name}.ttl' #============================================================================== # -- Parsing from a file -amrbatch.parsing_sentences_from_file( - input_file_path, penman_output_file=None, turtle_output_file=None) +amr_graph_list = amrbatch.parse_sentences_from_file( + input_filepath, amr_model_path=AMR_MODEL_PATH, + output_dirpath=output_dirpath, amrld_serialization=True) + +print(f'\n *** TEST RESULT ***') +for amr_graph in amr_graph_list: + print(f'\n{amr_graph}') \ No newline at end of file