Welcome to jsonldschema’s documentation!¶
Utilities for semantic comparison of JSON-LD-schemas¶
-
class
compareEntities.
EntityCoverage
(schema_a, context_a, schema_b, context_b)[source]¶ A class that compute the overlap between two JSON schemas semantic values taken from context files. This operation is not commutative. Thus, to find out if the schema/context pairs are equivalent, we need to run both semDiff(s_a, c_a, s_b, c_b) and semDiff(s_b, c_b, s_a, c_a)
Parameters: - schema_a – the content of the first schema
- context_a – the context content bound to the first schema
- schema_b – the content of the second schema
- context_b – the context content bound to the second schema
-
class
compareNetwork.
NetworkCoverage
(networks_array)[source]¶ This class compute the coverage of entities (schemas) among two networks (set of schemas) by comparing the semantic base type of each schema. :param networks_array: an array containing the two networks to compare
Utilities FOR PREPARING FUNCTIONS INPUT¶
Utilities to validate JSON-schemas and instances¶
-
jsonschema_validator.
validate_instance
(schemapath, schemafile, instancepath, instancefile, error_printing, store)[source]¶ Validate a JSON instance againsts a JSON schema.
-
jsonschema_validator.
validate_schema
(path, schema_file_name)[source]¶ Validate a JSON schema given the folder/path and file name of the schema file.
-
jsonschema_validator.
validate_schema_file
(schema_file)[source]¶ Validate a JSON schema given the schema file.
-
class
miflowcyt_validate.
FlowRepoClient
(mapping, base_schema, client_id)[source]¶ A class that provides functionality to download experiments from the FlowRepository (https://flowrepository.org/), transform the XML into JSON and validate the instances against their schema. The transformation from XML to JSON relies on the JSONBender library (https://github.com/Onyo/jsonbender).
-
static
get_mapping
(mapping_file_name)[source]¶ Build the mapping dictionary based on the given mapping file :param mapping_file_name: the name of the mapping file :return mapping: the mapping of the fields
-
get_user_content_id
(client_identifier)[source]¶ Return all IDs found in the user content XML :param client_identifier: the user content ID :return: a list of all IDs there were identified in the variable returned by the API
-
static
grab_experiment_from_api
(client_identifier, item_identifier)[source]¶ Retrieve the experimental metadata and return it as a python object :param client_identifier: the client identifier (apiKey) :param item_identifier: the item identifier that should be retrieved :return: the python object obtained from the XML
-
static
grab_user_content
(client_identifier)[source]¶ Grab all content for a given user ID as an XML and outputs it as a JSON. This method will grab all public experiments plus those only accessible to the user ID.
- Args:
- client_identifier: the user ID
- Returns
- response the dictionary containing the XML
-
make_validation
(number_of_items)[source]¶ Method to run the mapping for the given number of items
- Args
- number_of_items (int): the number of items to process
- Returns
- errors (dict): a dictionary containing the list of errors for all processed items
-
static
validate_instance_from_file
(instance, item_id, schema_name)[source]¶ Method to output the extracted JSON into a file and validate it against the given schema :param instance: the instance to output into a file :param item_id: the instance ID needed to create the file name :param schema_name: the schema to check against :return errors: a list of fields that have an error for this instance
-
static
-
class
miflowcyt_validate.
FlowRepoClient
(mapping, base_schema, client_id)[source] A class that provides functionality to download experiments from the FlowRepository (https://flowrepository.org/), transform the XML into JSON and validate the instances against their schema. The transformation from XML to JSON relies on the JSONBender library (https://github.com/Onyo/jsonbender).
-
static
get_mapping
(mapping_file_name)[source] Build the mapping dictionary based on the given mapping file :param mapping_file_name: the name of the mapping file :return mapping: the mapping of the fields
-
get_user_content_id
(client_identifier)[source] Return all IDs found in the user content XML :param client_identifier: the user content ID :return: a list of all IDs there were identified in the variable returned by the API
-
static
grab_experiment_from_api
(client_identifier, item_identifier)[source] Retrieve the experimental metadata and return it as a python object :param client_identifier: the client identifier (apiKey) :param item_identifier: the item identifier that should be retrieved :return: the python object obtained from the XML
-
static
grab_user_content
(client_identifier)[source] Grab all content for a given user ID as an XML and outputs it as a JSON. This method will grab all public experiments plus those only accessible to the user ID.
- Args:
- client_identifier: the user ID
- Returns
- response the dictionary containing the XML
-
make_validation
(number_of_items)[source] Method to run the mapping for the given number of items
- Args
- number_of_items (int): the number of items to process
- Returns
- errors (dict): a dictionary containing the list of errors for all processed items
-
static
validate_instance_from_file
(instance, item_id, schema_name)[source] Method to output the extracted JSON into a file and validate it against the given schema :param instance: the instance to output into a file :param item_id: the instance ID needed to create the file name :param schema_name: the schema to check against :return errors: a list of fields that have an error for this instance
-
static
CEDAR utilities¶
The CEDAR client will provide all the links the the CEDAR API functionnalities such as get, post and updates on templates, template elements, folders, instances ect …
-
class
client.
CEDARClient
[source]¶ A client for the CEDAR API
-
create_folder
(endpoint_type, api_key, target_folder_id, new_folder_name, new_folder_description)[source]¶ Create a folder with new_folder_name in the target_folder_id location
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- target_folder_id – (str) he CEDAR target folder’s ID where the new folder will be created
- new_folder_name – (str) the new folder name to create
- new_folder_description – (str) the new folder description to create
Returns: (dict) a request response
-
create_template
(endpoint_type, api_key, folder_id, template_file)[source]¶ Post a new schema to the selected folder id
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- folder_id – (str) the CEDAR target folder’s ID
- template_file – (str) the CEDAR target template’s ID
Returns: (dict) a request response
-
create_template_element
(endpoint_type, api_key, folder_id, template_resource)[source]¶ Create a new template element on the given server
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- folder_id – (str) the CEDAR target folder’s ID
- template_resource – (dict) the resource to post
Returns: (dict) a request response
-
delete_folder
(endpoint_type, api_key, folder_id)[source]¶ Delete a given folder from the server
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- folder_id – (str) the CEDAR target folder’s ID
Returns: (dict) a request response
-
get_folder_content
(endpoint_type, api_key, folder_id)[source]¶ Get the content of a folder from CEDAR
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- folder_id – (str) the CEDAR target folder’s ID
Returns: (dict) a request response
-
static
get_headers
(api_key)[source]¶ Method to build the HTTP request header
Parameters: api_key – (str) the API Key to your CEDAR account Returns: (dict) the HTTP headers
-
get_template_content
(endpoint_type, api_key, template_id)[source]¶ Get the content of a CEDAR template
Parameters: - endpoint_type – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- template_id – (str) the CEDAR target template’s ID
Returns: (dict) a request response
-
get_users
(endpoint_type, api_key)[source]¶ Method to get all users from the server
Parameters: - endpoint_type – (str) url to the CEDAR selected server
- api_key – (str) your CEDAR user API key
Returns: (dict) a request response
-
static
post
(url, parameter, headers, directory)[source]¶ Method to post data to the CEDAR selected server and log the process
Parameters: - url – (str) the URL to the selected server
- parameter – (dict) parameters of the HTTP request
- headers – (dict) the header required by the HTTP request
- directory – (str) the directory where to saved the log file
-
static
select_endpoint
(server_type)[source]¶ Method to select the server (prod or dev)
Parameters: server_type – (str) the type of server to select Returns: (str) the URL corresponding to the selected server
-
update_template
(endpoint_type, api_key, template_file)[source]¶ Update the content of template_file into the selected template
Parameters: - endpoint_type – (str) “staging” or “production”
- api_key – (str) your CEDAR user API key
- template_file – (str) the full path to a local template JSON file
Returns: (dict) a request response
-
upload_element
(server_alias, api_key, schema_file, remote_folder_id)[source]¶ Upload a template element to the server
Parameters: - server_alias – (str) the type of server to prompt
- api_key – (str) your CEDAR user API key
- schema_file – (str) the full path to a local template element JSON file
- remote_folder_id – (str) the CEDAR target folder’s ID
Returns: (dict) a request response
-
upload_resource
(api_key, request_url, resource)[source]¶ Upload the given resource to the CEDAR server
Parameters: - api_key – (str) your CEDAR user API key
- request_url – (str) the CEDAR server URL to post to
- resource – (dict) the resource to upload
Returns: (dict) a response text loaded as a dictionary
-
validate_element
(server_alias, api_key, element)[source]¶ Method to validate a CEDAR template element
Parameters: - server_alias – (str) the URL to run the validation from
- api_key – (str) your CEDAR user API key
- element – (dict) the resource to validate as a template
Returns: (dict) a request response
-
validate_instance
(server_address, api_key, instance)[source]¶ Method to validate a JSON instance against the corresponding resource on CEDAR
Parameters: - server_address – (str) the CEDAR server URL
- api_key – (str) your CEDAR user API key
- instance – (dict) the resource to validate as an instance
Returns: (dict) a request response
-
The schema2cedar classes will help you transform your JSON schemas draft 04 into compatible CEDAR schemas
-
class
schema2cedar.
Schema2CedarBase
[source]¶ The base converter class
Warning
This class should not be used! Use its children for converting to cedar template and template elements
-
static
json_pretty_dump
(json_object, output_file)[source]¶ Dump a given json in the given file
Parameters: Returns: the dumping result
Return type: string
-
static
set_prop_context
(schema)[source]¶ Set the required context for the properties attribute of the given schema
Parameters: schema – an input JSON schema Returns: the properties context required by CEDAR
-
static
set_properties_base_item
()[source]¶ Set the base properties required by CEDAR
Returns: the base property dictionary
-
static
set_required_item
(schema)[source]¶ Set the required items that a CEDAR schema needs for a given schema
Parameters: schema – the input schema Returns: the dictionary of required items
-
static
set_stripped_properties
(schema)[source]¶ Set the properties of a given schema
Parameters: schema – the input schema Returns: a dictionary of properties
-
static
set_sub_context
(schema)[source]¶ Set the context required by CEDAR for each individual attribute/field for a given schema
Parameters: schema – the input schema Returns: the dictionary of required context for each field
-
static
set_template_element_property_minimals
(sub_context, schema)[source]¶ Set the minimal elements of the properties attributes of a given schema and its sub-context
Parameters: - sub_context – the schema sub-context
- schema – the input schema
Returns: (dict) a dictionary of the required properties for CEDAR conversion
-
static
-
class
schema2cedar.
Schema2CedarTemplate
[source]¶ Schema 2 Template Converter, this is the one you want to use if you want to convert a schema into a template
-
class
schema2cedar.
Schema2CedarTemplateElement
[source]¶ Schema to TemplateElement converter.
Warning
Should only be used to convert schemas to template element. If you want to convert a schema to a template, use Schema2CedarTemplate (it will automatically create nested template elements for you)
-
convert_template_element
(input_json_schema, **kwargs)[source]¶ Method to convert a given schema into a CEDAR template element
Parameters: - input_json_schema – the input schema
- kwargs – optional parameter to provide the field name referencing that schema
Returns: the schema converted to a CEDAR template element
-
find_sub_specs
(schema, sub_spec_container)[source]¶ Inspect a given schema to find and load its schemas dependencies
Parameters: - schema – the input schema
- sub_spec_container – a container that will hold the dependencies
Return sub_spec_container: the filled container with the schema dependencies
-
static
load_sub_spec
(path_to_load, parent_schema, field_key)[source]¶ Load the given sub schema into memory
Parameters: - path_to_load – path to the sub schema
- parent_schema – the parent schema that this sub-schema is referenced from
- field_key – the parent schema field name that this sub-schema is referenced from
Returns: the string containing the loaded JSON schema
-