1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
// JavaScript
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global GrammalectePanel, oGrammalecte, oGrammalecteBackgroundPort, showError, window, document, console */
"use strict";
function onGrammalecteGCPanelClick (xEvent) {
try {
let xElem = xEvent.target;
if (xElem.id) {
if (xElem.id.startsWith("grammalecte_sugg")) {
oGrammalecte.oGCPanel.applySuggestion(xElem.id);
} else if (xElem.id === "grammalecte_tooltip_ignore") {
oGrammalecte.oGCPanel.ignoreError(xElem.id);
} else if (xElem.id.startsWith("grammalecte_check")) {
oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num, 10));
} else if (xElem.id.startsWith("grammalecte_hide")) {
xElem.parentNode.parentNode.style.display = "none";
} else if (xElem.id.startsWith("grammalecte_err")
&& xElem.className !== "grammalecte_error_corrected"
&& xElem.className !== "grammalecte_error_ignored") {
|
>
>
>
|
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
|
// JavaScript
/* jshint esversion:6, -W097 */
/* jslint esversion:6 */
/* global GrammalectePanel, oGrammalecte, oGrammalecteBackgroundPort, showError, window, document, console */
"use strict";
function onGrammalecteGCPanelClick (xEvent) {
try {
let xElem = xEvent.target;
if (xElem.id) {
if (xElem.id.startsWith("grammalecte_sugg")) {
oGrammalecte.oGCPanel.applySuggestion(xElem.id);
} else if (xElem.id === "grammalecte_tooltip_ignore") {
oGrammalecte.oGCPanel.ignoreError(xElem.id);
} else if (xElem.id.startsWith("grammalecte_analysis")) {
oGrammalecte.oGCPanel.sendParagraphToGrammaticalAnalysis(parseInt(xElem.dataset.para_num, 10));
} else if (xElem.id.startsWith("grammalecte_check")) {
oGrammalecte.oGCPanel.recheckParagraph(parseInt(xElem.dataset.para_num, 10));
} else if (xElem.id.startsWith("grammalecte_hide")) {
xElem.parentNode.parentNode.style.display = "none";
} else if (xElem.id.startsWith("grammalecte_err")
&& xElem.className !== "grammalecte_error_corrected"
&& xElem.className !== "grammalecte_error_ignored") {
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
this.oTextControl = null;
this.nLastResult = 0;
this.iLastEditedParagraph = -1;
this.nParagraph = 0;
// Lexicographer
this.nLxgCount = 0;
this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"});
this.xPanelContent.appendChild(this.xLxgPanelContent);
// Conjugueur
this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"});
this.xConjPanelContent.innerHTML = sGrammalecteConjugueurHTML; // @Reviewers: sGrammalecteConjugueurHTML is a const value defined in <content_scripts/html_src.js>
this.xPanelContent.appendChild(this.xConjPanelContent);
this.sVerb = "";
this.bListenConj = false;
|
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
this.oTextControl = null;
this.nLastResult = 0;
this.iLastEditedParagraph = -1;
this.nParagraph = 0;
// Lexicographer
this.nLxgCount = 0;
this.xLxgPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_lxg_panel_content"});
this.xLxgInputBlock = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_block"});
this.xLxgInput = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input", lang: "fr", contentEditable: "true"});
this.xLxgInputButton = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_button", textContent: "Analyse grammaticale"});
this.xLxgInputButton.addEventListener("click", () => { this.grammaticalAnalysis(); }, false);
this.xLxgInputButton2 = oGrammalecte.createNode("div", {id: "grammalecte_lxg_input_button", textContent: "Analyse lexicale"});
this.xLxgInputButton2.addEventListener("click", () => { this.getListOfTokens(); }, false);
this.xLxgInputBlock.appendChild(this.xLxgInput);
this.xLxgInputBlock.appendChild(this.xLxgInputButton);
this.xLxgInputBlock.appendChild(this.xLxgInputButton2);
this.xLxgPanelContent.appendChild(this.xLxgInputBlock);
this.xLxgResultZone = oGrammalecte.createNode("div", {id: "grammalecte_lxg_result_zone"});
this.xLxgPanelContent.appendChild(this.xLxgResultZone);
this.xPanelContent.appendChild(this.xLxgPanelContent);
// Conjugueur
this.xConjPanelContent = oGrammalecte.createNode("div", {id: "grammalecte_conj_panel_content"});
this.xConjPanelContent.innerHTML = sGrammalecteConjugueurHTML; // @Reviewers: sGrammalecteConjugueurHTML is a const value defined in <content_scripts/html_src.js>
this.xPanelContent.appendChild(this.xConjPanelContent);
this.sVerb = "";
this.bListenConj = false;
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
this.oTextControl.clear();
}
addParagraphResult (oResult) {
try {
this.resetTimer();
if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) {
let xNodeDiv = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_block"});
// actions
let xActionsBar = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_actions"});
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum}));
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"}));
// paragraph
let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.dataset.timer_id = "0";
xParagraph.addEventListener("input", function (xEvent) {
if (this.bAutoRefresh) {
// timer for refreshing analysis
window.clearTimeout(parseInt(xParagraph.dataset.timer_id, 10));
xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum);
this.iLastEditedParagraph = oResult.iParaNum;
}
// write text
this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num, 10), xEvent.target.textContent);
}.bind(this)
, true);
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
xNodeDiv.appendChild(xActionsBar);
xNodeDiv.appendChild(xParagraph);
this.xParagraphList.appendChild(xNodeDiv);
this.nParagraph += 1;
}
}
catch (e) {
showError(e);
}
}
|
<
>
>
|
|
|
|
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
this.oTextControl.clear();
}
addParagraphResult (oResult) {
try {
this.resetTimer();
if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) {
// actions
let xActionsBar = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_actions"});
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum}));
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_analysis" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_blue", textContent: "»", title: "Analyse grammaticale…"}, {para_num: oResult.iParaNum}));
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"}));
// paragraph
let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.dataset.timer_id = "0";
xParagraph.addEventListener("input", function (xEvent) {
if (this.bAutoRefresh) {
// timer for refreshing analysis
window.clearTimeout(parseInt(xParagraph.dataset.timer_id, 10));
xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum);
this.iLastEditedParagraph = oResult.iParaNum;
}
// write text
this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num, 10), xEvent.target.textContent);
}.bind(this)
, true);
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
let xParagraphBlock = oGrammalecte.createNode("div", {className: "grammalecte_paragraph_block"});
xParagraphBlock.appendChild(xActionsBar);
xParagraphBlock.appendChild(xParagraph);
this.xParagraphList.appendChild(xParagraphBlock);
this.nParagraph += 1;
}
}
catch (e) {
showError(e);
}
}
|
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
}
}
// Lexicographer
clearLexicographer () {
this.nLxgCount = 0;
while (this.xLxgPanelContent.firstChild) {
this.xLxgPanelContent.removeChild(this.xLxgPanelContent.firstChild);
}
}
addLxgSeparator (sText) {
if (this.xLxgPanelContent.textContent !== "") {
this.xLxgPanelContent.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_separator", textContent: sText}));
}
}
addMessageToLxgPanel (sMessage) {
let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_message", textContent: sMessage});
this.xLxgPanelContent.appendChild(xNode);
}
addListOfTokens (lToken) {
try {
if (lToken) {
this.nLxgCount += 1;
let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"});
xTokenList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount}));
for (let oToken of lToken) {
xTokenList.appendChild(this._createTokenBlock(oToken));
}
this.xLxgPanelContent.appendChild(xTokenList);
}
}
catch (e) {
showError(e);
}
}
|
|
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
|
>
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
>
>
|
|
>
|
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
}
}
// Lexicographer
clearLexicographer () {
this.nLxgCount = 0;
while (this.xLxgResultZone.firstChild) {
this.xLxgResultZone.removeChild(this.xLxgResultZone.firstChild);
}
}
// Grammatical analysis
sendParagraphToGrammaticalAnalysis (iParaNum) {
let xParagraph = this.xParent.getElementById("grammalecte_paragraph" + iParaNum);
this.xLxgInput.textContent = xParagraph.textContent;
this.grammaticalAnalysis();
this.showLexicographer();
}
grammaticalAnalysis (iParaNum) {
if (!this.bOpened || this.bWorking) {
return;
}
this.startWaitIcon();
this.clearLexicographer();
let sText = this.xLxgInput.innerText.replace(/\n/g, " ");
console.log(sText);
oGrammalecteBackgroundPort.parseFull(sText, "__GrammalectePanel__");
}
showParagraphAnalysis (oResult) {
if (!this.bOpened || oResult === null) {
return;
}
try {
for (let oSentence of oResult.lSentences) {
this.nLxgCount += 1;
if (oSentence.sSentence.trim() !== "") {
let xSentenceBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_paragraph_sentence_block"});
xSentenceBlock.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount}));
xSentenceBlock.appendChild(oGrammalecte.createNode("p", {className: "grammalecte_lxg_paragraph_sentence", textContent: oSentence.sSentence}));
let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"});
for (let oToken of oSentence.lTokens) {
if (oToken["sType"] != "INFO") {
xTokenList.appendChild(this._createTokenBlock2(oToken));
}
}
xSentenceBlock.appendChild(xTokenList);
this.xLxgResultZone.appendChild(xSentenceBlock);
}
}
}
catch (e) {
showError(e);
}
this.stopWaitIcon();
}
_createTokenBlock2 (oToken) {
let xTokenBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_block"});
// token description
xTokenBlock.appendChild(this._createTokenDescr2(oToken));
// subtoken description
if (oToken.aSubElem) {
let xSubBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_subblock"});
for (let oSubElem of oToken.aSubElem) {
xSubBlock.appendChild(this._createTokenDescr2(oSubElem));
}
xTokenBlock.appendChild(xSubBlock);
}
return xTokenBlock;
}
_createTokenDescr2 (oToken) {
try {
let xTokenDescr = oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_descr"});
if (oToken.sType == "LOCP") {
xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_also", textContent: "possiblement › "}));
}
xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token grammalecte_lxg_token_" + oToken.sType, textContent: oToken.sValue}));
xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_token_colon", textContent: ":"}));
if (oToken.lMorph.length < 2) {
// one morphology only
xTokenDescr.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem_inline", textContent: oToken.lMorph[0]}));
} else {
// several morphology
let xMorphList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_list"});
for (let sLabel of oToken.lMorph) {
xMorphList.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_morph_elem", textContent: "• " + sLabel}));
}
xTokenDescr.appendChild(xMorphList);
}
return xTokenDescr;
}
catch (e) {
showError(e);
}
}
// Lexical analysis
getListOfTokens () {
if (!this.bOpened || this.bWorking) {
return;
}
this.startWaitIcon();
this.clearLexicographer();
let sText = this.xLxgInput.innerText; // to get carriage return (\n)
console.log(sText);
oGrammalecteBackgroundPort.getListOfTokens(sText, "__GrammalectePanel__");
}
addListOfTokens (oResult) {
try {
if (oResult && oResult.sParagraph != "") {
this.nLxgCount += 1;
let xSentenceBlock = oGrammalecte.createNode("div", {className: "grammalecte_lxg_paragraph_sentence_block"});
xSentenceBlock.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_num", textContent: this.nLxgCount}));
xSentenceBlock.appendChild(oGrammalecte.createNode("p", {className: "grammalecte_lxg_paragraph_sentence", textContent: oResult.sParagraph}));
let xTokenList = oGrammalecte.createNode("div", {className: "grammalecte_lxg_list_of_tokens"});
for (let oToken of oResult.lTokens) {
xTokenList.appendChild(this._createTokenBlock(oToken));
}
xSentenceBlock.appendChild(xTokenList);
this.xLxgResultZone.appendChild(xSentenceBlock);
}
}
catch (e) {
showError(e);
}
}
|
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
return xTokenDescr;
}
catch (e) {
showError(e);
}
}
setHidden (sClass, bHidden) {
let xPanelContent = this.xParent.getElementById('grammalecte_panel_content');
for (let xNode of xPanelContent.getElementsByClassName(sClass)) {
xNode.hidden = bHidden;
}
}
// Conjugueur
listenConj () {
if (!this.bListenConj) {
// button
this.xParent.getElementById('grammalecte_conj_button').addEventListener("click", (e) => { this.conjugateVerb(); });
|
<
<
<
<
<
<
|
704
705
706
707
708
709
710
711
712
713
714
715
716
717
|
return xTokenDescr;
}
catch (e) {
showError(e);
}
}
// Conjugueur
listenConj () {
if (!this.bListenConj) {
// button
this.xParent.getElementById('grammalecte_conj_button').addEventListener("click", (e) => { this.conjugateVerb(); });
|