Skip to content

Commit 173889b

Browse files
author
Zan Vrabic
committed
Fixed data preperation for visualization
1 parent b2aab77 commit 173889b

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

niaarm/visualize.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -635,23 +635,25 @@ def prepare_data(rules, M, interestingness_measure):
635635
node_indices = {}
636636

637637
for rule in selected_rules:
638+
# Ensure all antecedents and consequents exist in the node list
639+
for item in rule.antecedent + rule.consequent:
640+
item_str = str(item)
641+
if item_str not in node_indices:
642+
node_indices[item_str] = len(labels)
643+
labels.append(item_str)
644+
645+
# Connect each antecedent to each consequent
638646
for antecedent in rule.antecedent:
639-
if str(antecedent) not in node_indices:
640-
node_indices[str(antecedent)] = len(labels)
641-
labels.append(str(antecedent))
642-
sources.append(node_indices[str(antecedent)])
643-
644-
for consequent in rule.consequent:
645-
if str(consequent) not in node_indices:
646-
node_indices[str(consequent)] = len(labels)
647-
labels.append(str(consequent))
648-
targets.append(node_indices[str(consequent)])
649-
650-
if hasattr(rule, interestingness_measure):
651-
measure_value = getattr(rule, interestingness_measure)
652-
else:
653-
measure_value=rule.support # Default support
654-
values.append(measure_value)
647+
for consequent in rule.consequent:
648+
sources.append(node_indices[str(antecedent)])
649+
targets.append(node_indices[str(consequent)])
650+
651+
# Assign measure value for each connection
652+
if hasattr(rule, interestingness_measure):
653+
measure_value = getattr(rule, interestingness_measure)
654+
else:
655+
measure_value = rule.support # Default support
656+
values.append(measure_value)
655657

656658
return labels, sources, targets, values
657659

0 commit comments

Comments
 (0)