in src/graph_notebook/network/sparql/SPARQLNetwork.py [0:0]
def parse_node(self, node_id: str, node_binding: dict = None, data: dict = None):
"""
overriding parent add_node class to automatically parse the uri for a node
and add data to the node for prefix and shortened name
:param node_id: the full uri
:param node_binding: the subject or object binding, in dict form
:param data: dict to set node initial node properties
"""
if data is None:
data = {}
label = ''
title = ''
if self.display_property:
label = self.get_property_value(node_binding, self.display_property)
if label:
title_new, label = self.strip_and_truncate_label_and_title(label, self.label_max_length)
title = title_new
if self.tooltip_property and self.tooltip_property != self.display_property:
tooltip_raw = self.get_property_value(node_binding, self.tooltip_property)
if tooltip_raw:
title, label_plc = self.strip_and_truncate_label_and_title(tooltip_raw)
data['title'] = title
# TODO: Check back on whether we want to overwrite existing labels
if not data.get('label'):
if label:
data['label'] = label
if not data.get('title'):
data['title'] = title
else:
data = self.generate_node_label_title(node_id=node_id, data=data)
if self.ignore_groups or not node_binding:
data['group'] = DEFAULT_GRP
else:
if isinstance(self.group_by_property, dict):
try:
if str(node_binding["type"]) in self.group_by_property:
data['group'] = node_binding[self.group_by_property[node_binding["type"]]]
else:
data['group'] = node_binding["type"]
except KeyError:
data['group'] = node_binding["type"]
elif self.group_by_property in node_binding:
data['group'] = node_binding[self.group_by_property]
else:
data['group'] = node_binding["type"]
self.add_node(node_id=node_id, data=data)