json2graph.modules.utils_graph

Util functions related to graphs.

Module Contents

Functions

ontouml_ref(entity)

Receive the name of the OntoUML Vocabulary's entity as a string and returns the corresponding URIRef.

load_ontouml_vocabulary([enable_remote])

Load the OntoUML Vocabulary to the working memory.

load_graph_safely(ontology_file[, out_format])

Safely load graph from file to working memory using arguments provided by the user, which are the file path and (optionally) the file type.

fix_uri(url_string)

Received a valid URL, but invalid URI string and converts to a valid URL and valid URI string.

rename_uriref_resource(graph, old_resource, new_resource)

Rename a URIRef resource of an RDF graph by replacing it to a new one with a different name.

Attributes

LOGGER

json2graph.modules.utils_graph.LOGGER
json2graph.modules.utils_graph.ontouml_ref(entity)

Receive 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

json2graph.modules.utils_graph.load_ontouml_vocabulary(enable_remote=False)

Load the OntoUML Vocabulary to the working memory.

If the argument enable_remote is enabled (i.e., equals True), it 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.

If the argument enable_remote is disabled, the function tries to load form the local resource and if fails, it calls the error reporting function.

The enable_remote is disabled by default as it can significantly decrease the software performance. However, using it can guarantee that the most recent version of vocabulary is always used.

Parameters:

enable_remote (bool) – Controls if the software will try to get the ontouml vocabulary ttl file from a remote source.

Returns:

RDFLib graph loaded as object.

Return type:

Graph

json2graph.modules.utils_graph.load_graph_safely(ontology_file, out_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.

  • out_format (str) – Optional argument. Format of the file to be loaded.

Returns:

RDFLib graph loaded as object.

Return type:

Graph

json2graph.modules.utils_graph.fix_uri(url_string)

Received a valid URL, but invalid URI string and converts to a valid URL and valid URI string.

This function takes a URL string, parses it, encodes non-URI characters, and reconstructs a valid URI.

Parameters:

url_string (str) – The URL string to be fixed.

Returns:

The resulting valid URI string.

Return type:

str

json2graph.modules.utils_graph.rename_uriref_resource(graph, old_resource, new_resource)

Rename a URIRef resource of an RDF graph by replacing it to a new one with a different name.

Parameters:
  • graph (Graph) – The RDF graph that contains the resource to be renamed.

  • old_resource (URIRef) – The old resource to be replaced.

  • new_resource (URIRef) – The new resource to replace the old one.

Returns:

None

Return type:

None