Spaces:
Running
Running
Julien Chaumond
commited on
Commit
·
001aa75
1
Parent(s):
b784e3e
singleScores
Browse files- assets/checkbox-off.svg +14 -0
- assets/checkbox-on.svg +15 -0
- assets/icon.svg +48 -0
- index.html +11 -5
- js-src/Displacy.ts +5 -1
- js-src/coref.ts +6 -1
- js-src/zController.ts +18 -2
- less/style.less +53 -2
- less/zDisplacy.less +16 -107
assets/checkbox-off.svg
ADDED
assets/checkbox-on.svg
ADDED
assets/icon.svg
ADDED
index.html
CHANGED
@@ -25,11 +25,17 @@
|
|
25 |
</div>
|
26 |
</form>
|
27 |
</div>
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
</div>
|
34 |
|
35 |
<div class="container">
|
|
|
25 |
</div>
|
26 |
</form>
|
27 |
</div>
|
28 |
+
<div class="menu-button js-checkbox">
|
29 |
+
Debug
|
30 |
+
<img class="svg-checkbox js-checkbox-off" src="/assets/checkbox-off.svg">
|
31 |
+
<img class="svg-checkbox js-checkbox-on hide" src="/assets/checkbox-on.svg">
|
32 |
+
</div>
|
33 |
+
|
34 |
+
<div class="menu-button logo">
|
35 |
+
<a target="_blank" href="https://huggingface.co">
|
36 |
+
<img class="svg-logo" src="/assets/icon.svg">
|
37 |
+
</a>
|
38 |
+
</div>
|
39 |
</div>
|
40 |
|
41 |
<div class="container">
|
js-src/Displacy.ts
CHANGED
@@ -29,7 +29,7 @@ class Displacy {
|
|
29 |
if (i < spans.length - 1) {
|
30 |
const sNext = spans[i+1];
|
31 |
if (s.start < sNext.start && s.end > sNext.start) {
|
32 |
-
|
33 |
}
|
34 |
}
|
35 |
});
|
@@ -79,6 +79,10 @@ class Displacy {
|
|
79 |
for (const sT of spanTags) {
|
80 |
if (sT.tag === "start") {
|
81 |
out.append(`<mark data-entity="${ sT.span.type.toLowerCase() }" data-index="${ (<any>sT.span).index }">`);
|
|
|
|
|
|
|
|
|
82 |
} else {
|
83 |
out.append(`</mark>`);
|
84 |
}
|
|
|
29 |
if (i < spans.length - 1) {
|
30 |
const sNext = spans[i+1];
|
31 |
if (s.start < sNext.start && s.end > sNext.start) {
|
32 |
+
console.log("ERROR", "Spans: strict overlapping");
|
33 |
}
|
34 |
}
|
35 |
});
|
|
|
79 |
for (const sT of spanTags) {
|
80 |
if (sT.tag === "start") {
|
81 |
out.append(`<mark data-entity="${ sT.span.type.toLowerCase() }" data-index="${ (<any>sT.span).index }">`);
|
82 |
+
const singleScore = (<any>sT.span).singleScore;
|
83 |
+
if (singleScore) {
|
84 |
+
out.append(`<span class="single-score">${ singleScore.toFixed(3) }</span>`);
|
85 |
+
}
|
86 |
} else {
|
87 |
out.append(`</mark>`);
|
88 |
}
|
js-src/coref.ts
CHANGED
@@ -63,7 +63,12 @@ class Coref {
|
|
63 |
}
|
64 |
|
65 |
render(res: Response) {
|
66 |
-
const
|
|
|
|
|
|
|
|
|
|
|
67 |
if (!this.container) { return ; }
|
68 |
// console.log(markup); // todo remove
|
69 |
this.container.innerHTML = `<div class="text">${markup}</div>`;
|
|
|
63 |
}
|
64 |
|
65 |
render(res: Response) {
|
66 |
+
const mentions = (<any>res).mentions; // We will sort them in Displacy
|
67 |
+
for (const m of mentions) {
|
68 |
+
// Let's add each mention's singleScore
|
69 |
+
m.singleScore = res.singleScores[m.index] || undefined;
|
70 |
+
}
|
71 |
+
const markup = Displacy.render(res.cleanedText, mentions);
|
72 |
if (!this.container) { return ; }
|
73 |
// console.log(markup); // todo remove
|
74 |
this.container.innerHTML = `<div class="text">${markup}</div>`;
|
js-src/zController.ts
CHANGED
@@ -6,6 +6,14 @@ const loading = () => {
|
|
6 |
document.body.classList.toggle('loading');
|
7 |
};
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
const coref = new Coref(ENDPOINT, {
|
10 |
onStart: loading,
|
11 |
onSuccess: loading,
|
@@ -25,8 +33,9 @@ const updateURL = (text) => {
|
|
25 |
}
|
26 |
|
27 |
document.addEventListener('DOMContentLoaded', () => {
|
28 |
-
const $input
|
29 |
-
const $form
|
|
|
30 |
coref.container = document.querySelector('.container') as HTMLElement;
|
31 |
|
32 |
{
|
@@ -54,6 +63,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
54 |
updateURL(text);
|
55 |
coref.parse(text);
|
56 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
});
|
58 |
|
59 |
|
|
|
6 |
document.body.classList.toggle('loading');
|
7 |
};
|
8 |
|
9 |
+
const toggleDebug = () => {
|
10 |
+
document.body.classList.toggle('debug');
|
11 |
+
const icons = document.querySelectorAll('.svg-checkbox');
|
12 |
+
(<any>icons).forEach((icon) => {
|
13 |
+
icon.classList.toggle('hide');
|
14 |
+
});
|
15 |
+
};
|
16 |
+
|
17 |
const coref = new Coref(ENDPOINT, {
|
18 |
onStart: loading,
|
19 |
onSuccess: loading,
|
|
|
33 |
}
|
34 |
|
35 |
document.addEventListener('DOMContentLoaded', () => {
|
36 |
+
const $input = document.querySelector('input.input-message') as HTMLInputElement;
|
37 |
+
const $form = document.querySelector('form.js-form') as HTMLFormElement;
|
38 |
+
const $checkbox = document.querySelector('.js-checkbox') as HTMLElement;
|
39 |
coref.container = document.querySelector('.container') as HTMLElement;
|
40 |
|
41 |
{
|
|
|
63 |
updateURL(text);
|
64 |
coref.parse(text);
|
65 |
});
|
66 |
+
|
67 |
+
$checkbox.addEventListener('click', () => {
|
68 |
+
toggleDebug();
|
69 |
+
});
|
70 |
+
|
71 |
+
// Turn on debug mode by default:
|
72 |
+
toggleDebug();
|
73 |
});
|
74 |
|
75 |
|
less/style.less
CHANGED
@@ -5,6 +5,8 @@
|
|
5 |
@import "mixins/size.less";
|
6 |
@import "mixins/user-select.less";
|
7 |
|
|
|
|
|
8 |
body {
|
9 |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
10 |
-webkit-font-smoothing: antialiased;
|
@@ -14,19 +16,23 @@ code, pre {
|
|
14 |
background-color: rgba(0,0,0,0.04);
|
15 |
border-radius: 3px;
|
16 |
padding: 2px 6px;
|
17 |
-
font-family:
|
18 |
font-size: 12px;
|
19 |
color: #2f2f2f;
|
20 |
}
|
21 |
|
|
|
|
|
|
|
22 |
.header {
|
23 |
padding: 18px 18px;
|
|
|
24 |
.input-wrapper {
|
25 |
background: #c5c5c5;
|
26 |
padding: 0.5rem 1rem;
|
27 |
margin: 0 0.75rem 0.75rem 0;
|
28 |
-
border-color: #181818;
|
29 |
border-radius: .5rem;
|
|
|
30 |
width: 76%;
|
31 |
.wrapper-inner {
|
32 |
width: 100%;
|
@@ -53,6 +59,29 @@ code, pre {
|
|
53 |
}
|
54 |
}
|
55 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
|
58 |
.container {
|
@@ -60,8 +89,30 @@ code, pre {
|
|
60 |
overflow-x: auto;
|
61 |
white-space: nowrap;
|
62 |
padding: 180px 40px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
/**
|
67 |
* Elements from Displacy
|
|
|
5 |
@import "mixins/size.less";
|
6 |
@import "mixins/user-select.less";
|
7 |
|
8 |
+
@fontMonospace: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
9 |
+
|
10 |
body {
|
11 |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
12 |
-webkit-font-smoothing: antialiased;
|
|
|
16 |
background-color: rgba(0,0,0,0.04);
|
17 |
border-radius: 3px;
|
18 |
padding: 2px 6px;
|
19 |
+
font-family: @fontMonospace;
|
20 |
font-size: 12px;
|
21 |
color: #2f2f2f;
|
22 |
}
|
23 |
|
24 |
+
.hide { display: none !important; }
|
25 |
+
|
26 |
+
|
27 |
.header {
|
28 |
padding: 18px 18px;
|
29 |
+
.clearfix();
|
30 |
.input-wrapper {
|
31 |
background: #c5c5c5;
|
32 |
padding: 0.5rem 1rem;
|
33 |
margin: 0 0.75rem 0.75rem 0;
|
|
|
34 |
border-radius: .5rem;
|
35 |
+
float: left;
|
36 |
width: 76%;
|
37 |
.wrapper-inner {
|
38 |
width: 100%;
|
|
|
59 |
}
|
60 |
}
|
61 |
}
|
62 |
+
div.menu-button {
|
63 |
+
background: #c5c5c5;
|
64 |
+
padding: 0.5rem 1rem;
|
65 |
+
margin: 0 0.75rem 0.75rem 0;
|
66 |
+
border-radius: .5rem;
|
67 |
+
float: left;
|
68 |
+
height: 29px;
|
69 |
+
line-height: 28px;
|
70 |
+
color: #444;
|
71 |
+
cursor: pointer;
|
72 |
+
.user-select(none);
|
73 |
+
&.logo {
|
74 |
+
background-color: #6779f7;
|
75 |
+
img.svg-logo {
|
76 |
+
height: 30px;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
img.svg-checkbox {
|
80 |
+
position: relative;
|
81 |
+
top: 3px;
|
82 |
+
margin-left: 3px;
|
83 |
+
}
|
84 |
+
}
|
85 |
}
|
86 |
|
87 |
.container {
|
|
|
89 |
overflow-x: auto;
|
90 |
white-space: nowrap;
|
91 |
padding: 180px 40px;
|
92 |
+
mark {
|
93 |
+
position: relative;
|
94 |
+
span.single-score {
|
95 |
+
position: absolute;
|
96 |
+
bottom: -32px;
|
97 |
+
left: 0; right: 0;
|
98 |
+
text-align: center;
|
99 |
+
font-family: @fontMonospace;
|
100 |
+
font-size: 12px;
|
101 |
+
visibility: hidden;
|
102 |
+
}
|
103 |
+
&:hover {
|
104 |
+
span.single-score {
|
105 |
+
visibility: visible;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
}
|
109 |
}
|
110 |
|
111 |
+
body.debug {
|
112 |
+
span.single-score {
|
113 |
+
visibility: visible !important;
|
114 |
+
}
|
115 |
+
}
|
116 |
|
117 |
/**
|
118 |
* Elements from Displacy
|
less/zDisplacy.less
CHANGED
@@ -24,120 +24,29 @@
|
|
24 |
}
|
25 |
[data-entity][data-entity="proper"] {
|
26 |
background: rgba(166, 226, 45, 0.2);
|
27 |
-
border-color: #a6e22d
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
}
|
32 |
[data-entity][data-entity="nominal"] {
|
33 |
background: rgba(224, 0, 132, 0.2);
|
34 |
-
border-color: #e00084
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
}
|
39 |
[data-entity][data-entity="pronominal"] {
|
40 |
background: rgba(67, 198, 252, 0.2);
|
41 |
-
border-color: #43c6fc
|
|
|
|
|
|
|
42 |
}
|
43 |
-
[data-entity][data-entity="pronominal"]:after {
|
44 |
-
background: #43c6fc
|
45 |
-
}
|
46 |
-
// [data-entity][data-entity="org"] {
|
47 |
-
// background: rgba(67, 198, 252, 0.2);
|
48 |
-
// border-color: #43c6fc
|
49 |
-
// }
|
50 |
-
// [data-entity][data-entity="org"]:after {
|
51 |
-
// background: #43c6fc
|
52 |
-
// }
|
53 |
[data-entity][data-entity="list"] {
|
54 |
background: rgba(253, 151, 32, 0.2);
|
55 |
-
border-color: #fd9720
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
}
|
60 |
-
[data-entity][data-entity="loc"] {
|
61 |
-
background: rgba(253, 151, 32, 0.2);
|
62 |
-
border-color: #fd9720
|
63 |
-
}
|
64 |
-
[data-entity][data-entity="loc"]:after {
|
65 |
-
background: #fd9720
|
66 |
-
}
|
67 |
-
[data-entity][data-entity="product"] {
|
68 |
-
background: rgba(142, 125, 255, 0.2);
|
69 |
-
border-color: #8e7dff
|
70 |
-
}
|
71 |
-
[data-entity][data-entity="product"]:after {
|
72 |
-
background: #8e7dff
|
73 |
-
}
|
74 |
-
[data-entity][data-entity="event"] {
|
75 |
-
background: rgba(255, 204, 0, 0.2);
|
76 |
-
border-color: #fc0
|
77 |
-
}
|
78 |
-
[data-entity][data-entity="event"]:after {
|
79 |
-
background: #fc0
|
80 |
-
}
|
81 |
-
[data-entity][data-entity="work_of_art"] {
|
82 |
-
background: rgba(255, 204, 0, 0.2);
|
83 |
-
border-color: #fc0
|
84 |
-
}
|
85 |
-
[data-entity][data-entity="work_of_art"]:after {
|
86 |
-
background: #fc0
|
87 |
-
}
|
88 |
-
[data-entity][data-entity="language"] {
|
89 |
-
background: rgba(255, 204, 0, 0.2);
|
90 |
-
border-color: #fc0
|
91 |
-
}
|
92 |
-
[data-entity][data-entity="language"]:after {
|
93 |
-
background: #fc0
|
94 |
-
}
|
95 |
-
[data-entity][data-entity="date"] {
|
96 |
-
background: rgba(47, 187, 171, 0.2);
|
97 |
-
border-color: #2fbbab
|
98 |
-
}
|
99 |
-
[data-entity][data-entity="date"]:after {
|
100 |
-
background: #2fbbab
|
101 |
-
}
|
102 |
-
[data-entity][data-entity="time"] {
|
103 |
-
background: rgba(47, 187, 171, 0.2);
|
104 |
-
border-color: #2fbbab
|
105 |
-
}
|
106 |
-
[data-entity][data-entity="time"]:after {
|
107 |
-
background: #2fbbab
|
108 |
-
}
|
109 |
-
[data-entity][data-entity="percent"] {
|
110 |
-
background: rgba(153, 153, 153, 0.2);
|
111 |
-
border-color: #999
|
112 |
-
}
|
113 |
-
[data-entity][data-entity="percent"]:after {
|
114 |
-
background: #999
|
115 |
-
}
|
116 |
-
[data-entity][data-entity="money"] {
|
117 |
-
background: rgba(153, 153, 153, 0.2);
|
118 |
-
border-color: #999
|
119 |
-
}
|
120 |
-
[data-entity][data-entity="money"]:after {
|
121 |
-
background: #999
|
122 |
-
}
|
123 |
-
[data-entity][data-entity="quantity"] {
|
124 |
-
background: rgba(153, 153, 153, 0.2);
|
125 |
-
border-color: #999
|
126 |
-
}
|
127 |
-
[data-entity][data-entity="quantity"]:after {
|
128 |
-
background: #999
|
129 |
-
}
|
130 |
-
[data-entity][data-entity="ordinal"] {
|
131 |
-
background: rgba(153, 153, 153, 0.2);
|
132 |
-
border-color: #999
|
133 |
-
}
|
134 |
-
[data-entity][data-entity="ordinal"]:after {
|
135 |
-
background: #999
|
136 |
-
}
|
137 |
-
[data-entity][data-entity="cardinal"] {
|
138 |
-
background: rgba(153, 153, 153, 0.2);
|
139 |
-
border-color: #999
|
140 |
}
|
141 |
-
[data-entity][data-entity="cardinal"]:after {
|
142 |
-
background: #999
|
143 |
-
}
|
|
|
24 |
}
|
25 |
[data-entity][data-entity="proper"] {
|
26 |
background: rgba(166, 226, 45, 0.2);
|
27 |
+
border-color: #a6e22d;
|
28 |
+
&:after {
|
29 |
+
background: #a6e22d;
|
30 |
+
}
|
31 |
}
|
32 |
[data-entity][data-entity="nominal"] {
|
33 |
background: rgba(224, 0, 132, 0.2);
|
34 |
+
border-color: #e00084;
|
35 |
+
&:after {
|
36 |
+
background: #e00084;
|
37 |
+
}
|
38 |
}
|
39 |
[data-entity][data-entity="pronominal"] {
|
40 |
background: rgba(67, 198, 252, 0.2);
|
41 |
+
border-color: #43c6fc;
|
42 |
+
&:after {
|
43 |
+
background: #43c6fc;
|
44 |
+
}
|
45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
[data-entity][data-entity="list"] {
|
47 |
background: rgba(253, 151, 32, 0.2);
|
48 |
+
border-color: #fd9720;
|
49 |
+
&:after {
|
50 |
+
background: #fd9720;
|
51 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
}
|
|
|
|
|
|