3.1. Utilities for preparing the input for the different functions

schema2context.create_and_save_contexts(mapping, semantic_types, write_to_file)[source]

Generates the context files for each schema in the given network and write these files to the disk

Parameters:
  • mapping (dict) – a file containing a mapping dict {“schemaName”: “schemaURL”}
  • semantic_types (dict) – a mapping dict of ontologies {“ontologyName”: “Ontology URL”}
  • write_to_file (str) – the directory absolute path to output the variables
Returns:

the resolved contexts

schema2context.create_context_template(schema, semantic_types, name)[source]

Create the context template

Parameters:
  • schema – the schema for which to build the context
  • semantic_types – the schema base type
  • name – the schema name
Returns:

a dictionary representing the schema context

schema2context.create_context_template_from_url(schema_url, semantic_types)[source]

Create a context template from the given URL

Parameters:
  • schema_url (str) – the schema URL
  • semantic_types (dict) – a dictionary with {“ontologyName”:”ontologyBaseURL”}
Returns:

a dictionary with a context variable for easy ontology

schema2context.create_network_context(mapping, semantic_types)[source]

Generates the context files for each schema in the given network

Parameters:
  • mapping (dict) – a file containing a mapping dict {“schemaName”: “schemaURL”}
  • semantic_types (dict) – a mapping dict of ontologies {“ontologyName”: “Ontology URL”}
Returns:

the resolved contexts

schema2context.generate_context_mapping(schema_url, regex_input)[source]

Resolves all schemas from given schema URL and creates the context mapping

Parameters:
  • schema_url (str) – a schema URL
  • regex_input (dict) – keys are the regex to locate and value the replace value
Returns:

a context mapping

schema2context.generate_context_mapping_dict(schema_url, regex_input, network_name)[source]

Generates the mapping dictionary used by full diff

Parameters:
  • schema_url (str) – the url of the main schema
  • regex_input (dict) – a set of regex to indicate how to transform schemas URL to contexts URL
  • network_name (str) – the name of the current network
Returns:

the mapping dictionary of schemas and contexts

schema2context.generate_contexts_from_regex(schema_url, regex_input)[source]

Creates the context URL for the given schema url based on given regex

Parameters:
  • schema_url (str) – a schema URL
  • regex_input (dict) – keys are the regex to locate and value the replace value
Returns:

a context URL

schema2context.generate_labels_from_contexts(contexts, labels)[source]

Generate labels from given context using OLS

Parameters:
  • contexts (dict) – a dictionary containing contexts associated to schema names
  • labels (dict) – pre-existing labels to avoid triggering twice the same query
Returns:

labels

schema2context.get_json_from_url(json_url)[source]

Gets the content of a json file from its URL - it can be a schema or a context file, or any other json file.

Parameters:json_url – a URL for a json file (e.g. a schema or a context file)
Returns:a dictionary with the json content
schema2context.prepare_input(schema_url, network_name)[source]

Enable to resolve all references from a given schema and create the output for create_network_context

Parameters:
  • schema_url (str) – url of the schema
  • network_name (str) – the name of the network
Returns:

a TextIOWrapper with the location of the mapping file

schema2context.process_schema_name(name)[source]

Extract the name out of a schema composite name by remove unnecessary strings

Parameters:name – a schema name
Returns:a string representing the processed schema

compile_schema.get_name(schema_url)[source]

Extract the item name from it’s URL

Parameters:schema_url – the URL of the schema
Return name:the name of the schema (eg: ‘item_schema.json’)
compile_schema.resolve_reference(schema_url)[source]

Load and decode the schema from a given URL

Parameters:schema_url – the URL to the schema
Returns:an exception or a decoded json schema as a dictionary
compile_schema.resolve_schema_references(schema, loaded_schemas, schema_url=None, refs=None)[source]

Resolves and replaces json-schema $refs with the appropriate dict. Recursively walks the given schema dict, converting every instance of $ref in a ‘properties’ structure with a resolved dict. This modifies the input schema and also returns it.

Parameters:
  • schema – the schema dict
  • loaded_schemas – a recursive dictionary that stores the path of already loaded schemas to prevent circularity issues
  • refs – a dict of <string, dict> which forms a store of referenced schemata
  • schema_url – the URL of the schema
Returns:

schema


prepare_fulldiff_input.load_context(context)[source]

Load the context variable from the given URL mapping

Parameters:context – a mapping of context URL
Returns:a context variable
prepare_fulldiff_input.prepare_input(schema_1_url, schema_2_url, mapping_1, mapping_2)[source]

Function to help preparing the full_diff input

Parameters:
  • schema_1_url – url of the first schema
  • schema_2_url – url of the second schema
  • mapping_1 – a mapping to contexts
  • mapping_2 – a mapping to contexts
Returns:

a fully prepared variable with all resolved references ready to be used by full_diff

prepare_fulldiff_input.resolve_network_url(schema_url)[source]

Function that triggers the resolved_schema_ref function

Parameters:schema_url – a schema URL
Returns:a fully resolved network
prepare_fulldiff_input.resolve_schema_ref(schema, resolver, network)[source]

Recursively resolves the references in the schemas and add them to the network

Warning

use resolve network instead

Parameters:
  • schema – the schema to resolve
  • resolver – the refResolver object
  • network – the network to add the schemas to
Returns:

a fully processed network with resolved ref