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
|
<div style="margin: 10px 20px; font-family: sans-serif">
<h1>Demo TAS</h1>
<div>
<h3>Beispiele</h3>
<p>
Brauch i mal 3 Führer, da erste nimmd si 247 ZickZack 211/2 Kuppeln Voll 39798, die anderen zwei nehmen sich den Vollzug im Waschgleis in den Westen zwei Teile, der erste geht nach 205/1 kuppeln Lang 39702. Der zweite vom Westen geht Osten Halle 5/3
</p>
<p>
Virtuelle Blockstellen sind eingerichtet an Stellen, die mit einem allein stehenden Signal Ne 14 oder einem Blockkennzeichen gekennzeichnet sind.
</p>
<p>
Die El-Signale sind ausgefallen, wir müssen jetzt auf Sicht fahren.git
</p>
</div>
<div style="margin-bottom: 20px">
<textarea style="width: 100%; height: 100px; display: block" placeholder="Input Text">Wegen der Beladung können die Baustoffe hier nicht mehr rauf.</textarea>
<button id="submit-text">Submit</button>
</div>
<div>
<input type="file" accept="application/pdf">
<button id="submit-doc">Submit</button>
</div>
<h3>Terms</h3>
<div class="terms"></div>
</div>
<script>
const textarea = document.querySelector('textarea');
const submitText = document.querySelector('#submit-text');
const submitDoc = document.querySelector('#submit-doc');
const fileInput = document.querySelector('input[type=file]');
const terms = document.querySelector('.terms');
submitText.addEventListener('click', () => {
const text = textarea.value;
submitText.disabled = true;
submitDoc.disabled = true;
terms.innerHTML = "loading..."
fetch('http://localhost:8000/simple?text=' + encodeURIComponent(text))
.then(response => response.json())
.then(data => {
console.log(data)
submitText.disabled = false;
submitDoc.disabled = false;
showResult(data)
})
})
submitDoc.addEventListener('click', () => {
const file = fileInput.files[0];
const formData = new FormData();
formData.append('file', file);
submitText.disabled = true;
submitDoc.disabled = true;
terms.innerHTML = "loading..."
fetch('http://localhost:8000/processFile', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.log(data)
submitText.disabled = false;
submitDoc.disabled = false;
showResult(data)
})
})
// window.addEventListener('load', () => {
// showResult({
// terms: [
// {
// text: "Beladungen",
// normalization: "Beladung",
// occurrences: [],
// definitions: [
// {
// text: "Beladung",
// partial: false,
// verified: false,
// }
// ]
// },
// {
// text: "Beladungen",
// normalization: "Beladung",
// occurrences: [],
// definitions: [
// {
// text: "Beladung",
// partial: false,
// verified: false,
// }
// ]
// }
// ]
// })
// })
function showResult(data) {
data.terms = data.terms.sort((a, b) => {
const textA = a.normalization ? a.normalization : a.text;
const textB = b.normalization ? b.normalization : b.text;
return textA.localeCompare(textB);
})
let termsHtml = ""
for (let term of data.terms) {
let definitionHtml = ""
for (let definition of term.definitions) {
definitionHtml += `
<div class="definition">
<span>${definition.verified ? "✅" : "✨"}${definition.partial ? "⚙️" : ""} ${definition.text}</span>
<span class="partial">Partial ${definition.partial}, Verified ${definition.verified}</span>
</div>`
}
var variationHtml = ""
if(term.variations) {
variationHtml = term.variations.join(", ")
}
termsHtml += `
<div class="term">
<span class="text">${term.normalization ? term.normalization : term.text}</span>
<span class="lemma">Lemmatized: <strong>${term.normalization}</strong>, Occures in ${term.occurrences.length} sources</span>
<span class="variations">Variations: ${variationHtml}</span>
<span class="occurrences"></span>
<div class="definitions">
${definitionHtml}
</div>
</div>`
}
terms.innerHTML = termsHtml
}
</script>
<style>
.terms {
display: flex;
flex-direction: column;
.term {
display: flex;
flex-direction: column;
padding: 20px 20px;
width: calc(100% - 40px);
&:not(:last-child) {
border-bottom: 1px solid #e5e5e5;
}
&:nth-child(2n) {
background: #f5f5f5
}
.text {
font-size: 1.5rem;
font-weight: bold;
}
.lemma, .occurrences, .variations {
opacity: 0.5;
}
.definitions {
display: flex;
flex-direction: column;
gap: 6px;
margin-top: 4px;
}
.definition {
display: flex;
flex-direction: column;
margin-left: 20px;
.partial, .verified {
opacity: 0.5;
}
}
}
}
</style>
|