Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -210,10 +210,15 @@ this.parseText(this.sText, this.sText0, true, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext); } catch (e) { console.error(e); } + 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)) { @@ -228,15 +233,20 @@ this.dTokenPos.set(dToken["nStart"], dToken); } } if (bFullInfo) { oSentence = { "nStart": iStart, "nEnd": iEnd, "sSentence": this.sSentence, "lToken": Array.from(this.lToken) }; + for (let oToken of oSentence["lToken"]) { + if (oToken["sType"] == "WORD") { + oToken["bValidToken"] = _oSpellChecker.isValidToken(oToken["sValue"]); + } + } // the list of tokens is duplicated, to keep all tokens from being deleted when analysis } this.parseText(this.sSentence, this.sSentence0, false, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext); if (bFullInfo) { - oSentence["aGrammarErrors"] = Array.from(this.dSentenceError.values()); + oSentence["lGrammarErrors"] = Array.from(this.dSentenceError.values()); lSentences.push(oSentence); this.dSentenceError.clear(); } } catch (e) { @@ -243,11 +253,11 @@ console.error(e); } } if (bFullInfo) { // Grammar checking and sentence analysis - return lSentences; + return [lParagraphErrors, lSentences]; } else { // Grammar checking only return Array.from(this.dError.values()); } } Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -193,11 +193,11 @@ #### Parsing def parse (sText, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False, bFullInfo=False): - "init point to analyse and returns an iterable of errors or (with option ) a list of sentences with tokens and errors" + "init point to analyse and returns an iterable of errors or (with option ) paragraphs errors and sentences with tokens and errors" oText = TextParser(sText) return oText.parse(sCountry, bDebug, dOptions, bContext, bFullInfo) #### TEXT PARSER @@ -232,22 +232,25 @@ #for nPos, dToken in self.dTokenPos.items(): # s += "{}\t{}\n".format(nPos, dToken) return s def parse (self, sCountry="${country_default}", bDebug=False, dOptions=None, bContext=False, bFullInfo=False): - "analyses and returns an iterable of errors or (with option ) a list of sentences with tokens and errors" + "analyses and returns an iterable of errors or (with option ) paragraphs errors and sentences with tokens and errors" #sText = unicodedata.normalize("NFC", sText) dOpt = dOptions or _dOptions bShowRuleId = option('idrule') # parse paragraph try: self.parseText(self.sText, self.sText0, True, 0, sCountry, dOpt, bShowRuleId, bDebug, bContext) except: raise + if bFullInfo: + lParagraphErrors = list(self.dError.values()) + lSentences = [] + self.dSentenceError.clear() # parse sentences sText = self._getCleanText() - lSentences = [] for iStart, iEnd in text.getSentenceBoundaries(sText): if 4 < (iEnd - iStart) < 2000: try: self.sSentence = sText[iStart:iEnd] self.sSentence0 = self.sText0[iStart:iEnd] @@ -254,21 +257,24 @@ self.nOffsetWithinParagraph = iStart self.lToken = list(_oTokenizer.genTokens(self.sSentence, True)) self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lToken if dToken["sType"] != "INFO" } if bFullInfo: dSentence = { "nStart": iStart, "nEnd": iEnd, "sSentence": self.sSentence, "lToken": list(self.lToken) } + for dToken in dSentence["lToken"]: + if dToken["sType"] == "WORD": + dToken["bValidToken"] = _oSpellChecker.isValidToken(dToken["sValue"]) # the list of tokens is duplicated, to keep all tokens from being deleted when analysis self.parseText(self.sSentence, self.sSentence0, False, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext) if bFullInfo: - dSentence["aGrammarErrors"] = list(self.dSentenceError.values()) + dSentence["lGrammarErrors"] = list(self.dSentenceError.values()) lSentences.append(dSentence) self.dSentenceError.clear() except: raise if bFullInfo: # Grammar checking and sentence analysis - return lSentences + return lParagraphErrors, lSentences else: # Grammar checking only return self.dError.values() # this is a view (iterable) def _getCleanText (self):