Skip to content
This repository was archived by the owner on Jan 4, 2021. It is now read-only.

Commit 2a2bac7

Browse files
author
Benoit Fonty
committed
Merge pull request #4 in WS/webcomponents-myscript-text-web from wip_rab to master
* commit '4ffc6ce7bc5a1081c0af0f041adfbb18c1c99649': recognition asset builder
2 parents 5b83a8f + 4ffc6ce commit 2a2bac7

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

myscript-text-web.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ class MyScriptTextWeb extends PolymerElement {
528528
value: [],
529529
reflectToAttribute: true
530530
},
531+
/**
532+
* custom lexicon
533+
*/
534+
customlexicon: {
535+
type: Array,
536+
value: [],
537+
reflectToAttribute: true
538+
},
531539
/**
532540
* If set to true, hide the export panel.
533541
*/
@@ -759,7 +767,7 @@ class MyScriptTextWeb extends PolymerElement {
759767
return stylesheet;
760768
}
761769

762-
static _generateTextConfiguration(configuration, language, mimetypes, alwaysconnected, disableguides, disablesmartguide, enablesmartguidefadeout, smartguidefadeoutduration, nolktext, customresources, textinputmode, resultdetail, contenttypes, subsetknowledges, userlkwords, userresources, textcandidatelistsize, wordcandidatelistsize, wordpredictionlistsize, wordcompletionlistsize, charactercandidatelistsize, enableoutoflexicon, discardcasevariations, discardaccentuationvariations, glyphdistortion, enabletagger, spellingdistortion) {
770+
static _generateTextConfiguration(configuration, language, mimetypes, alwaysconnected, disableguides, disablesmartguide, enablesmartguidefadeout, smartguidefadeoutduration, nolktext, customresources, customlexicon, textinputmode, resultdetail, contenttypes, subsetknowledges, userlkwords, userresources, textcandidatelistsize, wordcandidatelistsize, wordpredictionlistsize, wordcompletionlistsize, charactercandidatelistsize, enableoutoflexicon, discardcasevariations, discardaccentuationvariations, glyphdistortion, enabletagger, spellingdistortion) {
763771
// FIXME: find a way to do a proper deep merge
764772
const conf = Object.assign({}, configuration);
765773
if (!conf.recognitionParams) {
@@ -813,7 +821,12 @@ class MyScriptTextWeb extends PolymerElement {
813821
}
814822
if (customresources) {
815823
conf.recognitionParams.v4.text.configuration.customResources = customresources;
816-
conf.recognitionParams.v4.text.configuration.addLKText = !nolktext;
824+
}
825+
if (customlexicon) {
826+
conf.recognitionParams.v4.text.configuration.customLexicon = customlexicon;
827+
}
828+
if (customresources || customlexicon) {
829+
conf.recognitionParams.v4.text.configuration.addLKText = !nolktext;
817830
}
818831
if (textinputmode) {
819832
conf.recognitionParams.v3.textParameter.textInputMode = textinputmode;
@@ -888,6 +901,7 @@ class MyScriptTextWeb extends PolymerElement {
888901
this.smartguidefadeoutduration,
889902
this.nolktext,
890903
this.customresources,
904+
this.customlexicon,
891905
this.textinputmode,
892906
this.resultdetail,
893907
this.contenttypes,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<!-- Those meta make the capture of handwriting inputs easier on mobile devices -->
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
8+
<meta name="apple-mobile-web-app-capable" content="yes">
9+
<meta name="mobile-web-app-capable" content="yes">
10+
<meta name="HandheldFriendly" content="true"/>
11+
12+
<title>Get started</title>
13+
14+
<link rel="stylesheet" href="../examples.css">
15+
16+
<script src="../../../../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
17+
<script type="module" src="../../../../myscript-text-web.js"></script>
18+
<style>
19+
.description {
20+
margin: 12px;
21+
}
22+
</style>
23+
</head>
24+
25+
<body>
26+
<input type="text" class="input-field" id="lexicon" data-type="text/plain" placeholder="Add your own lexicon (space-separated)">
27+
<button class="classic-btn" id="reinit">Reinit</button>
28+
<myscript-text-web scheme="https"
29+
host="webdemoapi.myscript.com"
30+
applicationkey="515131ab-35fa-411c-bb4d-3917e00faf60"
31+
hmackey="54b2ca8a-6752-469d-87dd-553bb450e9ad"
32+
touch-action="none">
33+
</myscript-text-web>
34+
<script>
35+
window.addEventListener('load', () => {
36+
37+
const textElement = document.querySelector('myscript-text-web');
38+
const reinitButton = document.getElementById('reinit');
39+
const lexicon = document.getElementById('lexicon');
40+
41+
reinitButton.addEventListener('click', function () {
42+
const values = lexicon.value;
43+
textElement.unloaded = true;
44+
textElement.customlexicon = values.split(' ');
45+
textElement.unloaded = false;
46+
});
47+
});
48+
</script>
49+
</body>
50+
</html>

src/demo-app/examples/v4/custom_resources.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
</head>
2424

2525
<body>
26-
<p class="description">Custom resources: <b>Dinosaurs</b>. Try to write some dinosaurs name!</p>
27-
<myscript-text-web scheme="https"
28-
host="webdemoapi.myscript.com"
26+
<p class="description">Pre-loaded custom resources: <b>Dinosaurs</b>. Try to write some dinosaurs name!</p>
27+
<myscript-text-web scheme="http"
28+
host="localhost:8897"
2929
applicationkey="515131ab-35fa-411c-bb4d-3917e00faf60"
3030
hmackey="54b2ca8a-6752-469d-87dd-553bb450e9ad"
3131
touch-action="none"

0 commit comments

Comments
 (0)