json2graph.modules package
Subpackages
- json2graph.modules.decoder package
- Submodules
- json2graph.modules.decoder.decode_general module
- json2graph.modules.decoder.decode_main module
- json2graph.modules.decoder.decode_obj_class module
create_class_properties()set_class_attribute_property()set_class_attributes()set_class_literal_literal()set_class_order_nonnegativeinteger()set_class_restrictedto_ontologicalnature()set_class_stereotype()set_defaults_class_attribute()set_defaults_class_order()validate_class_attribute_constraints()validate_class_order_constraints()
- json2graph.modules.decoder.decode_obj_diagram module
- json2graph.modules.decoder.decode_obj_elementview module
- json2graph.modules.decoder.decode_obj_generalization module
- json2graph.modules.decoder.decode_obj_generalizationset module
- json2graph.modules.decoder.decode_obj_package module
- json2graph.modules.decoder.decode_obj_path module
- json2graph.modules.decoder.decode_obj_project module
- json2graph.modules.decoder.decode_obj_property module
- json2graph.modules.decoder.decode_obj_rectangularshape module
- json2graph.modules.decoder.decode_obj_relation module
- Module contents
Submodules
json2graph.modules.arguments module
Argument Treatments Module.
This module provides functions for parsing and validating user-provided arguments when starting the software execution as a script.
It also makes the ARGUMENTS variable globally accessible with the user’s arguments (when executed as a script) or with default values (when executed as test or as a library).
- json2graph.modules.arguments.initialize_arguments(json_path='not_initialized', base_uri='https://example.org#', graph_format='ttl', language='', model_only=False, silent=True, correct=False, execution_mode='import')
This function initializes the global variable ARGUMENTS of type dictionary, which contains user-provided (when executed in script mode) or default arguments (when executed as a library or for testing). The ARGUMENTS variable must be initialized in every possible execution mode.
The valid execution modes are: - ‘script’: If used as a script, use user’s arguments parsed from the command line. - ‘package’: When imported into external code, working as a library package. - ‘test’: Used for testing.
- Parameters:
json_path (str) – Path to the JSON file to be decoded provided by the user. (Optional)
base_uri (str) – Base URI to be used for generating URIs for ontology concepts.
graph_format (str) –
language (str) –
model_only (bool) –
silent (bool) –
correct (bool) –
execution_mode (str) –
Default is “https://example.org#”. (Optional) :type base_uri: str :param graph_format: Format for saving the resulting knowledge graph. Default value is ‘ttl’ (Turtle syntax). (Optional) :type graph_format: str :param language: Language tag to be added to the ontology’s concepts. (Optional) :type language: str :param model_only: If True, only the OntoUML model will be extracted without diagrammatic information. (Optional) :type model_only: bool :param silent: If True, suppresses intermediate communications and log messages during execution. (Optional) :type silent: bool :param correct: If True, attempts to correct potential errors during the conversion process. (Optional) :type correct: bool :param execution_mode: Information about the execution mode. Valid values are ‘import’ (default), ‘script’, and ‘test’. (Optional) :type execution_mode: str
- json2graph.modules.arguments.treat_user_arguments()
This function parses the command-line arguments provided by the user and performs necessary validations.
- Returns:
Dictionary with json path (key ‘json_path’) and final file format (key ‘format’).
- Return type:
dict
json2graph.modules.errors module
Functions related to the verification and treatment of identified ERROR cases.
- json2graph.modules.errors.report_error_end_of_switch(invalid_parameter, caller_function_name)
Reports the error caused when an invalid parameter is provided to a switch case (if-else statements). Used to validate parameters.
NOTE: caller_function_name can be obtained from ‘current_function = inspect.stack()[0][3]’
- Parameters:
invalid_parameter (str) – Invalid function parameter that caused the error.
caller_function_name (str) – Name of the function in which the invalid parameter was used.
- Raises:
ValueError – Always.
- Return type:
None
- json2graph.modules.errors.report_error_io_read(desired_content, file_description, error)
Reports the error caused program cannot read or load the desired content (test_files or directories).
- Parameters:
desired_content (str) – Name of the file used by the IO operation caused the error.
file_description (str) – Description of the file in desired_content.
error (OSError) – Error raised by the IO operation.
- Raises:
OSError – Always.
- Return type:
None
- json2graph.modules.errors.report_error_io_write(desired_content, file_description, error)
Reports the error caused program cannot save or write the desired content (test_files or directories).
- Parameters:
desired_content (str) – Name of the file used by the IO operation caused the error.
file_description (str) – Description of the file in desired_content.
error (OSError) – Error raised by the IO operation.
- Raises:
OSError – Always.
- Return type:
None
- json2graph.modules.errors.report_error_requirement_not_met(error_message)
Reports the error caused when a requirement is not met. As this is a generic function, the error message parameter must be used to identify the error to the user.
- Parameters:
error_message (str) – Message to be printed to the user indicating the detected error.
- Raises:
ValueError – Always.
- Return type:
None
json2graph.modules.globals module
Global variables definitions.
json2graph.modules.input_output module
IO functions used in diverse occasions.
- json2graph.modules.input_output.create_directory_if_not_exists(directory_path, file_description)
Checks if the directory that has the path received as argument exists. If it does, do nothing. If it does not, create it.
- Parameters:
directory_path (str) – Path to the directory to be created (if it does not exist).
file_description (str) –
- Return type:
None
- json2graph.modules.input_output.safe_load_json_file(json_path)
Safely loads the JSON file inputted by the user as an argument into a dictionary.
- Parameters:
json_path (str) – Path to the JSON file to be loaded.
- Returns:
Dictionary with loaded JSON’s data.
- Return type:
dict
- json2graph.modules.input_output.safe_write_graph_file(ontouml_graph, output_file_path, syntax)
Safely saves the graph into a file in the informed destination with the desired syntax.
- Parameters:
ontouml_graph (Graph) – Graph compliant with the OntoUML Vocabulary.
output_file_path (str) – Complete path of the output file to be created (including name and extension).
syntax (str) – Syntax to be used for saving the ontology file.
- Return type:
None
json2graph.modules.logger module
This module provides functions for configuring a logger that outputs messages to both the console and a log file. The logger can be customized based on different execution modes, allowing you to control the log level.
- json2graph.modules.logger.initialize_logger(execution_mode='script')
Create and initialize logger. The created logger is called ‘execution-logger’. Different triggers are defined for each execution mode:
script: INFO
import: ERROR
test: ERROR
- Parameters:
execution_mode (str) – Information about execution mode. Valid values are ‘script’, ‘import’ and ‘test’.
- Returns:
Created logger called ‘execution-logger’.
- Return type:
logging.Logger
- json2graph.modules.logger.logger_get_date_time()
Return a string in a specified format with date and time.
- Returns:
Formatted date and time. Format example: 2022.10.23-14.43
- Return type:
str
json2graph.modules.messages module
Decoding messages to be displayed to users must be concentrated in this module whenever possibile.
- json2graph.modules.messages.get_decode_log_message(object_dict, warning_code, property_name, att_valid_stereotype='')
Mounts and returns a warning message according to the information received as parameter.
- Parameters:
object_dict (dict) – Object’s JSON data loaded as a dictionary.
warning_code (str) – Code used to select the correct message to be displayed to the user if not in silent mode.
property_name (str) – Information about a property or attribute type to be displayed in a warning message. Optional.
att_valid_stereotype (str) – Stereotype associated to an attribute to be displayed in a warning message. Optional.
- Returns:
Warning message containing information about the modification made to be printed to user.
- Return type:
str
- json2graph.modules.messages.print_decode_log_message(object_dict, warning_code, property_name='', att_valid_stereotype='')
Gets warning message and prints it to the user as a log if not in silent mode.
- Parameters:
object_dict (dict) – Object’s JSON data loaded as a dictionary.
warning_code (str) – Predefined warning number to be displayed to the user if not in silent mode.
property_name (str) – Information about a property or attribute type to be displayed in a warning message. Optional.
att_valid_stereotype (str) – Optional attribute’s stereotype to be displayed in a warning message.
- Return type:
None
json2graph.modules.sparql_queries module
All SPARQL queries used for decoding the JSON.
json2graph.modules.utils_general module
Diverse util and auxiliary functions.
- json2graph.modules.utils_general.count_elements_types(element_type_list, element_counting)
Returns the number of elements (in the already counted data) of the types given in a list. Receives a dictionary of number of items and returns the value corresponding to the provided argument.
- Parameters:
element_type_list (list[str]) – List of types of elements to have their count value returned.
element_counting (dict) – Dictionary with types and corresponding number of occurrences.
- Returns:
Number of occurrences of the element of the given type.
- Return type:
int
- json2graph.modules.utils_general.get_date_time(date_time_format)
Return a string with date and time according to the specified format received as argument. For valid formats: https://docs.python.org/3.11/library/datetime.html#strftime-and-strptime-format-codes
- Parameters:
date_time_format (str) – Valid format accepted by the datetime function.
- Returns:
Formatted current date and time.
- Return type:
str
json2graph.modules.utils_graph module
Util functions related to graphs.
- json2graph.modules.utils_graph.get_all_ids_for_type(ontology_graph, element_type)
Queries the graph for all elements of the given element_type and returns a list of their ids.
- Parameters:
ontology_file (Graph) – Loaded ontology graph.
element_type (list[str]) – Type of the element (originally a JSON object) to be queried to have their ids returned .
ontology_graph (Graph) –
- Return type:
list[str]
- json2graph.modules.utils_graph.load_graph_safely(ontology_file, format='not_provided')
Safely load graph from file to working memory using arguments provided by the user, which are the file path and (optionally) the file type.
- Parameters:
ontology_file (str) – Path to the ontology file to be loaded into the working memory.
format (str) – Optional argument. Format of the file to be loaded.
- Returns:
RDFLib graph loaded as object.
- Return type:
Graph
- json2graph.modules.utils_graph.load_ontouml_vocabulary()
Loads the OntoUML Vocabulary to the working memory. First tries to load from web resource, if fails, it tries to load form the local resource. If both options fail, calls error reporting function.
- Returns:
RDFLib graph loaded as object.
- Return type:
Graph
- json2graph.modules.utils_graph.ontouml_ref(entity)
Receives the name of the OntoUML Vocabulary’s entity as a string and returns the corresponding URIRef.
- Parameters:
entity (str) – OntoUML Vocabulary entity (class, property, or individual) to have its URIRef returned.
- Returns:
URIRef of the informed OntoUML Vocabulary’s entity.
- Return type:
URIRef