File size: 2,427 Bytes
90c8ced
 
1b1c01c
90c8ced
1fb895a
90c8ced
 
 
 
 
 
 
 
 
 
1fb895a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90c8ced
 
 
 
 
 
 
 
1fb895a
90c8ced
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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