-
Notifications
You must be signed in to change notification settings - Fork 5
/
render_entities.js
40 lines (38 loc) · 1.47 KB
/
render_entities.js
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
icons = {
'person':['male','blue'],
'quantity':['sort-numeric-asc','yellow'],
'time':['clock-o','pink'],
'abstract':['cloud','cyan'],
'object':['cube','green'],
'animal':['paw','orange'],
'plant':['pagelines','magenta'],
'place':['map-marker','red'],
'substance':['flask','purple'],
'organization':['bank','brown'],
'event':['bell','gold']};
nlp_result = $("#result").html();
if (nlp_result.includes("entity=")){
nlp_result = nlp_result.replace(/>/g,'>');
nlp_result = nlp_result.replace(/</g,'<');
nlp_result = nlp_result.replace(/&/g,'&');
nlp_result = nlp_result.replace(/(<|<\/)[^\/e][^<>]+>\n?/g,'');
nlp_result = nlp_result.replace(/entity=/g,'class="referent" style="border-color: COLOR" entity=');
nlp_result = nlp_result.replace(/(<\/?)entity/g,'$1div');
nlp_result = nlp_result.replace(/([^\n<>]+)\n/g,'<span class="entity_tok">$1 </span>');
formatted = [];
lines = nlp_result.split("\n");
icon_template = '<span class="entity_type"><i title="TYPE" class="fa fa-ICON"></i></span>';
pat = /entity="([^"]+)"/;
for (line of lines){
if (line.includes("entity=")){
e_type = pat.exec(line)[1];
line += icon_template;
line = line.replace(/TYPE/,e_type).replace(/ICON/,icons[e_type][0]).replace(/COLOR/,icons[e_type][1]);
}
formatted.push(line);
}
entity_output = formatted.join("\n");
$("#entity_container").html(entity_output);
$("#entity_container").css("display","block");
$('<p>Entities:</p>').insertBefore( "#entity_container" );
}