Spaces:
Sleeping
Sleeping
File size: 10,850 Bytes
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
// //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}};
var parte1;
var incorrect_loss;
var incorrect_hazard;
var incorrect_constraint;
var list_sim_loss;
var list_sim_hazard;
var list_sim_constraint;
var list_erro_loss;
var list_erro_hazard;
var list_erro_constraint;
let incorrect_ids = [];
let erro_classif_ids = [];
// let sub_loss_incorreto = ['accidentl', 'ambiguol', 'reescreverl', 'dueto', 'incompletol', 'notl', 'environment', 'during', 'eventl', 'hazardl'];
// let sub_hazard_incorreto = ['incompletoh', 'when', 'reescreverh', 'accidenth', 'ambiguoh', 'causes', 'fail', 'noth', 'eventh', 'while', 'lossh'];
// let sub_constraint_incorreto = ['recommendation', 'notc', 'incompletoc', 'reescreverc', 'ambiguoc'];
// let sub_loss_incorreto = ['acidente', 'reescrever', 'condicional', 'not', 'ambiente']
// let sub_hazard_incorreto = ['reescrever', 'acidente', 'fail', 'not', 'condicional']
// let sub_constraint_incorreto = ['recomendacao', 'not', 'reescrever']
let step1_labels = ['loss', 'hazard', 'constraint']
let step2_labels = ['correct', 'incorrect']
let step3_labels = ['rewrite', 'not', 'condition', 'accident']//, 'correct']
//let list_labels = ['loss', 'hazard', 'constraint'];
function addData(tupla,t_id) {
let id = tupla['id'];
let req = tupla['req'];
let label = tupla['label'];
let pred = tupla['pred'];
let flag = 0;
if(label!=pred){
flag = 1;
}
//console.log(req)
//console.log(label)
// Get the table and insert a new row at the end
let table = document.getElementById(t_id).getElementsByTagName('tbody')[0];
let newRow = table.insertRow(table.rows.length);
//table.innerHTML = '';
for(let i = 0; i<incorrect_loss.length;i++){
if(id==incorrect_loss[i]['id']){//pode ser ['id'][i]
newRow.className = 'incorrect';
incorrect_ids.push(id)
}
}
for(let i = 0; i<incorrect_hazard.length;i++){
if(id==incorrect_hazard[i]['id']){//pode ser ['id'][i]
newRow.className = 'incorrect';
incorrect_ids.push(id)
}
}
for(let i = 0; i<incorrect_constraint.length;i++){
if(id==incorrect_constraint[i]['id']){//pode ser ['id'][i]
newRow.className = 'incorrect';
incorrect_ids.push(id)
}
}
if(label != pred){
newRow.className = 'erro';
erro_classif_ids.push(id);
}
newRow.insertCell(0).innerHTML = id;
newRow.insertCell(1).innerHTML = req;
newcell = newRow.insertCell(2);
newcell.innerHTML = list_labels[label];
newcell.className = "erro_classif";
newcell = newRow.insertCell(3);
newcell.innerHTML = list_labels[pred];
newcell.className = "erro_classif";
// Clear input fields
//clearInputs();
}
function addData_correct(){
data = parte1;
document.getElementById("all_sent_table").getElementsByTagName('tbody')[0].innerHTML = '';
for(let i = 0; i<data.length;i++){
if(!incorrect_ids.includes(data[i]['id'])){
addData(data[i],"all_sent_table");
}
}
}
function addData_incorrect(){
data = parte1;
let aux = incorrect_ids;
incorrect_ids = [];
document.getElementById("all_sent_table").getElementsByTagName('tbody')[0].innerHTML = '';
for(let i = 0; i<data.length;i++){
if(aux.includes(data[i]['id'])){
addData(data[i],"all_sent_table");
}
}
}
function addData_erro(){
data = parte1;
let aux = erro_classif_ids;
erro_classif_ids = [];
document.getElementById("all_sent_table").getElementsByTagName('tbody')[0].innerHTML = '';
for(let i = 0; i<data.length;i++){
if(aux.includes(data[i]['id'])){
addData(data[i],"all_sent_table");
}
}
}
function addData2(tupla,t_id) {
//alert("etnrou addData2");
//let id = tupla[0];
let simi = tupla[1];
let req = tupla[2];
// Get the table and insert a new row at the end
let table = document.getElementById(t_id).getElementsByTagName('tbody')[0];
let newRow = table.insertRow(table.rows.length);
// Insert data into cells of the new row
newRow.insertCell(0).innerHTML = (simi*100).toFixed(2)+'%';
newRow.insertCell(1).innerHTML = req;
}
function addData3(tupla,p_id, label){
let pred = tupla[2];
let prob = tupla[3];
//let sugestao = 'Placeholder suggestion.'
let sub;
//step3_labels = ['rewrite', 'not', 'condition', 'accident', 'correct']
let sugestao = ['The sentence may [have a lacking keyword], ou [has all the necessary information, but is not wel-written].\nCertify that all information is present (ex.: "loss", "value", "system", ou "safe/unsafe condition"), and rewrite the sentence to a format closer to the STPA Handbook.',
'The sentence may not be of the original class. Check for possible labeling errors, or if there are no ambiguous words or context in the sentence.',
'The sentence may contain certain words (such as "causes", "caused by", "results in", "due to") that gives a meaning of cause and effect, and limits the scope of the analysis.',
'Accidents were isolated in this category, because they are not something of value that should not be lost (Loss), nor conditions that in the worst environmental scenarios, will lead to a Loss (Hazard). Check the context of the sentence, and adjust the information to the adequate class.',
'Error: suggestion 5.'
]
// switch(pred){
// case 0://rewrite
// sugestao = 'The sentence may [have a lacking keyword], ou [has all the necessary information, but is not wel-written].\nCertify that all information is present (ex.: "loss", "value", "system", ou "safe/unsafe condition"), and rewrite the sentence to a format closer to the STPA Handbook.';
// break;
// case 1://not
// sugestao = 'The sentence may not be of the original class. Check for possible labeling errors, or if there are no ambiguous words or context in the sentence.';
// case 2://condition
// sugestao = 'The sentence may contain certain words (such as "causes", "caused by", "results in", "due to") that gives a meaning of cause and effect, and limits the scope of the analysis.';
// break;
// case 3://accident
// sugestao = 'Accidents were isolated in this category, because they are not something of value that should not be lost (Loss), nor conditions that in the worst environmental scenarios, will lead to a Loss (Hazard). Check the context of the sentence, and adjust the information to the adequate class.';
// default:
// //console.log('entrou addData3');
// break;
// }
sub = step3_labels;
// switch(+label){
// case 0:
// sub = sub_loss_incorreto;
// //sugestao = 'Sugestao1';//lista de sugestao com base no pred let sug_loss = [(10 sugestoes)]
// break;
// case 1:
// sub = sub_hazard_incorreto;
// break;
// case 2:
// sub = sub_constraint_incorreto;
// break;
// }
let paragrafo = document.getElementById(p_id);
paragrafo.innerHTML = 'Detected error: '+sub[pred]+';<br />Error suggention: '+sugestao[pred]+';';//Probabilidade: ${prob};<br />
// Get the table and insert a new row at the end
let table = document.getElementById('erro_table').getElementsByTagName('tbody')[0];
//table.innerHTML = '';
for(let i=0 ;i<sub.length;i++){
if(label==2 && i==2){
break
}
let newRow = table.insertRow(table.rows.length);
// Insert data into cells of the new row
newRow.insertCell(0).innerHTML = (prob[i]*100).toFixed(2)+'%';
newRow.insertCell(1).innerHTML = sub[i];
}
}
function update_table(){
data = parte1;
//console.log(data[0])
document.getElementById("all_sent_table").getElementsByTagName('tbody')[0].innerHTML = '';
for(let i = 0; i<data.length;i++){
addData(data[i],"all_sent_table");
}
}
function 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){// window.onload = function()
parte1 = result_parte1;
incorrect_loss = result_incorrect_loss;
incorrect_hazard = result_incorrect_hazard;
incorrect_constraint = result_incorrect_constraint;
list_sim_loss = result_list_sim_loss;
list_sim_hazard = result_list_sim_hazard;
list_sim_constraint = result_list_sim_constraint;
list_erro_loss = result_list_erro_loss;
list_erro_hazard = result_list_erro_hazard;
list_erro_constraint = result_list_erro_constraint;
update_table();
}
function start2(label,id){
//alert('entrou start2');
//alert(label);
//alert(id);
let data;
// var old_tbody = document.getElementById('similar_tbody');
// var new_tbody = document.createElement('tbody');
// populate_with_new_rows(new_tbody);
// old_tbody.parentNode.replaceChild(new_tbody, old_tbody);
document.getElementById('sim_sent_table').getElementsByTagName('tbody')[0].innerHTML = '';
if(label==0){
data = list_sim_loss;
}
else if(label==1){
data = list_sim_hazard;
}
else if(label==2){
data = list_sim_constraint;
}
for(let i = 0; i<data.length;i++){
if(id==data[i][0]){
//alert(data[i][0])certo
//alert(data[0][i])undefined
//console.log(data[i])
addData2(data[i],"sim_sent_table");
}
}
}
function show_erro(label, id){
let data;
document.getElementById('erro_table').getElementsByTagName('tbody')[0].innerHTML = '';
if(label==0){
data = list_erro_loss;
}
else if(label==1){
data = list_erro_hazard;
}
else if(label==2){
data = list_erro_constraint;
}
for(let i = 0; i<data.length;i++){
if(id==data[i][0]){
//alert(data[i][0])certo
//alert(data[0][i])undefined
addData3(data[i],"p_erro",label);
}
}
}
|