Overview
Comment: | [core][fr] code cleaning (pylint) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | fr | core |
Files: | files | file ages | folders |
SHA3-256: |
2c639e2d925f312eca88f05c0c7ddcee |
User & Date: | olr on 2019-05-11 15:54:20 |
Other Links: | manifest | tags |
Context
2019-05-11
| ||
17:34 | [fr] conjugaisons: sujets nous/vous, ajustements check-in: 2b2c772a7d user: olr tags: trunk, fr | |
15:54 | [core][fr] code cleaning (pylint) check-in: 2c639e2d92 user: olr tags: trunk, fr, core | |
15:17 | [fr] erreur de paramètre check-in: 249d9c7d08 user: olr tags: trunk, fr | |
Changes
Modified gc_core/py/lang_core/gc_engine.py from [cf7715eca3] to [0d99523db5].
︙ | ︙ | |||
100 101 102 103 104 105 106 | _rules_graph = gc_rules_graph # compile rules regex for sOption, lRuleGroup in chain(_rules.lParagraphRules, _rules.lSentenceRules): if sOption != "@@@@": for aRule in lRuleGroup: try: aRule[0] = re.compile(aRule[0]) | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | _rules_graph = gc_rules_graph # compile rules regex for sOption, lRuleGroup in chain(_rules.lParagraphRules, _rules.lSentenceRules): if sOption != "@@@@": for aRule in lRuleGroup: try: aRule[0] = re.compile(aRule[0]) except (IndexError, re.error): echo("Bad regular expression in # " + str(aRule[2])) aRule[0] = "(?i)<Grammalecte>" def ignoreRule (sRuleId): "disable rule <sRuleId>" _aIgnoredRules.add(sRuleId) |
︙ | ︙ | |||
125 126 127 128 129 130 131 | def listRules (sFilter=None): "generator: returns typle (sOption, sLineId, sRuleId)" if sFilter: try: zFilter = re.compile(sFilter) | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | def listRules (sFilter=None): "generator: returns typle (sOption, sLineId, sRuleId)" if sFilter: try: zFilter = re.compile(sFilter) except re.error: echo("# Error. List rules: wrong regex.") sFilter = None for sOption, lRuleGroup in chain(_getRules(True), _getRules(False)): if sOption != "@@@@": for _, _, sLineId, sRuleId, _, _ in lRuleGroup: if not sFilter or zFilter.search(sRuleId): yield (sOption, sLineId, sRuleId) |
︙ | ︙ | |||
276 277 278 279 280 281 282 283 284 285 286 287 288 289 | self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lToken if dToken["sType"] != "INFO" } self.parseText(self.sSentence, self.sSentence0, False, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext) except: raise return self.dError.values() # this is a view (iterable) def parseText (self, sText, sText0, bParagraph, nOffset, sCountry, dOptions, bShowRuleId, bDebug, bContext): bChange = False for sOption, lRuleGroup in _getRules(bParagraph): if sOption == "@@@@": # graph rules if not bParagraph and bChange: self.update(sText, bDebug) bChange = False | > | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | self.dTokenPos = { dToken["nStart"]: dToken for dToken in self.lToken if dToken["sType"] != "INFO" } self.parseText(self.sSentence, self.sSentence0, False, iStart, sCountry, dOpt, bShowRuleId, bDebug, bContext) except: raise return self.dError.values() # this is a view (iterable) def parseText (self, sText, sText0, bParagraph, nOffset, sCountry, dOptions, bShowRuleId, bDebug, bContext): "parse the text with rules" bChange = False for sOption, lRuleGroup in _getRules(bParagraph): if sOption == "@@@@": # graph rules if not bParagraph and bChange: self.update(sText, bDebug) bChange = False |
︙ | ︙ | |||
613 614 615 616 617 618 619 | # Message sMessage = globals()[sMsg[1:]](sText, m) if sMsg[0:1] == "=" else m.expand(sMsg) if bShowRuleId: sMessage += " # " + sLineId + " # " + sRuleId # if _bWriterError: return self._createErrorForWriter(nStart, nEnd - nStart, sRuleId, sOption, sMessage, lSugg, sURL) | < | < | | 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 | # Message sMessage = globals()[sMsg[1:]](sText, m) if sMsg[0:1] == "=" else m.expand(sMsg) if bShowRuleId: sMessage += " # " + sLineId + " # " + sRuleId # 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] == "=": sSugg = globals()[sSugg[1:]](self.lToken, nTokenOffset, nLastToken) lSugg = sSugg.split("|") if sSugg else [] elif sSugg == "_": lSugg = [] else: lSugg = self._expand(sSugg, nTokenOffset, nLastToken).split("|") if bCaseSvty and lSugg and self.lToken[iFirstToken]["sValue"][0:1].isupper(): lSugg = list(map(lambda s: s[0:1].upper()+s[1:], lSugg)) # Message sMessage = globals()[sMsg[1:]](self.lToken, nTokenOffset, nLastToken) if sMsg[0:1] == "=" else self._expand(sMsg, nTokenOffset, nLastToken) if bShowRuleId: sMessage += " " + sLineId + " # " + sRuleId # 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 _createErrorForWriter (self, nStart, nLen, sRuleId, sOption, sMessage, lSugg, sURL): xErr = SingleProofreadingError() # uno.createUnoStruct( "com.sun.star.linguistic2.SingleProofreadingError" ) xErr.nErrorStart = nStart xErr.nErrorLength = nLen xErr.nErrorType = PROOFREADING xErr.aRuleIdentifier = sRuleId |
︙ | ︙ | |||
750 751 752 753 754 755 756 | def rewriteFromTags (self, bDebug=False): "rewrite the sentence, modify tokens, purge the token list" if bDebug: echo("REWRITE") lNewToken = [] nMergeUntil = 0 | | | 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | def rewriteFromTags (self, bDebug=False): "rewrite the sentence, modify tokens, purge the token list" if bDebug: echo("REWRITE") lNewToken = [] nMergeUntil = 0 dTokenMerger = {} for iToken, dToken in enumerate(self.lToken): bKeepToken = True if dToken["sType"] != "INFO": if nMergeUntil and iToken <= nMergeUntil: dTokenMerger["sValue"] += " " * (dToken["nStart"] - dTokenMerger["nEnd"]) + dToken["sValue"] dTokenMerger["nEnd"] = dToken["nEnd"] if bDebug: |
︙ | ︙ | |||
787 788 789 790 791 792 793 | nDiffLen = len(dToken["sRealValue"]) - len(dToken["sNewValue"]) sNewRepl = (dToken["sNewValue"] + " " * nDiffLen) if nDiffLen >= 0 else dToken["sNewValue"][:len(dToken["sRealValue"])] self.sSentence = self.sSentence[:dToken["nStart"]] + sNewRepl + self.sSentence[dToken["nEnd"]:] del dToken["sNewValue"] else: try: del self.dTokenPos[dToken["nStart"]] | | < | 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 | nDiffLen = len(dToken["sRealValue"]) - len(dToken["sNewValue"]) sNewRepl = (dToken["sNewValue"] + " " * nDiffLen) if nDiffLen >= 0 else dToken["sNewValue"][:len(dToken["sRealValue"])] self.sSentence = self.sSentence[:dToken["nStart"]] + sNewRepl + self.sSentence[dToken["nEnd"]:] del dToken["sNewValue"] else: try: del self.dTokenPos[dToken["nStart"]] except KeyError: echo(self) echo(dToken) if bDebug: echo(" TEXT REWRITED: " + self.sSentence) self.lToken.clear() self.lToken = lNewToken #### common functions |
︙ | ︙ | |||
860 861 862 863 864 865 866 | "returns True if s has pattern sPattern and m.group(1) has pattern sPatternGroup1" m = re.search(sPattern, s) if not m: return False try: sWord = m.group(1) nPos = m.start(1) + nOffset | | | 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | "returns True if s has pattern sPattern and m.group(1) has pattern sPatternGroup1" m = re.search(sPattern, s) if not m: return False try: sWord = m.group(1) nPos = m.start(1) + nOffset except IndexError: return False return morph(dTokenPos, (nPos, sWord), sPatternGroup1, sNegPatternGroup1) #### Analyse groups for regex rules |
︙ | ︙ | |||
897 898 899 900 901 902 903 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) | < | | | < | | | | 895 896 897 898 899 900 901 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 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) zNegPattern = re.compile(sNegPattern) if any(zNegPattern.search(sMorph) for sMorph in lMorph): return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) def analyse (sWord, sPattern, sNegPattern=""): "analyse a word, returns True if not sNegPattern in word morphologies and sPattern in word morphologies (disambiguation off)" lMorph = _oSpellChecker.getMorph(sWord) if not lMorph: return False # check negative condition if sNegPattern: if sNegPattern == "*": zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) zNegPattern = re.compile(sNegPattern) if any(zNegPattern.search(sMorph) for sMorph in lMorph): return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) #### Analyse tokens for graph rules |
︙ | ︙ | |||
966 967 968 969 970 971 972 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) | < | | | | 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) zNegPattern = re.compile(sNegPattern) if any(zNegPattern.search(sMorph) for sMorph in lMorph): return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) def g_analyse (dToken, sPattern, sNegPattern="", nLeft=None, nRight=None, bMemorizeMorph=True): "analyse a token, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies (disambiguation off)" |
︙ | ︙ | |||
991 992 993 994 995 996 997 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) | < | | | < | | | | 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) return all(zPattern.search(sMorph) for sMorph in lMorph) zNegPattern = re.compile(sNegPattern) if any(zNegPattern.search(sMorph) for sMorph in lMorph): return False # search sPattern zPattern = re.compile(sPattern) return any(zPattern.search(sMorph) for sMorph in lMorph) def g_merged_analyse (dToken1, dToken2, cMerger, sPattern, sNegPattern="", bSetMorph=True): "merge two token values, return True if <sNegPattern> not in morphologies and <sPattern> in morphologies (disambiguation off)" lMorph = _oSpellChecker.getMorph(dToken1["sValue"] + cMerger + dToken2["sValue"]) if not lMorph: return False # check negative condition if sNegPattern: if sNegPattern == "*": # all morph must match sPattern zPattern = re.compile(sPattern) bResult = all(zPattern.search(sMorph) for sMorph in lMorph) if bResult and bSetMorph: dToken1["lMorph"] = lMorph return bResult zNegPattern = re.compile(sNegPattern) if any(zNegPattern.search(sMorph) for sMorph in lMorph): return False # search sPattern zPattern = re.compile(sPattern) bResult = any(zPattern.search(sMorph) for sMorph in lMorph) if bResult and bSetMorph: dToken1["lMorph"] = lMorph return bResult |
︙ | ︙ |
Modified gc_core/py/lang_core/gc_options.py from [d511603a82] to [b668596de4].
︙ | ︙ | |||
22 23 24 25 26 27 28 | def getOptionsColors (sTheme="Default", sColorType="aRGB"): "returns dictionary of options colors" dOptColor = _dOptColor[sTheme] if sTheme in _dOptColor else _dOptColor["Default"] dColorType = _dColorType[sColorType] if sColorType in _dColorType else _dColorType["aRGB"] try: return { sOpt: dColorType[sColor] for sOpt, sColor in dOptColor.items() } | | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | def getOptionsColors (sTheme="Default", sColorType="aRGB"): "returns dictionary of options colors" dOptColor = _dOptColor[sTheme] if sTheme in _dOptColor else _dOptColor["Default"] dColorType = _dColorType[sColorType] if sColorType in _dColorType else _dColorType["aRGB"] try: return { sOpt: dColorType[sColor] for sOpt, sColor in dOptColor.items() } except KeyError: traceback.print_exc() return {} lStructOpt = ${lStructOpt} |
︙ | ︙ |
Modified gc_lang/fr/modules/gce_analyseur.py from [252fe3713f] to [bae6058302].
1 2 3 4 5 6 7 8 9 10 11 12 13 | #### GRAMMAR CHECKING ENGINE PLUGIN: Parsing functions for French language from . import cregex as cr def g_morphVC (dToken, sPattern, sNegPattern=""): nEnd = dToken["sValue"].rfind("-") if "-t-" in dToken["sValue"]: nEnd = nEnd - 2 return g_morph(dToken, sPattern, sNegPattern, 0, nEnd, False) def rewriteSubject (s1, s2): | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #### GRAMMAR CHECKING ENGINE PLUGIN: Parsing functions for French language from . import cregex as cr def g_morphVC (dToken, sPattern, sNegPattern=""): "lance la fonction g_morph() sur la première partie d’un verbe composé (ex: vient-il)" nEnd = dToken["sValue"].rfind("-") if "-t-" in dToken["sValue"]: nEnd = nEnd - 2 return g_morph(dToken, sPattern, sNegPattern, 0, nEnd, False) def rewriteSubject (s1, s2): |
︙ | ︙ |
Modified gc_lang/fr/modules/gce_date_verif.py from [0f6e9ac587] to [489e3ffdfc].
︙ | ︙ | |||
29 30 31 32 33 34 35 | "return True if the date is valid" if not sMonth.isdigit(): sMonth = _dMonth.get(sMonth.lower(), "13") try: return datetime.date(int(sYear), int(sMonth), int(sDay)) except ValueError: return False | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | "return True if the date is valid" if not sMonth.isdigit(): sMonth = _dMonth.get(sMonth.lower(), "13") try: return datetime.date(int(sYear), int(sMonth), int(sDay)) except ValueError: return False except TypeError: return True def checkDay (sWeekday, sDay, sMonth, sYear): "return True if sWeekday is valid according to the given date" xDate = checkDate(sDay, sMonth, sYear) if xDate and _getDay(xDate) != sWeekday.lower(): |
︙ | ︙ | |||
64 65 66 67 68 69 70 | sGregorianDay = _lDay[xDate.weekday()] return _dGregorianToJulian.get(sGregorianDay, "Erreur: jour inconnu") # 1582 if xDate.month < 12 or xDate.day <= 9: # Calendrier julien sGregorianDay = _lDay[xDate.weekday()] return _dGregorianToJulian.get(sGregorianDay, "Erreur: jour inconnu") | | < | | | 64 65 66 67 68 69 70 71 72 73 74 75 | sGregorianDay = _lDay[xDate.weekday()] return _dGregorianToJulian.get(sGregorianDay, "Erreur: jour inconnu") # 1582 if xDate.month < 12 or xDate.day <= 9: # Calendrier julien sGregorianDay = _lDay[xDate.weekday()] return _dGregorianToJulian.get(sGregorianDay, "Erreur: jour inconnu") if xDate.day >= 20: # Calendrier grégorien return _lDay[xDate.weekday()] # 10 - 19 décembre 1582: jours inexistants en France. return "" |
Modified gc_lang/fr/modules/gce_suggestions.py from [6333a4318e] to [14bc22abf3].
︙ | ︙ | |||
177 178 179 180 181 182 183 | if sWordToAgree: lMorph = _oSpellChecker.getMorph(sFlex) if not lMorph: return "" sGender = cr.getGender(lMorph) if sGender == ":m": return suggMasPlur(sFlex) | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | if sWordToAgree: lMorph = _oSpellChecker.getMorph(sFlex) if not lMorph: return "" sGender = cr.getGender(lMorph) if sGender == ":m": return suggMasPlur(sFlex) if sGender == ":f": return suggFemPlur(sFlex) aSugg = set() if "-" not in sFlex: if sFlex.endswith("l"): if sFlex.endswith("al") and len(sFlex) > 2 and _oSpellChecker.isValid(sFlex[:-1]+"ux"): aSugg.add(sFlex[:-1]+"ux") if sFlex.endswith("ail") and len(sFlex) > 3 and _oSpellChecker.isValid(sFlex[:-2]+"ux"): |
︙ | ︙ | |||
415 416 417 418 419 420 421 | return "" def suggCeOrCet (sWord): "suggest “ce” or “cet” or both according to the first letter of <sWord>" if re.match("(?i)[aeéèêiouyâîï]", sWord): return "cet" | | | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | return "" def suggCeOrCet (sWord): "suggest “ce” or “cet” or both according to the first letter of <sWord>" if re.match("(?i)[aeéèêiouyâîï]", sWord): return "cet" if sWord[0:1] in "hH": return "ce|cet" return "ce" def suggLesLa (sWord): "suggest “les” or “la” according to <sWord>" if any( ":p" in sMorph for sMorph in _oSpellChecker.getMorph(sWord) ): |
︙ | ︙ | |||
471 472 473 474 475 476 477 | def formatNF (s): "typography: format NF reference (norme française)" try: m = re.match("NF[ -]?(C|E|P|Q|S|X|Z|EN(?:[ -]ISO|))[ -]?([0-9]+(?:[/‑-][0-9]+|))", s) if not m: return "" return "NF " + m.group(1).upper().replace(" ", " ").replace("-", " ") + " " + m.group(2).replace("/", "‑").replace("-", "‑") | | | | | | | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | def formatNF (s): "typography: format NF reference (norme française)" try: m = re.match("NF[ -]?(C|E|P|Q|S|X|Z|EN(?:[ -]ISO|))[ -]?([0-9]+(?:[/‑-][0-9]+|))", s) if not m: return "" return "NF " + m.group(1).upper().replace(" ", " ").replace("-", " ") + " " + m.group(2).replace("/", "‑").replace("-", "‑") except (re.error, IndexError): traceback.print_exc() return "# erreur #" def undoLigature (c): "typography: split ligature character <c> in several chars" if c == "fi": return "fi" if c == "fl": return "fl" if c == "ff": return "ff" if c == "ffi": return "ffi" if c == "ffl": return "ffl" if c == "ſt": return "ft" if c == "st": return "st" return "_" _xNormalizedCharsForInclusiveWriting = str.maketrans({ |
︙ | ︙ |