schema_compare

Functions

compare_differences(schema1, schema2[, ...])

Compare the tags in two schemas, this finds any differences

compare_schemas(schema1, schema2[, ...])

Compare two schemas section by section.

find_matching_tags(schema1, schema2[, ...])

Compare the tags in two library schemas.

compare_differences(schema1, schema2, output='raw', attribute_filter=None, sections=(<HedSectionKey.Tags: 'tags'>, ), include_summary=True)[source]

Compare the tags in two schemas, this finds any differences

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • output (str) – ‘raw’ (default) returns a tuple of python object dicts with raw results. ‘string’ returns a single string ‘dict’ returns a json-style python dictionary that can be converted to JSON

  • attribute_filter (str, optional) – The attribute to filter entries by. Entries without this attribute are skipped. The most common use would be HedKey.InLibrary If it evaluates to False, no filtering is performed.

  • sections (list or None) – the list of sections to compare. By default, just the tags section. If None, checks all sections including header, prologue, and epilogue.

  • include_summary (bool) – If True, adds the ‘summary’ dict to the dict return option, and prints it with the string option. Lists the names of all the nodes that are missing or different.

Returns:

  • Tuple with dict entries (not_in_schema1, not_in_schema1, unequal_entries).

  • Formatted string with the output ready for printing.

  • A Python dictionary with the output ready to be converted to JSON (for web output).

Return type:

tuple, str or dict

Notes: The underlying dictionaries are:
  • not_in_schema1(dict): Entries present in schema2 but not in schema1.

  • not_in_schema2(dict): Entries present in schema1 but not in schema2.

  • unequal_entries(dict): Entries that differ between the two schemas.

compare_schemas(schema1, schema2, attribute_filter='inLibrary', sections=(<HedSectionKey.Tags: 'tags'>, ))[source]

Compare two schemas section by section. The function records matching entries, entries present in one schema but not in the other, and unequal entries.

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • attribute_filter (str, optional) – The attribute to filter entries by. Entries without this attribute are skipped. The most common use would be HedKey.InLibrary If it evaluates to False, no filtering is performed.

  • sections (list) – the list of sections to compare. By default, just the tags section. If None, checks all sections including header, prologue, and epilogue.

Returns: tuple: A tuple containing four dictionaries:

  • matches(dict): Entries present in both schemas and are equal.

  • not_in_schema1(dict): Entries present in schema2 but not in schema1.

  • not_in_schema2(dict): Entries present in schema1 but not in schema2.

  • unequal_entries(dict): Entries present in both schemas but are not equal.

find_matching_tags(schema1, schema2, output='raw', sections=(<HedSectionKey.Tags: 'tags'>, ), include_summary=True)[source]

Compare the tags in two library schemas. This finds tags with the same term.

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • output (str) – Defaults to returning a python object dicts. ‘string’ returns a single string ‘dict’ returns a json style dictionary

  • sections (list) – the list of sections to compare. By default, just the tags section. If None, checks all sections including header, prologue, and epilogue.

  • include_summary (bool) – If True, adds the ‘summary’ dict to the dict return option, and prints it with the string option. Lists the names of all the nodes that are missing or different.

Returns:

A dictionary containing matching entries in the Tags section of both schemas.

Return type:

dict, json style dict, or str