Upload index.html
Browse files- index.html +65 -18
index.html
CHANGED
|
@@ -1,19 +1,66 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="sv">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Selma Lagerlöf — Predicción de palabra (trigramas)</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }
|
| 8 |
+
input { width: 100%; padding: 10px; font-size: 16px; box-sizing: border-box; }
|
| 9 |
+
#result { margin-top: 20px; font-size: 18px; min-height: 1.5em; }
|
| 10 |
+
#status { color: #888; font-size: 14px; }
|
| 11 |
+
</style>
|
| 12 |
+
</head>
|
| 13 |
+
<body>
|
| 14 |
+
<h1>Selma Lagerlöf — Predicción de la siguiente palabra</h1>
|
| 15 |
+
<p>Modelo de trigramas entrenado sobre el corpus de Selma Lagerlöf
|
| 16 |
+
(Assignment 2, Language Technology, Lund University).</p>
|
| 17 |
+
<p>Escribe al menos dos palabras en sueco (p. ej. "det var"):</p>
|
| 18 |
+
<input id="textbox" type="text" placeholder="det var" autocomplete="off">
|
| 19 |
+
<div id="status">Cargando trigramas...</div>
|
| 20 |
+
<div id="result"></div>
|
| 21 |
+
|
| 22 |
+
<script>
|
| 23 |
+
let trigrams = new Map(); // key "w1|w2" -> array of [w3, count]
|
| 24 |
+
|
| 25 |
+
fetch('trigrams.jsonl')
|
| 26 |
+
.then(r => r.text())
|
| 27 |
+
.then(text => {
|
| 28 |
+
const lines = text.split('\n').filter(l => l.trim().length > 0);
|
| 29 |
+
for (const line of lines) {
|
| 30 |
+
const data = JSON.parse(line);
|
| 31 |
+
if (data.ngram.length === 3) {
|
| 32 |
+
const key = data.ngram[0] + '|' + data.ngram[1];
|
| 33 |
+
if (!trigrams.has(key)) trigrams.set(key, []);
|
| 34 |
+
trigrams.get(key).push([data.ngram[2], data.count]);
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
document.getElementById('status').textContent =
|
| 38 |
+
'Trigramas cargados: ' + lines.length.toLocaleString();
|
| 39 |
+
})
|
| 40 |
+
.catch(err => {
|
| 41 |
+
document.getElementById('status').textContent =
|
| 42 |
+
'Error cargando trigrams.jsonl: ' + err;
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
document.getElementById('textbox').addEventListener('input', function () {
|
| 46 |
+
const words = this.value.toLowerCase().trim().split(/\s+/);
|
| 47 |
+
const resultDiv = document.getElementById('result');
|
| 48 |
+
if (words.length < 2 || words[0] === '') {
|
| 49 |
+
resultDiv.textContent = '';
|
| 50 |
+
return;
|
| 51 |
+
}
|
| 52 |
+
const w1 = words[words.length - 2];
|
| 53 |
+
const w2 = words[words.length - 1];
|
| 54 |
+
const candidates = trigrams.get(w1 + '|' + w2) || [];
|
| 55 |
+
const sorted = candidates.slice().sort((a, b) => {
|
| 56 |
+
if (b[1] !== a[1]) return b[1] - a[1]; // frequency desc
|
| 57 |
+
return a[0].localeCompare(b[0]); // then alphabetical
|
| 58 |
+
});
|
| 59 |
+
const top5 = sorted.slice(0, 5).map(c => c[0]);
|
| 60 |
+
resultDiv.textContent = top5.length > 0
|
| 61 |
+
? 'Predicciones: ' + top5.join(', ')
|
| 62 |
+
: 'No hay predicciones para ese contexto.';
|
| 63 |
+
});
|
| 64 |
+
</script>
|
| 65 |
+
</body>
|
| 66 |
</html>
|