-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy pathexample.html
100 lines (81 loc) · 2.92 KB
/
example.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of Using Bling Fire WebAssembly</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<script type="module">
import { GetVersion, TextToWords, TextToSentences, LoadModel, FreeModel, TextToIds, WordHyphenation } from './blingfire_wrapper.js';
$(document).ready(function() {
var text = "I saw a girl with a telescope. Я видел девушку с телескопом.";
$("#btn1").click(function () {
console.log("Version: " + GetVersion());
});
$("#btn2").click(function () {
console.log(TextToWords(text));
});
$("#btn3").click(function () {
console.log(TextToSentences(text));
});
var modelHandle1 = null;
var modelHandle2 = null;
$("#btn4").click(function () {
if(modelHandle1 == null) {
(async function () {
modelHandle1 = await LoadModel("./laser100k.bin");
console.log("Model handle: " + modelHandle1);
})();
}
if(modelHandle2 == null) {
(async function () {
modelHandle2 = await LoadModel("./syllab.bin");
console.log("Model handle: " + modelHandle2);
})();
}
});
$("#btn5").click(function () {
if(modelHandle1 != null) {
FreeModel(modelHandle1);
modelHandle1 = null;
console.log("Model Freed!");
}
if(modelHandle2 != null) {
FreeModel(modelHandle2);
modelHandle2 = null;
console.log("Model Freed!");
}
});
$("#btn6").click(function () {
if(modelHandle1 != null) {
console.log(TextToIds(modelHandle1, text, 128));
} else {
console.log("Load the model first!");
}
});
$("#btn7").click(function () {
if(modelHandle2 != null) {
console.log(WordHyphenation(modelHandle2, "syllabification"));
} else {
console.log("Load the model first!");
}
});
});
</script>
</head>
<body>
<div class="container">
<h2>See Console output for different APIs:</h2>
<button type="button" class="btn btn-primary" id="btn1">GetBlingFireTokVersion</button>
<button type="button" class="btn btn-secondary" id="btn2">TextToWords</button>
<button type="button" class="btn btn-secondary" id="btn3">TextToSentences</button>
<button type="button" class="btn btn-secondary" id="btn4">LoadModel</button>
<button type="button" class="btn btn-secondary" id="btn5">FreeModel</button>
<button type="button" class="btn btn-secondary" id="btn6">TextToIds</button>
<button type="button" class="btn btn-secondary" id="btn7">HyphenateWordWithModel</button>
</div>
</body>
</html>