From f03de707c9c2714975791a59e5f216109a3415e8 Mon Sep 17 00:00:00 2001 From: gschnabel <40870991+gschnabel@users.noreply.github.com> Date: Sun, 4 Sep 2022 22:44:47 +0200 Subject: [PATCH] include tablify demo in example --- examples/example-002-transformer-demo.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/example-002-transformer-demo.py b/examples/example-002-transformer-demo.py index 5297baf..6442832 100644 --- a/examples/example-002-transformer-demo.py +++ b/examples/example-002-transformer-demo.py @@ -1,19 +1,24 @@ from pathlib import Path from exfor_parserpy import read_exfor, write_exfor -from exfor_parserpy.trafos import unitfy, uncommonfy, depointerfy, detextify +from exfor_parserpy.trafos import unitfy, uncommonfy, depointerfy, detextify, tablify import json TEST_DATA = Path(__file__).resolve().parents[1] / "tests" / "testdata" exfor_entry = read_exfor(TEST_DATA / "entry_21308.txt") +# convert the entry to a table +exfor_table = tablify(exfor_entry) +print(exfor_table) + # apply all transformations: unitfy, uncommonfy, depointerfy trafo_entry = unitfy(exfor_entry) trafo_entry = uncommonfy(trafo_entry) trafo_entry = depointerfy(trafo_entry) write_exfor("entry_21308_transformed1.txt", trafo_entry, overwrite=True) -# change the order and see if we get identical results +# change the order in which the transformer are applied +# and check if we get identical results trafo_entry = depointerfy(exfor_entry) trafo_entry = unitfy(trafo_entry) trafo_entry = uncommonfy(trafo_entry) @@ -29,6 +34,10 @@ trafo_entry = unitfy(exfor_entry) write_exfor("entry_23245_unitfy.txt", trafo_entry, overwrite=True) +# here we chain transformers before calling +# tablify to create a pandas DataFrame +exfor_table = tablify(unitfy(depointerfy(uncommonfy(exfor_entry)))) +print(exfor_table) # example with detextify transformer exfor_entry = read_exfor(TEST_DATA / "entry_T0408.txt")