Parser Functions#
The following functions can be used to create the final TOML parser file
- autoparser.create_parser(mappings: DataFrame | str, schema_path: Path, parser_name: str, description: str | None = None, config='config/autoparser.toml')
Takes the csv mapping file created by create_mapping and writes out a TOML parser
Generates a TOML parser for use with ADTL from the intermediate CSV file generated by create_mapping. This will generate a TOML file that can be used to parse raw data into the format expected by the schema.
- Parameters:
mappings – Path to the CSV file containing the mappings
schema_path – Path to the schema file
parser_name – Name of the parser to create
description – Description of the parser. Defaults to the parser name.
config – Path to the configuration file to use. Default is config/autoparser.toml.
- Return type:
None
Class definitions#
You can also interact with the base class parserGenerator
- class autoparser.ParserGenerator(mappings: DataFrame | str | Path, schema_path: Path | str, parser_name: str, description: str | None = None, config: Path | None = None, transformation_tool: str = 'ADTL')#
Class for creating a TOML parser from an intermediate CSV file.
Use create_parser() to write out the TOML parser file, as the function equivalent of the command line create-parser script.
- Parameters:
mappings (pd.DataFrame | str | Path) – The intermediate CSV file created by create_mapping.py
schema_path (Path | str) – The path to the folder containing all the schema files
parser_name (str) – The name of the parser
description (str, optional) – The description of the parser
config (Path, optional) – The path to the configuration file to use if not using the default configuration
transformation_tool ("ADTL") – The transformation tool which will use the generated parser to convert data (only ADTL is currently supported)
- create_parser(file_name: str = None)#
Main function to create the TOML parser from the intermediate CSV file.
- make_toml() dict[str, Any]#
Takes the csv mapping file from create_mapping and writes out a TOML parser
Generates a TOML parser for use with ADTL using the intermediate CSV file from by create_mapping. This will generate a TOML file that can be used to parse raw data into the format expected by the schema.
- Returns:
Dictionary containing the TOML parser data, ready to be written out.
- Return type:
dict
- make_toml_table(table: str) dict[str, Any]#
Make single TOML table from mappings
- property parsed_choices: Series#
Returns the mapped values for each taget field
- property references_definitions: tuple[dict[str, str], dict[str, dict]]#
Finds and returns the references and definitions for the mappings
- schema_fields(table: str)#
Returns all the fields for table and their properties
- single_field_mapping(match: DataFrame) dict[str, Any]#
Make a single field mapping from a single row of the mappings dataframe
- write_toml(data: dict[str, Any], output: str = None)#
Write a dictionary structure to a TOML file, using output as the filename if provided.
- Parameters:
data (dict) – Dictionary containing the TOML parser data
output (str, optional) – Filename to write the TOML data to. Defaults to the name of the parser.