# 1.1.1. How to compare and merge set of JSON-LD-schemas: code documentation¶

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
_EntityCoverage__build_context_dict(schema_input)

A private method that associate each field in a schema to it’s semantic value in the context and reverse the result

Parameters: Return sorted_values: schema_input – a dictionary of semantic values and their corresponding field a list of fields that were ignored due to having no semantic value in the context file
static _EntityCoverage__compute_context_coverage(context1, context2)

Private method that compares the fields from the two schemas based on their semantic values

Parameters: Return local_overlap_value: context1 – the final output of __build_context_dict() for the first schema context2 – the final output of __build_context_dict() for the second schema a namedtuple containing relative and absolute coverage a dictionary that associate fields in schema 1 with their semantic twins in schema 2 a dictionary of all fields of the second schema that haven’t been matched in the first schema
static _EntityCoverage__process_field(field_name, field_value, context, comparator)

Private method that catches a given field semantic value from the given context and adds it to the output

Parameters: Return comparator: field_name – the name of the given field field_value – the value of the given field context – the context from which to retrieve the semantic value comparator – the output of __build_context_dict() a dictionary of semantic values and corresponding fields from the given schema and context
__init__(schema_a, context_a, schema_b, context_b)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

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.

Parameters: networks_array – an array containing the two networks to compare
static _NetworkCoverage__compute_coverage(network_a, network_b)

Private method that compute the coverage between two networks

Parameters: network_a – the output of __process_network for the first network network_b – the output of __process_network for the second network an array containing the twined entities, the number of processed entities and the number of twins between both networks
static _NetworkCoverage__process_network(network)

Private method that retrieve the base type of each entity in a given network for later comparison

Parameters: Return network_output: network – a dictionary of schemas and their context (the network itself) a dictionary of schemas and their base type retrieved from the context
__init__(networks_array)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

class fullDiff.FullDiffGenerator(first_network, second_network)[source]

A Full Diff Generator that use regex to recompose context files URLS. It then resolves the two given networks of schemas and the two given networks of contexts, then proceeds to the actual comparison

__init__(first_network, second_network)[source]
Parameters: first_network (dict) – the first network to compare from second_network (dict) – the second network to compare against
__weakref__

list of weak references to the object (if defined)

class fullDiff.FullSemDiff(contexts, network_1, network_2)[source]

A class that computes the coverage at entity level and extracts ‘semantic synonyms’ (named twins in the code) between two network. It will then compute the coverage at attribute level between ‘semantic synonyms’.

__init__(contexts, network_1, network_2)[source]

The class constructor

Parameters: contexts – an array containing the two context networks to use network_1 – a dictionary containing the first set of schemas network_2 – a dictionary containing the second set of schemas
__weakref__

list of weak references to the object (if defined)

class fullDiff.FullSemDiffMultiple(networks)[source]

A class that computes the coverage at entity level and extracts ‘semantic synonyms’ (named twins in the code) between multiple networks. It will then compute the coverage at attribute level between ‘semantic synonyms’.

__init__(networks)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

class mergeEntities.EntityMerge(schema1, context1, schema2, context2)[source]

A class that merge two schemas based on their semantic annotations

Parameters: schema1 – dictionary of the first schema context1 – dictionary of the first context as {“@context”:{}} schema2 – dictionary of the second schema context2 – dictionary of the second context as {“@context”:{}}
__init__(schema1, context1, schema2, context2)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

class mergeEntities.MergeEntityFromDiff(overlaps)[source]

A class that merges network2 into network1 based on overlaps from FullDiff

Parameters: overlaps – a variable containing
__init__(overlaps)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

add_schema(schema_name)[source]

Adds the schema to the merge

Parameters: schema_name –
find_references(field)[source]

Find $ref at root, in items or in allOf, anyOf, oneOf, adds the schema/context to the merge and change reference names Parameters: field (dict) – a schema field modify_references()[source] Modify the$ref names

save(base_url)[source]

Saves the merge to disk and replace “id” attribute with the given base url + schema name

Parameters: base_url –
validate_output()[source]

Validates the output of the merge