json2graph.decoder.decode_general

General decoding functions.

Module Contents

Functions

create_point(point_id, x_coord, y_coord, ontouml_graph)

Create a new instance of ontouml:Point with its ontouml:xCoordinate, and ontouml:yCoordinate properties.

count_elements_graph(ontouml_graph)

Return a dictionary with all element types on graphs and their respective quantity.

get_stereotype(object_dict)

For coding reasons (dictionary index error), it is necessary to check if an object has its stereotype not set.

get_list_subdictionaries_for_specific_type(...[, ...])

Recursively access all objects in the dictionary until find an object of the desired type.

get_subdictionary_for_specific_id(dictionary_data, ...)

Recursively access all objects in the dictionary until find the desired ID.

get_all_ids_of_specific_type(dictionary_data, wanted_type)

Recursively access all objects in the dictionary and generates a list of all ids of objects for a given type.

clean_null_data(dictionary_data)

Remove all empty values (i.e., keys associated with None) from the received dictionary.

Attributes

LOGGER

json2graph.decoder.decode_general.LOGGER
json2graph.decoder.decode_general.create_point(point_id, x_coord, y_coord, ontouml_graph)

Create a new instance of ontouml:Point with its ontouml:xCoordinate, and ontouml:yCoordinate properties.

Parameters:
  • point_id (str) – ID of the new ontouml:Point instance to be created.

  • x_coord (int) – Horizontal coordinate of the new ontouml:Point.

  • y_coord (int) – Vertical coordinate of the new ontouml:Point.

  • ontouml_graph (Graph) – Knowledge graph that complies with the OntoUML Vocabulary.

Return type:

None

json2graph.decoder.decode_general.count_elements_graph(ontouml_graph)

Return a dictionary with all element types on graphs and their respective quantity.

Parameters:

ontouml_graph (Graph) – Knowledge graph with loaded objects’ ids and types

Returns:

Dictionary with types and respective quantities present on graph.

Return type:

dict

json2graph.decoder.decode_general.get_stereotype(object_dict)

For coding reasons (dictionary index error), it is necessary to check if an object has its stereotype not set.

Returns the evaluated object’s stereotype or ‘null’ when the stereotype is absent.

Parameters:

object_dict (dict) – Object loaded as a dictionary.

Returns:

Evaluated object’s stereotype or ‘null’ when the stereotype is absent.

Return type:

str

json2graph.decoder.decode_general.get_list_subdictionaries_for_specific_type(dictionary_data, wanted_type, return_list=None)

Recursively access all objects in the dictionary until find an object of the desired type.

When the type is found, adds a copy of its dictionaries to a list to be returned (containing all its sub-dictionaries).

Parameters:
  • dictionary_data (dict) – Dictionary to have its fields decoded.

  • wanted_type (str) – ID of the object to have its dictionary (including sub-dictionaries) returned.

  • return_list (list[dict]) – Optional. Searched dictionary to be returned. Used for recursion only.

Returns:

List of copy of the object’s dictionaries.

Return type:

list[dict]

json2graph.decoder.decode_general.get_subdictionary_for_specific_id(dictionary_data, wanted_id, return_dict=None)

Recursively access all objects in the dictionary until find the desired ID.

When the id is found, return a copy of its dictionary (containing all its sub-dictionaries).

Parameters:
  • dictionary_data (dict) – Dictionary to have its fields decoded.

  • wanted_id (str) – ID of the object to have its dictionary (including sub-dictionaries) returned.

  • return_dict (dict) – Optional. Searched dictionary to be returned. Used for recursion only.

Returns:

Copy of the object’s dictionary.

Return type:

dict

json2graph.decoder.decode_general.get_all_ids_of_specific_type(dictionary_data, wanted_type, list_ids_for_type=None)

Recursively access all objects in the dictionary and generates a list of all ids of objects for a given type.

Parameters:
  • dictionary_data (dict) – Dictionary to have its fields decoded.

  • wanted_type (str) – Name of the type of the objects to have their IDs identified.

  • list_ids_for_type (list[str]) –

Returns:

List of ids from all objects for a given type.

Return type:

list[str]

json2graph.decoder.decode_general.clean_null_data(dictionary_data)

Remove all empty values (i.e., keys associated with None) from the received dictionary.

If a value of the dictionary is another dictionary, this function recursively verify this sub-dictionary elements. I.e., all empty fields, from all dictionaries composing the main dictionary are also cleaned.

Parameters:

dictionary_data (dict) – Dictionary to have its empty fields cleaned.

Returns:

Dictionary without empty fields.

Return type:

dict