openschemas.main.map2model package

Submodules

openschemas.main.map2model.file_manager module

class openschemas.main.map2model.file_manager.FolderDigger(config_file_path=None)[source]

Bases: object

get_specification_list(input_folder, key='specifications')[source]

get a list of specifications based on those defined in the configuration.yml and then found in the specifications folder.

input_folder: the folder with subfolders of specifications key: the key to lookup in the configurations.yml (default is specifications)

get_specs(spec_config, input_folder)[source]
yml_config = ''

openschemas.main.map2model.mapping module

class openschemas.main.map2model.mapping.MappingParser(metadata=None)[source]

Bases: object

check_url(spec_url)[source]

check_url doesn’t exit if the address isn’t found, etc. it just adds the string “err_404” as metadata given these cases.

get_description(spec_file=None)[source]
get_mapping(spec_sheet=None, bioschemas_sheet=None)[source]

get a mapping, meanng the full properties given a specification sheet and a bioschemas sheet. If files aren’t provided, the defaults defined at self.defaults.paths are used.

spec_sheet: the sheet with basic information (description, name, etc.) bioschemas_sheet: sheet (tsv) with bioschemas fields

metadata = {}
set_metadata(metadata)[source]
openschemas.main.map2model.mapping.get_dict_from_row(row, headers)[source]

a row is typically a list of values, assigned to another list of headers. this function parses a known set of headers and enters them into the expected values for bioschemas attributes. We return a dict.

row: the row (list) of values from the bioschemas tsv file headers: the headers that are expected (already validated)

openschemas.main.map2model.mapping.get_expected_types(expected_types)[source]

Function that receives an string with expected types and generates an array with each expected type

openschemas.main.map2model.mapping.get_formatted_props(sdo_props, mapping_props, spec_name, spec_type)[source]

This function combines the parsed mapping properties (importantly, mapping_props needs to “parent” field added) with the properties from the standard ontology

::Note: this function needs testing for a type

sdo_props: standard ontology (shared) properties mapping_props: result from get_mapping_properties (bioschemas_file) spec_name: the name of the specification (specification_file) spec_type: the type of the specification (specification_file)

openschemas.main.map2model.mapping.get_hierarchy(props_dic)[source]
openschemas.main.map2model.mapping.get_mapping_properties(bioschemas_file)[source]

use the bioschemas field file and the specification type to return a list of type properties. The bioschemas file should already be validated for correct headers.

bioschemas_file: the <Template> - Bioschemas.tsv file

openschemas.main.map2model.mapping.get_properties_in_hierarchy(type_name)[source]
openschemas.main.map2model.mapping.get_property_in_hierarchy(sdo_props, mapping_property, prop_type='new_sdo')[source]

if a mapping property (indexed by its name, which is key “property”) if found as a key in sdo_props at a particular entity (e.g., Thing) then we’ve found it in the sdo, and grab it’s description for use from the sdo. If we don’t find it, we return the type as a “new_sdo”

openschemas.main.map2model.mapping.get_row_value(field, row, headers, default='', clean=True)[source]

get a value from a list based on a field name that is expected to appear in headers. This allows for change in the ordering of fields as long as the header is correctly labeled. The default value of an empty string is returned, and we clean by stripping spaces and newlines.

field: the field to look up row: the row (list) of values headers: the list of field names (header of the tsv file) to match field default: the default value to return, if not found clean: boolean to indicate wanting to strip newlines and spaces

openschemas.main.map2model.mapping.load_tsv(filename)[source]

load a tsv file using the csv default provided reader!

filename: the file name to load, will return list (rows) of lists (columns)

openschemas.main.map2model.parser module

class openschemas.main.map2model.parser.FrontMatterParser(input_folder='specifications', output_folder=None, config_file_path=None, template=None, repo=None)[source]

Bases: object

the FrontEndMatterParser takes an input folder of specification subfolders, and a configuration.yml file, and generates a set of specification folders, each with a <Specification>.html file that can be contributed as a specification to the openschemas.github.io repository.

parse_front_matter()[source]

the primary function to parse the provided front matter, the tsv files, and generate yml specifications from the templates

save_html_template(data, output_name, template_file=None)[source]

save an html template, meaning a jekyll template with {{OPENSCHEMAS_FRONTEND_MATTER}} to replace with front matter. If a template isn’t defined, the default provided by the package is used

template_file: the jekyll template to use, provided if not defined output_name: the name for the output file, should end in .html

openschemas.main.map2model.validator module

class openschemas.main.map2model.validator.FolderValidator(folder)[source]

Bases: object

validate(folder=None)[source]

validate runs each set of tests, and returns a list of results. If any validators fail, we return a False (failed) validation, otherwise True

validate_exists(folder=None)[source]

Ensure the folder exists

folder: full (or relative) path to folder

validate_extension(path, ext='tsv')[source]

Ensure the worksheet is a tsv file (default ends in tsv)

path: a name (string) of the worksheet file ext: the extension to check using “endswith”

validate_headers()[source]

Ensure that headers for specific files only conform to those required and expected

validate_paths(ext='tsv')[source]

Ensure that default files (self.defaults) exist in the folder (self.folder)

class openschemas.main.map2model.validator.WorksheetDefaults(name, folder=None)[source]

Bases: object

get_headers(key)[source]

get a headers list for a particular key in the names of defaults.

key: the key in the self.lookup to get default headers for

get_names()[source]
get_paths()[source]
load_name(name)[source]

load a tsv based on its name, the key in the self.paths lookup

name: the file key to load.

set_names(name, ext='tsv')[source]

define expected set of file names (basepath) based on Specification Name

name: the name of the specification

set_paths(folder=None)[source]

define expected set of file (fullpath) from names lookup with a folder name.

name: the name of the specification

Module contents

openschemas.main.map2model.main(config_yml=None, folder=None, output=None, template=None, repo=None)[source]

entrypoint function for map2model, when used by the openschemas client.

config: The configuration.yml. If not defined, defaults to that in PWD. folder: the input folder where specification subfolders are expected. If not defined, defaults to “specifications” output: the output folder for specification files. If not defined, defaults to “spec files” template: the template to use for the specification. Defaults to “template.html” provided by the module repo: the repository where the specification will be published. defaults to openschemas/specifications