Skip to content

Commit

Permalink
include tablify demo in example
Browse files Browse the repository at this point in the history
  • Loading branch information
gschnabel committed Sep 5, 2022
1 parent 6079426 commit f03de70
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions examples/example-002-transformer-demo.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit f03de70

Please sign in to comment.