pyirk.visualization

This module contains code for the visualization of IRK-entities.

Module Contents

Classes

AbstractGraphObject

Common base class for nodes and edges

EntityNode

Container to represent a node in a networkx graph (for visualization)

LiteralStrNode

Edge

This class models the graphviz representation of an edge between two nodes

CustomizedDiGraph

Functions

key_generator

create_node

create_key_with_length

create_label_segments

Split label string into segments and assign a key to each. Return items.

create_nx_graph_from_entity

:param uri: :param url_template: :return:

get_color_for_item

get_color_for_stm

create_complete_graph

:param url_template: template to insert links based on uris :param limit: :return:

render_graph_to_dot

:param G: nx.DiGraph; the graph to render :return: dot_data

build_edge_color_map

svg_replace

visualize_entity

:param uri: entity uri (like “irk:/my/module#I0123”) :param url_template: url template for creation of a-tags (html links) for the labels :param write_tmp_files: boolean flag whether to write debug output

get_label

visualize_all_entities

render_label

Data

__all__

REL_BLACKLIST

REPLACEMENTS

NEWLINE_REPLACEMENTS

mpl_colors

label_segment_key_gen

literal_node_key_gen

relation_key_gen

API

pyirk.visualization.__all__

[‘visualize_entity’, ‘visualize_all_entities’]

pyirk.visualization.REL_BLACKLIST

(‘irk:/builtins#R1’, ‘irk:/builtins#R2’)

pyirk.visualization.REPLACEMENTS

None

pyirk.visualization.NEWLINE_REPLACEMENTS

[(’newline-center’, ‘\n’), (’newline-left’, ‘\l’)]

pyirk.visualization.mpl_colors

[‘#ff7f0e’, ‘#1f77b4’, ‘#2ca02c’, ‘#d62728’, ‘#9467bd’, ‘#8c564b’, ‘#e377c2’, ‘#7f7f7f’, ‘#bcbd22’, …

class pyirk.visualization.AbstractGraphObject

Bases: abc.ABC

Common base class for nodes and edges

Initialization

_perform_label_segmentation() None
    handle label formatting (segmentation into multiple lines and later wrapping by html tags)

    labels of Nodes should be centered (dot file should contain r"

“ between segments) however neither using “ “ nor r” “ inside the nxv-node-labels leads to the desired results thus: use a dummy which will be replaced later

__repr__() str
get_dot_label()
perform_html_wrapping(use_html=True) None

Assigns the segment key to the actual html-wrapped string. This pair will be used later by .format to modify the generated svg-data

This two-step process is necessary due to the internal escaping of the graph-viz rendering.

:return: None

pyirk.visualization.key_generator(template='k{:04d}')
pyirk.visualization.label_segment_key_gen

‘key_generator(…)’

pyirk.visualization.literal_node_key_gen

‘key_generator(…)’

pyirk.visualization.relation_key_gen

‘key_generator(…)’

class pyirk.visualization.EntityNode(entity: pyirk.Entity, url_template: str)

Bases: pyirk.visualization.AbstractGraphObject

Container to represent a node in a networkx graph (for visualization)

Initialization

get_dot_label(render=False) str
get_color() str
class pyirk.visualization.LiteralStrNode(arg: str)

Bases: pyirk.visualization.AbstractGraphObject

__repr__() str
get_dot_label()
class pyirk.visualization.Edge(relation: pyirk.Relation, url_template: str)

Bases: pyirk.visualization.AbstractGraphObject

This class models the graphviz representation of an edge between two nodes

Initialization

_perform_label_segmentation() None
get_dot_label()
get_color() str
pyirk.visualization.create_node(arg: Union[pyirk.Entity, object], url_template: str) pyirk.visualization.AbstractGraphObject
pyirk.visualization.create_key_with_length(basic_key_gen: callable, length: int) str
pyirk.visualization.create_label_segments(label: str, maxlen: int) Tuple[List[str], List[str]]

Split label string into segments and assign a key to each. Return items.

Examples:

  • I4321[“quite long label with many words”] -> [(“key0”, ‘I4321’), (“key1”, ‘[quite long label’), (“key2”, ‘with many words]’)]

    note: for the sake of brevity we skip quotes inside of […]

:param label: label string :param maxlen: maximum length of each line

:return: (keys, segments)

class pyirk.visualization.CustomizedDiGraph(incoming_graph_data=None, **attr)

Bases: networkx.DiGraph

add_node(node: pyirk.visualization.AbstractGraphObject, **kwargs)
pyirk.visualization.create_nx_graph_from_entity(uri, url_template='') networkx.DiGraph

:param uri: :param url_template: :return:

pyirk.visualization.get_color_for_item(item: pyirk.Item) str
pyirk.visualization.get_color_for_stm(stm: pyirk.Statement) str
pyirk.visualization.create_complete_graph(url_template='', limit: Optional[int] = None) networkx.DiGraph

:param url_template: template to insert links based on uris :param limit: :return:

pyirk.visualization.render_graph_to_dot(G: networkx.DiGraph) str

:param G: nx.DiGraph; the graph to render :return: dot_data

pyirk.visualization.build_edge_color_map(G)
pyirk.visualization.svg_replace(raw_svg_data: str, REPLACEMENTS: dict) str
pyirk.visualization.visualize_entity(uri: str, url_template='', write_tmp_files: bool = False, radius=1) str

:param uri: entity uri (like “irk:/my/module#I0123”) :param url_template: url template for creation of a-tags (html links) for the labels :param write_tmp_files: boolean flag whether to write debug output

:return: svg_data as string

pyirk.visualization.get_label(entity)
pyirk.visualization.visualize_all_entities(url_template='', write_tmp_files: bool = False) str
pyirk.visualization.render_label(label: str)