Package: sciencebeam-utils
ScienceBeam UtilsProvides utility functions related to theScienceBeamproject.Please refer to thedevelopment documentationif you wish to contribute to the project.Most tools are not yet documented. Please feel free to browse the code or tests, or raise an issue.Pre-requisitesPython 3Apache BeamApache Beammay be used to for preprocessing but also its transparent FileSystems API which makes it easy to access files in the cloud.Installpipinstallapache_beam[gcp]pipinstallsciencebeam-utilsCLI ToolsFind File PairsThe preferred input layout is a directory containing a gzipped pdf (.pdf.gz) and gzipped xml (.nxml.gz), e.g.:manuscript_1/manuscript_1.pdf.gzmanuscript_1.nxml.gzmanuscript_2/manuscript_2.pdf.gzmanuscript_2.nxml.gzUsing compressed files is optional but recommended to reduce file storage cost.The parent directory per manuscript is optional. If that is not the case then the name before the extension must be identical (which is recommended in general).Run:python-msciencebeam_utils.tools.find_file_pairs\--data-path<sourcedirectory>\--source-pattern*.pdf.gz--xml-pattern*.nxml.gz\--out<outputfilelistcsv/tsv>e.g.:python-msciencebeam_utils.tools.find_file_pairs\--data-pathgs://some-bucket/some-dataset\--source-pattern*.pdf.gz--xml-pattern*.nxml.gz\--outgs://some-bucket/some-dataset/file-list.tsvThat will create the TSV (tab separated) filefile-list.tsvwith the following columns:source_urlxml_urlThat file could also be generated using any other preferred method.Split File ListTo separate the file list into atraining,validationandtestdataset, the following script can be used:python-msciencebeam_utils.tools.split_csv_dataset\--input<csv/tsvfilelist>\--train0.5--validation0.2--test0.3--random--fille.g.:python-msciencebeam_utils.tools.split_csv_dataset\--inputgs://some-bucket/some-dataset/file-list.tsv\--train0.5--validation0.2--test0.3--random--fillThat will create three separate files in the same directory:file-list-train.tsvfile-list-validation.tsvfile-list-test.tsvThe file pairs will be randomly selected (--random) and one group will also include all remaining file pairs that wouldn't get include due to rounding (--fill).As with the previous step, you may decide to use your own process instead.Note: those files shouldn't change anymore once you used those filesGet Output FilesSince ScienceBeam is intended to convert files, there will be output files. To make it specific what the filenames are,
the output files are also kept in a file list. This tool will generate the file list (it doesn't matter whether the files actually exist for this purpose).e.g.python-msciencebeam_utils.tools.get_output_files\--source-file-listpath/to/source/file-list-train.tsv\--source-file-column=source_url\--output-file-suffix=.xml\--output-file-listpath/to/results/file-list.lstBy adding the--checkargument, it will check whether the output files exist (see below).Check File ListAfter generating an output file list, this tool can be used whether the output files exist or are complete.e.g.python-msciencebeam_utils.tools.check_file_list\--file-listpath/to/results/file-list.lst\--file-column=source_url\--limit=100This will check the first 100 output files and report on it. The command will fail if none of the output files exist.