Overview
Comment: | [core][fx][cli] syntax analysis and new lexicographer |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | cli | core | fx | salxg |
Files: | files | file ages | folders |
SHA3-256: |
79e9913b4f708b48bbbec398a1330802 |
User & Date: | olr on 2020-08-22 15:23:25 |
Other Links: | branch diff | manifest | tags |
Context
2020-08-23
| ||
05:28 | [graphspell][js] update tags check-in: f6092331a8 user: olr tags: graphspell, salxg | |
2020-08-22
| ||
15:23 | [core][fx][cli] syntax analysis and new lexicographer check-in: 79e9913b4f user: olr tags: cli, core, fx, salxg | |
2020-08-20
| ||
12:02 | [fr] faux positifs et ajustements check-in: 11a61c0c94 user: olr tags: trunk, fr | |
Changes
Modified gc_core/js/lang_core/gc_engine.js from [1328582cce] to [a10785f066].
︙ | |||
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | + + - + - + - + - - - - - - - + + + + + + + + + + + + + + + | // parse paragraph try { this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext); } catch (e) { console.error(e); } this.lTokens = null; this.lTokens0 = null; let lParagraphErrors = null; if (bFullInfo) { lParagraphErrors = Array.from(this.dError.values()); this.dSentenceError.clear(); } // parse sentence let sText = this._getCleanText(); let lSentences = []; let oSentence = null; for (let [iStart, iEnd] of text.getSentenceBoundaries(sText)) { try { this.sSentence = sText.slice(iStart, iEnd); this.sSentence0 = this.sText0.slice(iStart, iEnd); this.nOffsetWithinParagraph = iStart; |
︙ | |||
370 371 372 373 374 375 376 | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | - + - + | if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("lMorph")) { oToken["lMorph"] = this.dTokenPos.get(oToken["nStart"])["lMorph"]; } if (this.dTokenPos.gl_get(oToken["nStart"], {}).hasOwnProperty("aTags")) { oToken["aTags"] = this.dTokenPos.get(oToken["nStart"])["aTags"]; } } |
︙ | |||
612 613 614 615 616 617 618 | 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | - + | } parseGraph (oGraph, sCountry="${country_default}", dOptions=null, bShowRuleId=false, bDebug=false, bContext=false) { // parse graph with tokens from the text and execute actions encountered let lPointer = []; let bTagAndRewrite = false; try { |
︙ | |||
664 665 666 667 668 669 670 | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | - - + + - + - - + + - + - - + + - + - - + + - + - + - - + + - - + + | // Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] // TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] // Disambiguator [ option, condition, "=", replacement/suggestion/action ] // Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] // Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] // Test [ option, condition, ">", "" ] if (!sOption || dOptions.gl_get(sOption, false)) { |
︙ | |||
806 807 808 809 810 811 812 | 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 | - - + + - + - - + + | return this._createError(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext); } _createErrorFromTokens (sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext) { // suggestions let lSugg = []; if (sSugg.startsWith("=")) { |
︙ | |||
851 852 853 854 855 856 857 | 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 | - + - + | return oErr; } _expand (sText, nTokenOffset, nLastToken) { let m; while ((m = /\\(-?[0-9]+)/.exec(sText)) !== null) { if (m[1].slice(0,1) == "-") { |
︙ | |||
892 893 894 895 896 897 898 | 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | - + - + - + - + - + - - + + - + - + - + - + + - + + + | } _tagAndPrepareTokenForRewriting (sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug) { // text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position if (sWhat === "*") { // purge text if (nTokenRewriteEnd - nTokenRewriteStart == 0) { |
︙ | |||
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | + + + - - + + + + + + | this.dTokenPos.delete(oToken["nStart"]); } catch (e) { console.log(this.asString()); console.log(oToken); } } if (this.lTokens0 !== null && bKeepToken0) { lNewTokens0.push(oToken); } } if (bDebug) { console.log(" TEXT REWRITED: " + this.sSentence); } |
︙ |
Modified gc_core/py/lang_core/gc_engine.py from [472d04d897] to [dc7c0547ff].
︙ | |||
231 232 233 234 235 236 237 | 231 232 233 234 235 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 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | - + - + + + - - + + - - - - - + - - + + + + + + + + + + + + | def __init__ (self, sText): self.sText = sText self.sText0 = sText self.sSentence = "" self.sSentence0 = "" self.nOffsetWithinParagraph = 0 |
︙ | |||
377 378 379 380 381 382 383 | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | - - + + - - + + | self.sText = sText else: self.sSentence = sText def update (self, sSentence, bDebug=False): "update <sSentence> and retokenize" self.sSentence = sSentence |
︙ | |||
548 549 550 551 552 553 554 | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | - + | dPointer2 = { "iToken1": iToken1, "iNode": dNode["<>"], "bKeep": True } yield from self._getNextPointers(dToken, dGraph, dPointer2, bDebug) def parseGraph (self, dGraph, sCountry="${country_default}", dOptions=None, bShowRuleId=False, bDebug=False, bContext=False): "parse graph with tokens from the text and execute actions encountered" lPointer = [] bTagAndRewrite = False |
︙ | |||
589 590 591 592 593 594 595 | 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 674 675 676 | - + - + - - + + - + - + - + - - + + - + - + - - + + - - + + | # Suggestion [ option, condition, "-", replacement/suggestion/action, iTokenStart, iTokenEnd, cStartLimit, cEndLimit, bCaseSvty, nPriority, sMessage, iURL ] # TextProcessor [ option, condition, "~", replacement/suggestion/action, iTokenStart, iTokenEnd, bCaseSvty ] # Disambiguator [ option, condition, "=", replacement/suggestion/action ] # Tag [ option, condition, "/", replacement/suggestion/action, iTokenStart, iTokenEnd ] # Immunity [ option, condition, "!", "", iTokenStart, iTokenEnd ] # Test [ option, condition, ">", "" ] if not sOption or dOptions.get(sOption, False): |
︙ | |||
692 693 694 695 696 697 698 | 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | - + - + - + | if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) return self._createErrorAsDict(nStart, nEnd, sLineId, sRuleId, sOption, sMessage, lSugg, sURL, bContext) def _createErrorFromTokens (self, sSugg, nTokenOffset, nLastToken, iFirstToken, nStart, nEnd, sLineId, sRuleId, bCaseSvty, sMsg, sURL, bShowRuleId, sOption, bContext): # suggestions if sSugg[0:1] == "=": |
︙ | |||
750 751 752 753 754 755 756 | 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | - + - + | dErr['sBefore'] = self.sText0[max(0,nStart-80):nStart] dErr['sAfter'] = self.sText0[nEnd:nEnd+80] return dErr def _expand (self, sText, nTokenOffset, nLastToken): for m in re.finditer(r"\\(-?[0-9]+)", sText): if m.group(1)[0:1] == "-": |
︙ | |||
779 780 781 782 783 784 785 | 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 | - + - + - + - + - + - + - + - + - + - + + - + - + + + + + - + + - + + + - - + + + + + | return sText[0:m.start(iGroup)] + sNew + sText[m.end(iGroup):] def _tagAndPrepareTokenForRewriting (self, sWhat, nTokenRewriteStart, nTokenRewriteEnd, nTokenOffset, nLastToken, bCaseSvty, bDebug): "text processor: rewrite tokens between <nTokenRewriteStart> and <nTokenRewriteEnd> position" if sWhat == "*": # purge text if nTokenRewriteEnd - nTokenRewriteStart == 0: |
Modified gc_lang/fr/webext/content_scripts/init.js from [d6a977e5a7] to [b54947b0d1].
︙ | |||
340 341 342 343 344 345 346 | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | - - + + - - + + | this.send("parseAndSpellcheck", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination }); }, parseAndSpellcheck1: function (sText, sDestination, sParagraphId) { this.send("parseAndSpellcheck1", { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, { sDestination: sDestination, sParagraphId: sParagraphId }); }, |
︙ | |||
418 419 420 421 422 423 424 | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | - + + + + - - - - - + + + + + + | break; case "parseAndSpellcheck1": if (oInfo.sDestination == "__GrammalectePanel__") { oGrammalecte.oGCPanel.refreshParagraph(oInfo.sParagraphId, result); } break; case "parseFull": |
︙ |
Modified gc_lang/fr/webext/content_scripts/panel_gc.css from [9a73dd19f8] to [89a25fc756].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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 | + + - - - - | /* Grammar checker */ div#grammalecte_gc_panel_content { position: absolute; height: 100%; width: 100%; margin: 0; overflow: auto; } div.grammalecte_paragraph_block { margin: 5px 5px 0 5px; background-color: hsl(0, 0%, 96%); border-radius: 2px; } |
︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | + + + + + + + | cursor: pointer; font-family: "Trebuchet MS", "Fira Sans", "Liberation Sans", sans-serif; font-size: 14px; color: hsl(0, 0%, 96%); border-radius: 2px; } div.grammalecte_paragraph_actions .grammalecte_blue { color: hsl(0, 0%, 80%); } div.grammalecte_paragraph_actions .grammalecte_blue:hover { background-color: hsl(210, 50%, 40%); color: hsl(0, 0%, 100%); } div.grammalecte_paragraph_actions .grammalecte_green { color: hsl(0, 0%, 80%); } div.grammalecte_paragraph_actions .grammalecte_green:hover { background-color: hsl(120, 50%, 40%); color: hsl(0, 0%, 100%); } |
︙ |
Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [5158e88aeb] to [14ecf7a831].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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 | 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; |
︙ | |||
110 111 112 113 114 115 116 | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | - - - - | oGrammalecte.bAutoRefresh = this.bAutoRefresh; browser.storage.local.set({"autorefresh_option": this.bAutoRefresh}); this.setAutoRefreshButton(); } this.xLxgButton.onclick = () => { if (!this.bWorking) { this.showLexicographer(); |
︙ | |||
236 237 238 239 240 241 242 | 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)) { |
︙ | |||
528 529 530 531 532 533 534 | 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; |
︙ | |||
598 599 600 601 602 603 604 | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | - - - - - - | return xTokenDescr; } catch (e) { showError(e); } } |
︙ |
Modified gc_lang/fr/webext/content_scripts/panel_lxg.css from [ae4f6ddf8d] to [1a476d12b0].
1 2 3 4 5 6 7 8 9 10 11 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + - + - + | /* Lexicographer */ div#grammalecte_lxg_panel_content { display: none; position: absolute; height: 100%; width: 100%; font-size: 13px; } div#grammalecte_lxg_input_block { padding: 10px; /*background-color: hsl(210, 50%, 95%);*/ /*border-bottom: solid 1px hsl(210, 0%, 90%);*/ text-align: right; } div#grammalecte_lxg_result_zone { } div#grammalecte_lxg_input { min-height: 100px; padding: 10px; background-color: hsl(210, 0%, 100%); border: solid 1px hsl(210, 20%, 80%); border-radius: 3px; font-family: "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; text-align: left; } div#grammalecte_lxg_input_button { display: inline-block; margin: 0 10px 0 0; padding: 3px 10px; background-color: hsl(210, 50%, 50%); color: hsl(210, 50%, 98%); text-align: center; cursor: pointer; border-radius: 0 0 3px 3px; } |
︙ |
Modified gc_lang/fr/webext/gce_worker.js from [e351d5e6fd] to [b9ffc9c0b7].
︙ | |||
227 228 229 230 231 232 233 | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | - + - - + - - - + + - - - - + - + | function parseAndSpellcheck1 (sParagraph, sCountry, bDebug, bContext, oInfo={}) { sParagraph = sParagraph.replace(//g, "").normalize("NFC"); let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, null, bContext); let aSpellErr = oSpellChecker.parseParagraph(sParagraph); postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, oInfo, true)); } |
︙ |
Modified grammalecte-cli.py from [0e5de0a660] to [d8f015f794].
︙ | |||
338 339 340 341 342 343 344 | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | - + | if xArgs.textformatter: sParagraph = oTextFormatter.formatText(sParagraph) lParagraphErrors, lSentences = oGrammarChecker.gce.parse(sParagraph, bDebug=xArgs.debug, bFullInfo=True) echo(txt.getReadableErrors(lParagraphErrors, xArgs.width)) for dSentence in lSentences: echo("{nStart}:{nEnd}".format(**dSentence)) echo(" <" + dSentence["sSentence"]+">") |
︙ |