function visualize_connectedNodes_continuous() % Read the data and create the connections map data = readtable('../MGREL.RRF', 'Delimiter', '|', 'FileType', 'text', 'NumHeaderLines', 0, 'VariableNamingRule', 'preserve'); data = renamevars(data, '#CUI1', 'CUI1'); data = data(1:50000,:); connectionsMap = containers.Map('KeyType', 'char', 'ValueType', 'char'); for i = 1:size(data, 1) node = data{i, 'CUI1'}; char_node = char(node); connectedNode = data{i, 'CUI2'}; char_connectedNode = char(connectedNode); rel = data{i, 'REL'}; char_rel = char(rel); if char_rel == "RN" || char_rel == "RB" disp(char_node) if isKey(connectionsMap, char_node) connectionsMap(char_node) = [connectionsMap(char_node), '|', char_connectedNode]; else connectionsMap(char_node) = char_connectedNode; end if isKey(connectionsMap, char_connectedNode) connectionsMap(char_connectedNode) = [connectionsMap(char_connectedNode), '|', char_node]; else connectionsMap(char_connectedNode) = char_node; end end end % Loop for continuous interaction while true % Prompt the user for input prompt = 'Enter a key (or type "exit" to quit):'; dlgtitle = 'Input'; dims = [1 50]; definput = {'C0013902'}; userInput = inputdlg(prompt, dlgtitle, dims, definput); % Check if user canceled the dialog or typed "exit" if isempty(userInput) || strcmp(userInput{1}, 'exit') disp('Exiting...'); break; end key = userInput{1}; % Check if the key exists in the connectionsMap if isKey(connectionsMap, key) % Split the value string by the pipe symbol '|' split_values = strsplit(connectionsMap(key), '|'); % Display the connected nodes disp(split_values); % Visualize the graph G = graph(); for i = 1:length(split_values) G = addedge(G, key, split_values{i}); end figure; plot(G, 'Layout', 'force'); title('Graph of Connected Nodes'); else disp('Key does not exist in the connectionsMap.'); end end end