File size: 6,834 Bytes
76d9a63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8150a82
 
 
 
76d9a63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head> 
    <script>
        //let sent_list_json;// = {{data}};|tojson 
// var parte1 = {{ result_parte1 }};
// var incorrect_loss = {{ result_incorrect_loss }};
// var incorrect_hazard = {{ result_incorrect_hazard }};
// var incorrect_constraint = {{ result_incorrect_constraint }};
// var list_sim_loss = {{ result_list_sim_loss }};
// var list_sim_hazard = {{ result_list_sim_hazard }};
// var list_sim_constraint = {{ result_list_sim_constraint }};
//let list_erro_loss = {{result_list_erro_loss}};
//let list_erro_hazard = {{result_list_erro_hazard}};
//let list_erro_constraint = {{result_list_erro_constraint}};
</script>
        <script src="{{url_for('.static', filename='script.js')}}"></script>

    <link rel="stylesheet"  type="text/css" href="{{url_for('.static', filename='style.css')}}">
    
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BEDS Web App Prototype</title>
</head>
<body  onload="start({{ result_parte1 }}, {{ result_incorrect_loss }}, {{ result_incorrect_hazard }}, {{ result_incorrect_constraint }},{{ result_list_sim_loss }},{{ result_list_sim_hazard }},{{ result_list_sim_constraint }},{{result_list_erro_loss}},{{result_list_erro_hazard}},{{result_list_erro_constraint}})"><!--/*data*/-->
    <div class="internal" style="width: 100%; height: 9%; float:none;  overflow: hidden;">
        <h1 style="float: left;">BEDS: BERT Error Detection for STPA</h1>
        <div class="help" onclick="help_visible()">Help</div>
    </div>
    <div id="help_div" onclick="help_visible()"  style="display: flex; justify-content: center; align-items: center;">
        <img src="{{url_for('.static', filename='help.jpg')}}" alt="help_img">
    </div>

    <div class="main_col">
        <div class="internal" id="all_sent", style="width: 100%; height: 90%;">

        <table id="all_sent_table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Sentence</th>
                    <th>Original lbl.</th>
                    <th>Predited lbl.</th>
                </tr>
            </thead>
            <tbody>

            </tbody>
            

        </table>
            
    </div>
    <div class="internal", style="width: 100%; height: 10%; max-height: 10%; overflow: hidden;">

        <div class="inter" onclick="addData_correct()" style="background-color: rgb(144, 238, 144); border: 2px solid gray; border-radius: 3px;">Show correct sentences</div>
        <div class="inter" onclick="addData_incorrect()" style="background-color: rgb(245, 233, 66); border: 2px solid gray; border-radius: 3px;">Show incorrect sentences</div>
        <div class="inter" onclick="addData_erro()" style="background-color: crimson; border: 2px solid gray; border-radius: 3px;">Show classification errors</div>
        <div class="inter" onclick="update_table()" style="border: 2px solid gray; border-radius: 3px;">Show all sentences (Default)</div>
        

            
    </div>
</div>
        
        <div class="main_col">

            <div class="internal" style="width: 100%; height: 15%; ">
                <p>Selected sentence:</p>
                <table id="select_sent">
                    <tr id="select_row">
                        <td id='select_id'>ID</td>
                        <td id='select_req'>Sentence</td>
                        <td id='select_label'>Original lbl.</td>
                        <td id='select_pred'>Predited lbl.</td>
                    </tr>
    
                </table>
            </div>
            <div id='similar_sent' class="internal" style="width: 100%; height: 50%;">
                <p>Suggestion of the most similar sentences:</p>
                <table id="sim_sent_table">
                    <thead>
                        <tr>
                            <th>Similarity</th>
                            <th>Correct sentence</th>
                        </tr>
                    </thead>
                    <tbody id="similar_tbody"></tbody>
    
                </table>
            </div>
    <div class="internal" style="width: 100%; height: 35%;">
    <p id="p_erro"></p>
    <p>Error type probabilities:</p>
    <table id="erro_table">
        <thead>
            <tr>
                <th>Probability</th>
                <th>Type</th>
            </tr>
        </thead>
        <tbody id="erro_tbody"></tbody>
    
    </table>
    </div>

        </div>
            
        

</body>

<script>
    function help_visible(){
        document.getElementById('help_div').style.visibility== 'visible' ? document.getElementById('help_div').style.visibility = 'hidden' : document.getElementById('help_div').style.visibility = 'visible';
    }

    function convert_label(txt){
        switch(txt){
            case 'loss':
                return 0;
            case 'hazard':
                return 1;
            case 'constraint':
                return 2;

        }
    }
    let prev_class = '';
    let list_labels = ['loss', 'hazard', 'constraint'];
    
    table = document.getElementById('all_sent_table');
    selected = table.getElementsByClassName('selected');
    //table.onclick = highlight;  
    
    table.onclick = function(event){
    event = event || window.event; //for IE8 backward compatibility
    var target = event.target || event.srcElement; //for IE8 backward compatibility
    while (target && target.nodeName != 'TR') {
        target = target.parentElement;
    }
    var cells = target.cells; //cells collection
    //var cells = target.getElementsByTagName('td'); //alternative
    if (!cells.length || target.parentNode.nodeName == 'THEAD') { // if clicked row is within thead
        return;
    }
    var id, req, label, pred;
    id = cells[0].innerHTML;
    req = cells[1].innerHTML;
    label = cells[2].innerHTML;
    pred = cells[3].innerHTML;
    if(document.getElementById('select_id').innerText != id){
        document.getElementById('select_row').className = event.target.parentNode.className;
    }
    document.getElementById('select_id').innerText = id;
    document.getElementById('select_req').innerText = req;
    document.getElementById('select_label').innerText = label;
    document.getElementById('select_pred').innerText = pred;
    
    //document.getElementById('select_row').className = event.target.parentNode.className;
    
    //if(incorrect_ids.includes(id)){event.target.parentNode.className = 'selected';}
    if(event.target.parentNode.className != 'selected')
    {
    if (selected[0]) selected[0].className = prev_class;
    prev_class = event.target.parentNode.className;
    event.target.parentNode.className = 'selected';
    
    start2(convert_label(pred),id);
    show_erro(convert_label(pred),id);
    }
    }
    </script>
</html>