diff --git a/amrbatch/amrld/wk/__wk__.txt b/amrbatch/amrld/wk/__wk__.txt deleted file mode 100644 index 8d1c8b69c3fce7bea45c73efd06983e3c419a92f..0000000000000000000000000000000000000000 --- a/amrbatch/amrld/wk/__wk__.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/amrbatch/main.py b/amrbatch/main.py index a933ae0ddcae1cb3d7c610c5e85ae3c2b37a9b06..f1de389c026d42baf5d8b8a1a71b213a7b458402 100644 --- a/amrbatch/main.py +++ b/amrbatch/main.py @@ -26,7 +26,6 @@ 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) @@ -157,51 +156,32 @@ def __generate_amr_graph_files(filepath_manager, workdata_list): # Serialization Steps #============================================================================== -def __serialize_amr_graph_to_rdf_triple(filepath_manager, data): - """ Serialize AMR graph to AMR-RDF triple """ +def __serialize_amr_graph_to_amr_rdf(filepath_manager, data): + logger.info("-- Serialize AMR graphs to RDF using amr-ld library") # -- Filepath - input_file = data.get_penman_amr_graph_output_filepath() - input_amrld_file = data.get_amr_graph_amrld_filepath() - output_amrld_file = data.get_amr_rdf_amrld_filepath() - input_wk_file = data.get_amr_graph_wk_filepath() - output_wk_file = data.get_amr_rdf_wk_filepath() - amr_triple_file = data.get_amr_rdf_triple_output_filepath() - amr_turtle_file = data.get_amr_rdf_turtle_output_filepath() + amr_penman_filepath = data.get_penman_amr_graph_output_filepath() + amr_rdf_triple_filepath = data.get_amr_rdf_triple_output_filepath() + amr_rdf_turtle_filepath = data.get_amr_rdf_turtle_output_filepath() + logger.debug(f'----- AMR filepath (penman): {amr_penman_filepath}') + logger.debug(f'----- AMR-RDF filepath (triple): {amr_rdf_triple_filepath}') + logger.debug(f'----- AMR-RDF filepath (turtle): {amr_rdf_turtle_filepath}') # -- 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) + amrld_process = ["python3", "amr_to_rdf.py", "-i", amr_penman_filepath, "-o", amr_rdf_triple_filepath] + if (os.path.isfile(amr_penman_filepath)): current_dirpath = os.getcwd() os.chdir(AMRLD_DIR) subprocess.run(amrld_process) os.chdir(current_dirpath) - - # -- File Generation (AMR-RDF triple) - 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) - + logger.info(f'----- AMR-RDF triple successfully processed ({os.path.basename(amr_rdf_triple_filepath)})') -def __convert_rdf_triple_to_rdf_turtle(filepath_manager, data): - """ Converting AMR-RDF triple to AMR-RDF turtle """ - - # -- Filepath - amr_triple_file = data.get_amr_rdf_triple_output_filepath() - amr_turtle_file = data.get_amr_rdf_turtle_output_filepath() - - # -- Conversion - if (os.path.isfile(amr_triple_file)): - logger.info(f'-- Generating AMR RDF file (turtle): {os.path.basename(amr_turtle_file)}') + # -- Turtle Conversion + if (os.path.isfile(amr_rdf_triple_filepath)): g = Graph() - g.parse(amr_triple_file) - g.serialize(destination=amr_turtle_file, format='turtle') + g.parse(amr_rdf_triple_filepath) + g.serialize(destination=amr_rdf_turtle_filepath, format='turtle') + logger.info(f'----- AMR-RDF triple successfully processed ({os.path.basename(amr_rdf_turtle_filepath)})') @@ -248,20 +228,18 @@ def parse_document_file_to_produce_amr_graph( # -- 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") + logger.info("-- library: amrld") + logger.debug(f' ({AMRLD_DIR})') for data in workdata_list: - __serialize_amr_graph_to_rdf_triple(filepath_manager, data) - __convert_rdf_triple_to_rdf_turtle(filepath_manager, data) + __serialize_amr_graph_to_amr_rdf(filepath_manager, data) # -- Getting AMR graph list amr_graph_list = [] diff --git a/tests/amrbatch.log b/tests/amrbatch.log index 8d54e482b7fa9c29bfa88212f39e7a43617590bb..a8ae492e043f223eb3dd6359da92f487cf5c674c 100644 --- a/tests/amrbatch.log +++ b/tests/amrbatch.log @@ -6,19 +6,17 @@ - INFO - -- output dirpath: /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/ - INFO - -- Reading input files to recover a list of sentences - DEBUG - *** sentence 1 *** -<work_data.WorkData object at 0x7f2eb8095660> +<work_data.WorkData object at 0x7f2e2f30a740> - DEBUG - *** sentence 2 *** -<work_data.WorkData object at 0x7f2eb8097670> +<work_data.WorkData object at 0x7f2e2f30bd00> - INFO - ----- number of sentences: 2 - DEBUG - -- Making output directory tree (/home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/) - 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 @@ -35,14 +33,17 @@ - DEBUG - ----- AMR Graph file (png): {os.path.basename(good_png_fn)} - INFO - === AMR Graphs Serialization to AMR-RDF Representation === -- INFO - -- library: amrlk +- INFO - -- library: amrld +- DEBUG - (/home/lamenji/Workspace/Tetras/amrbatch/amrbatch/amrld/) - INFO - -- Serialize AMR graphs to RDF using amr-ld library -- DEBUG - ----- penman filepath: /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/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 +- DEBUG - ----- AMR filepath (penman): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-01/test-01.stog.amr.penman +- DEBUG - ----- AMR-RDF filepath (triple): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-01/test-01.stog.amr.nt +- DEBUG - ----- AMR-RDF filepath (turtle): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-01/test-01.stog.amr.ttl +- INFO - ----- AMR-RDF triple successfully processed (test-01.stog.amr.nt) +- INFO - ----- AMR-RDF triple successfully processed (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-20230306/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 +- DEBUG - ----- AMR filepath (penman): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-02/test-02.stog.amr.penman +- DEBUG - ----- AMR-RDF filepath (triple): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-02/test-02.stog.amr.nt +- DEBUG - ----- AMR-RDF filepath (turtle): /home/lamenji/Workspace/Tetras/amrbatch/tests/output/Test-20230306/test-02/test-02.stog.amr.ttl +- INFO - ----- AMR-RDF triple successfully processed (test-02.stog.amr.nt) +- INFO - ----- AMR-RDF triple successfully processed (test-02.stog.amr.ttl) diff --git a/tests/output/Test-20230306/test-01/test-01.stog.amr.nt b/tests/output/Test-20230306/test-01/test-01.stog.amr.nt index 430dd5c7d9a506dedc220dd8d839558fb415d170..1850501006316f8eb5a96623cfa12b028e5cc2a0 100644 --- a/tests/output/Test-20230306/test-01/test-01.stog.amr.nt +++ b/tests/output/Test-20230306/test-01/test-01.stog.amr.nt @@ -1,22 +1,22 @@ -<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#Frame> <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://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/rdf/core-amr#AMR> . -<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/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . -<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#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-EntityType" . -<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#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . -<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#root> <http://amr.isi.edu/amr_data/test-01#s> . <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/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-sentence> "The sun is a star." . -<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/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/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/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#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . <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/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-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/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#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/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/2000/01/rdf-schema#label> "AMR-Role" . +<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/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/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#NamedEntity> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Term" . diff --git a/tests/output/Test-20230306/test-02/test-02.stog.amr.nt b/tests/output/Test-20230306/test-02/test-02.stog.amr.nt index cd76066b7046a48cf746823d48c067b7f38a9054..1d0ab2ad6417545dcfa25a2ec720bfe1a6f7d731 100644 --- a/tests/output/Test-20230306/test-02/test-02.stog.amr.nt +++ b/tests/output/Test-20230306/test-02/test-02.stog.amr.nt @@ -1,19 +1,19 @@ -<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/rdf/core-amr#Role> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-Role" . -<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#Frame> <http://www.w3.org/2000/01/rdf-schema#label> "AMR-PropBank-Frame" . +<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/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/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/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#NamedEntity> <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-02#p> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://amr.isi.edu/entity-types#planet> . +<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#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/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-02#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-02" . +<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/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/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/2000/01/rdf-schema#label> "AMR-EntityType" . -<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#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/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/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#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/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#NamedEntity> <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-02#root01> <http://amr.isi.edu/rdf/core-amr#has-id> "test-02" .