Grammalecte  Check-in [ae76e8614f]

Overview
Comment:[core][cli][API] wrapper for the grammar checker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | cli | core
Files: files | file ages | folders
SHA3-256: ae76e8614f2a76684379a31b0dffce85e4fbd745ec4be8bc7abbcc1648435999
User & Date: olr on 2018-02-20 12:12:28
Other Links: manifest | tags
Context
2018-02-20
13:50
[core] grammar_checker.py: add option <dOptions> check-in: 8378730de1 user: olr tags: core, trunk
12:12
[core][cli][API] wrapper for the grammar checker check-in: ae76e8614f user: olr tags: cli, core, trunk
12:10
[fr][tests] update: text2 check-in: abade51f3f user: olr tags: fr, trunk
Changes

Modified gc_core/py/__init__.py from [a7ffc6f8bf] to [aeadedff14].

            1  +
            2  +from .grammar_checker import *

Added gc_core/py/grammar_checker.py version [ccd29a288b].

            1  +# Grammalecte
            2  +# Main class: wrapper
            3  +
            4  +import importlib
            5  +import json
            6  +
            7  +from . import text
            8  +
            9  +
           10  +class GrammarChecker:
           11  +
           12  +    def __init__ (self, sLangCode, sContext="Python"):
           13  +        self.sLangCode = sLangCode
           14  +        # Grammar checker engine
           15  +        self.gce = importlib.import_module("."+sLangCode, "grammalecte")
           16  +        self.gce.load(sContext)
           17  +        # Spell checker
           18  +        self.oSpellChecker = self.gce.getSpellChecker()
           19  +        # Lexicographer
           20  +        self.oLexicographer = None
           21  +        # Text formatter
           22  +        self.oTextFormatter = None
           23  +
           24  +    def getGCEngine (self):
           25  +        return self.gce
           26  +
           27  +    def getSpellChecker (self):
           28  +        return self.oSpellChecker
           29  +
           30  +    def getTextFormatter (self):
           31  +        if self.oTextFormatter == None:
           32  +            self.tf = importlib.import_module("."+self.sLangCode+".textformatter", "grammalecte")
           33  +        self.oTextFormatter = self.tf.TextFormatter()
           34  +        return self.oTextFormatter
           35  +
           36  +    def getLexicographer (self):
           37  +        if self.oLexicographer == None:
           38  +            self.lxg = importlib.import_module("."+self.sLangCode+".lexicographe", "grammalecte")
           39  +        self.oLexicographer = self.lxg.Lexicographe(self.oSpellChecker)
           40  +        return self.oLexicographer
           41  +
           42  +    def displayGCOptions (self):
           43  +        self.gce.displayOptions()
           44  +
           45  +    def getParagraphErrors (self, sText, bContext=False, bSpellSugg=False, bDebug=False):
           46  +        "returns a tuple: (grammar errors, spelling errors)"
           47  +        aGrammErrs = self.gce.parse(sText, "FR", bDebug=bDebug, bContext=bContext)
           48  +        aSpellErrs = self.oSpellChecker.parseParagraph(sText, bSpellSugg)
           49  +        return aGrammErrs, aSpellErrs
           50  +
           51  +    def generateText (self, sText, bEmptyIfNoErrors=False, bSpellSugg=False, nWidth=100, bDebug=False):
           52  +        pass
           53  +
           54  +    def generateTextAsJSON (self, sText, bContext=False, bEmptyIfNoErrors=False, bSpellSugg=False, bReturnText=False, bDebug=False):
           55  +        pass
           56  +
           57  +    def generateParagraph (self, sText, bEmptyIfNoErrors=False, bSpellSugg=False, nWidth=100, bDebug=False):
           58  +        aGrammErrs, aSpellErrs = self.getParagraphErrors(sText, False, bSpellSugg, bDebug)
           59  +        if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
           60  +            return ""
           61  +        return text.generateParagraph(sText, aGrammErrs, aSpellErrs, nWidth)
           62  +
           63  +    def generateParagraphAsJSON (self, iIndex, sText, bContext=False, bEmptyIfNoErrors=False, bSpellSugg=False, bReturnText=False, lLineSet=None, bDebug=False):
           64  +        aGrammErrs, aSpellErrs = self.getParagraphErrors(sText, bContext, bSpellSugg, bDebug)
           65  +        aGrammErrs = list(aGrammErrs)
           66  +        if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
           67  +            return ""
           68  +        if lLineSet:
           69  +            aGrammErrs, aSpellErrs = text.convertToXY(aGrammErrs, aSpellErrs, lLineSet)
           70  +            return json.dumps({ "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
           71  +        if bReturnText:
           72  +            return json.dumps({ "iParagraph": iIndex, "sText": sText, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
           73  +        return json.dumps({ "iParagraph": iIndex, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)

Modified grammalecte-cli.py from [d66b04b565] to [150bfbed66].

     1      1   #!/usr/bin/env python3
     2      2   
     3      3   import sys
     4      4   import os.path
     5      5   import argparse
     6      6   import json
     7      7   
     8         -import grammalecte.fr as gce
     9         -import grammalecte.fr.lexicographe as lxg
    10         -import grammalecte.fr.textformatter as tf
            8  +import grammalecte
    11      9   import grammalecte.text as txt
    12         -import grammalecte.graphspell.tokenizer as tkz
    13     10   from grammalecte.graphspell.echo import echo
    14     11   
    15     12   
    16     13   _EXAMPLE = "Quoi ? Racontes ! Racontes-moi ! Bon sangg, parles ! Oui. Il y a des menteur partout. " \
    17     14              "Je suit sidéré par la brutales arrogance de cette homme-là. Quelle salopard ! Un escrocs de la pire espece. " \
    18     15              "Quant sera t’il châtiés pour ses mensonge ?             Merde ! J’en aie marre."
    19     16   
................................................................................
    40     37       if sys.platform == "win32":
    41     38           # Apparently, the console transforms «’» in «'».
    42     39           # So we reverse it to avoid many useless warnings.
    43     40           sText = sText.replace("'", "’")
    44     41       return sText
    45     42   
    46     43   
    47         -def _getErrors (sText, oTokenizer, oSpellChecker, bContext=False, bSpellSugg=False, bDebug=False):
    48         -    "returns a tuple: (grammar errors, spelling errors)"
    49         -    aGrammErrs = gce.parse(sText, "FR", bDebug=bDebug, bContext=bContext)
    50         -    aSpellErrs = []
    51         -    for dToken in oTokenizer.genTokens(sText):
    52         -        if dToken['sType'] == "WORD" and not oSpellChecker.isValidToken(dToken['sValue']):
    53         -            if bSpellSugg:
    54         -                dToken['aSuggestions'] = []
    55         -                for lSugg in oSpellChecker.suggest(dToken['sValue']):
    56         -                    dToken['aSuggestions'].extend(lSugg)
    57         -            aSpellErrs.append(dToken)
    58         -    return aGrammErrs, aSpellErrs
    59         -
    60         -
    61         -def generateText (sText, oTokenizer, oSpellChecker, bDebug=False, bEmptyIfNoErrors=False, bSpellSugg=False, nWidth=100):
    62         -    aGrammErrs, aSpellErrs = _getErrors(sText, oTokenizer, oSpellChecker, False, bSpellSugg, bDebug)
    63         -    if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
    64         -        return ""
    65         -    return txt.generateParagraph(sText, aGrammErrs, aSpellErrs, nWidth)
    66         -
    67         -
    68         -def generateJSON (iIndex, sText, oTokenizer, oSpellChecker, bContext=False, bDebug=False, bEmptyIfNoErrors=False, bSpellSugg=False, lLineSet=None, bReturnText=False):
    69         -    aGrammErrs, aSpellErrs = _getErrors(sText, oTokenizer, oSpellChecker, bContext, bSpellSugg, bDebug)
    70         -    aGrammErrs = list(aGrammErrs)
    71         -    if bEmptyIfNoErrors and not aGrammErrs and not aSpellErrs:
    72         -        return ""
    73         -    if lLineSet:
    74         -        aGrammErrs, aSpellErrs = txt.convertToXY(aGrammErrs, aSpellErrs, lLineSet)
    75         -        return json.dumps({ "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
    76         -    if bReturnText:
    77         -        return json.dumps({ "iParagraph": iIndex, "sText": sText, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
    78         -    return json.dumps({ "iParagraph": iIndex, "lGrammarErrors": aGrammErrs, "lSpellingErrors": aSpellErrs }, ensure_ascii=False)
    79         -
    80         -
    81         -def readfile (spf):
           44  +def readFile (spf):
    82     45       "generator: returns file line by line"
    83     46       if os.path.isfile(spf):
    84     47           with open(spf, "r", encoding="utf-8") as hSrc:
    85     48               for sLine in hSrc:
    86     49                   yield sLine
    87     50       else:
    88         -        print("# Error: file not found.")
           51  +        print("# Error: file <" + spf + ">not found.")
    89     52   
    90     53   
    91         -def readfileAndConcatLines (spf):
    92         -    "generator: returns text by list of lines not separated by an empty line"
    93         -    lLine = []
    94         -    for i, sLine in enumerate(readfile(spf), 1):
    95         -        if sLine.strip():
    96         -            lLine.append((i, sLine))
    97         -        elif lLine:
    98         -            yield lLine
    99         -            lLine = []
   100         -    if lLine:
   101         -        yield lLine
           54  +def generateParagraphFromFile (spf, bConcatLines=False):
           55  +    "generator: returns text by tuple of (iParagraph, sParagraph, lLineSet)"
           56  +    if not bConcatLines:
           57  +        for iParagraph, sLine in enumerate(readFile(spf), 1):
           58  +            yield iParagraph, sLine, None
           59  +    else:
           60  +        lLine = []
           61  +        iParagraph = 1
           62  +        for iLine, sLine in enumerate(readFile(spf), 1):
           63  +            if sLine.strip():
           64  +                lLine.append((iLine, sLine))
           65  +            elif lLine:
           66  +                sText, lLineSet = txt.createParagraphWithLines(lLine)
           67  +                yield iParagraph, sText, lLineSet
           68  +                lLine = []
           69  +            iParagraph += 1
           70  +        if lLine:
           71  +            sText, lLineSet = txt.createParagraphWithLines(lLine)
           72  +            yield iParagraph, sText, lLineSet
   102     73   
   103     74   
   104     75   def output (sText, hDst=None):
   105     76       if not hDst:
   106     77           echo(sText, end="")
   107     78       else:
   108     79           hDst.write(sText)
................................................................................
   111     82   def main ():
   112     83       xParser = argparse.ArgumentParser()
   113     84       xParser.add_argument("-f", "--file", help="parse file (UTF-8 required!) [on Windows, -f is similar to -ff]", type=str)
   114     85       xParser.add_argument("-ff", "--file_to_file", help="parse file (UTF-8 required!) and create a result file (*.res.txt)", type=str)
   115     86       xParser.add_argument("-owe", "--only_when_errors", help="display results only when there are errors", action="store_true")
   116     87       xParser.add_argument("-j", "--json", help="generate list of errors in JSON (only with option --file or --file_to_file)", action="store_true")
   117     88       xParser.add_argument("-cl", "--concat_lines", help="concatenate lines not separated by an empty paragraph (only with option --file or --file_to_file)", action="store_true")
   118         -    xParser.add_argument("-tf", "--textformatter", help="auto-format text according to typographical rules (unavailable with option --concat_lines)", action="store_true")
           89  +    xParser.add_argument("-tf", "--textformatter", help="auto-format text according to typographical rules (not with option --concat_lines)", action="store_true")
   119     90       xParser.add_argument("-tfo", "--textformatteronly", help="auto-format text and disable grammar checking (only with option --file or --file_to_file)", action="store_true")
   120     91       xParser.add_argument("-ctx", "--context", help="return errors with context (only with option --json)", action="store_true")
   121     92       xParser.add_argument("-wss", "--with_spell_sugg", help="add suggestions for spelling errors (only with option --file or --file_to_file)", action="store_true")
   122     93       xParser.add_argument("-w", "--width", help="width in characters (40 < width < 200; default: 100)", type=int, choices=range(40,201,10), default=100)
   123     94       xParser.add_argument("-lo", "--list_options", help="list options", action="store_true")
   124     95       xParser.add_argument("-lr", "--list_rules", nargs="?", help="list rules [regex pattern as filter]", const="*")
   125     96       xParser.add_argument("-sug", "--suggest", help="get suggestions list for given word", type=str)
   126     97       xParser.add_argument("-on", "--opt_on", nargs="+", help="activate options")
   127     98       xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options")
   128     99       xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules")
   129    100       xParser.add_argument("-d", "--debug", help="debugging mode (only in interactive mode)", action="store_true")
   130    101       xArgs = xParser.parse_args()
   131    102   
   132         -    gce.load()
          103  +    oGrammarChecker = grammalecte.GrammarChecker("fr")
          104  +    oSpellChecker = oGrammarChecker.getSpellChecker()
          105  +    oLexicographer = oGrammarChecker.getLexicographer()
          106  +    oTextFormatter = oGrammarChecker.getTextFormatter()
          107  +
   133    108       if not xArgs.json:
   134         -        echo("Grammalecte v{}".format(gce.version))
   135         -    oSpellChecker = gce.getSpellChecker()
   136         -    oTokenizer = tkz.Tokenizer("fr")
   137         -    oLexGraphe = lxg.Lexicographe(oSpellChecker)
   138         -    if xArgs.textformatter or xArgs.textformatteronly:
   139         -        oTF = tf.TextFormatter()
          109  +        echo("Grammalecte v{}".format(oGrammarChecker.gce.version))
   140    110   
          111  +    # list options or rules
   141    112       if xArgs.list_options or xArgs.list_rules:
   142    113           if xArgs.list_options:
   143         -            gce.displayOptions("fr")
          114  +            oGrammarChecker.gce.displayOptions("fr")
   144    115           if xArgs.list_rules:
   145         -            gce.displayRules(None  if xArgs.list_rules == "*"  else xArgs.list_rules)
          116  +            oGrammarChecker.gce.displayRules(None  if xArgs.list_rules == "*"  else xArgs.list_rules)
   146    117           exit()
   147    118   
          119  +    # spell suggestions
   148    120       if xArgs.suggest:
   149    121           for lSugg in oSpellChecker.suggest(xArgs.suggest):
   150    122               if xArgs.json:
   151    123                   sText = json.dumps({ "aSuggestions": lSugg }, ensure_ascii=False)
   152    124               else:
   153    125                   sText = "Suggestions : " + " | ".join(lSugg)
   154    126               echo(sText)
   155    127           exit()
   156    128   
          129  +    # disable options
   157    130       if not xArgs.json:
   158    131           xArgs.context = False
          132  +    if xArgs.concat_lines:
          133  +        xArgs.textformatter = False
   159    134   
   160         -    gce.setOptions({"html": True, "latex": True})
          135  +    # grammar options
          136  +    oGrammarChecker.gce.setOptions({"html": True, "latex": True})
   161    137       if xArgs.opt_on:
   162         -        gce.setOptions({ opt:True  for opt in xArgs.opt_on  if opt in gce.getOptions() })
          138  +        oGrammarChecker.gce.setOptions({ opt:True  for opt in xArgs.opt_on  if opt in oGrammarChecker.gce.getOptions() })
   163    139       if xArgs.opt_off:
   164         -        gce.setOptions({ opt:False  for opt in xArgs.opt_off  if opt in gce.getOptions() })
          140  +        oGrammarChecker.gce.setOptions({ opt:False  for opt in xArgs.opt_off  if opt in oGrammarChecker.gce.getOptions() })
   165    141   
          142  +    # disable grammar rules
   166    143       if xArgs.rule_off:
   167    144           for sRule in xArgs.rule_off:
   168         -            gce.ignoreRule(sRule)
          145  +            oGrammarChecker.gce.ignoreRule(sRule)
   169    146   
   170    147       sFile = xArgs.file or xArgs.file_to_file
   171    148       if sFile:
   172    149           # file processing
   173    150           hDst = open(sFile[:sFile.rfind(".")]+".res.txt", "w", encoding="utf-8", newline="\n")  if xArgs.file_to_file or sys.platform == "win32"  else None
   174    151           bComma = False
   175    152           if xArgs.json:
   176         -            output('{ "grammalecte": "'+gce.version+'", "lang": "'+gce.lang+'", "data" : [\n', hDst)
   177         -        if not xArgs.concat_lines:
   178         -            # pas de concaténation des lignes
   179         -            for i, sText in enumerate(readfile(sFile), 1):
   180         -                if xArgs.textformatter or xArgs.textformatteronly:
   181         -                    sText = oTF.formatText(sText)
   182         -                if xArgs.textformatteronly:
   183         -                    output(sText, hDst)
   184         -                else:
   185         -                    if xArgs.json:
   186         -                        sText = generateJSON(i, sText, oTokenizer, oSpellChecker, bContext=xArgs.context, bDebug=False, bEmptyIfNoErrors=xArgs.only_when_errors, bSpellSugg=xArgs.with_spell_sugg, bReturnText=xArgs.textformatter)
   187         -                    else:
   188         -                        sText = generateText(sText, oTokenizer, oSpellChecker, bDebug=False, bEmptyIfNoErrors=xArgs.only_when_errors, bSpellSugg=xArgs.with_spell_sugg, nWidth=xArgs.width)
   189         -                    if sText:
   190         -                        if xArgs.json and bComma:
   191         -                            output(",\n", hDst)
   192         -                        output(sText, hDst)
   193         -                        bComma = True
   194         -                if hDst:
   195         -                    echo("§ %d\r" % i, end="", flush=True)
   196         -        else:
   197         -            # concaténation des lignes non séparées par une ligne vide
   198         -            for i, lLine in enumerate(readfileAndConcatLines(sFile), 1):
   199         -                sText, lLineSet = txt.createParagraphWithLines(lLine)
   200         -                if xArgs.json:
   201         -                    sText = generateJSON(i, sText, oTokenizer, oSpellChecker, bContext=xArgs.context, bDebug=False, bEmptyIfNoErrors=xArgs.only_when_errors, bSpellSugg=xArgs.with_spell_sugg, lLineSet=lLineSet)
   202         -                else:
   203         -                    sText = generateText(sText, oTokenizer, oSpellChecker, bDebug=False, bEmptyIfNoErrors=xArgs.only_when_errors, bSpellSugg=xArgs.with_spell_sugg, nWidth=xArgs.width)
   204         -                if sText:
   205         -                    if xArgs.json and bComma:
   206         -                        output(",\n", hDst)
   207         -                    output(sText, hDst)
   208         -                    bComma = True
   209         -                if hDst:
   210         -                    echo("§ %d\r" % i, end="", flush=True)
          153  +            output('{ "grammalecte": "'+oGrammarChecker.gce.version+'", "lang": "'+oGrammarChecker.gce.lang+'", "data" : [\n', hDst)
          154  +        for i, sText, lLineSet in generateParagraphFromFile(sFile, xArgs.concat_lines):
          155  +            if xArgs.textformatter or xArgs.textformatteronly:
          156  +                sText = oTextFormatter.formatText(sText)
          157  +            if xArgs.textformatteronly:
          158  +                output(sText, hDst)
          159  +                continue
          160  +            if xArgs.json:
          161  +                sText = oGrammarChecker.generateParagraphAsJSON(i, sText, bContext=xArgs.context, bEmptyIfNoErrors=xArgs.only_when_errors, \
          162  +                                                                bSpellSugg=xArgs.with_spell_sugg, bReturnText=xArgs.textformatter, lLineSet=lLineSet)
          163  +            else:
          164  +                sText = oGrammarChecker.generateParagraph(sText, bEmptyIfNoErrors=xArgs.only_when_errors, bSpellSugg=xArgs.with_spell_sugg, nWidth=xArgs.width)
          165  +            if sText:
          166  +                if xArgs.json and bComma:
          167  +                    output(",\n", hDst)
          168  +                output(sText, hDst)
          169  +                bComma = True
          170  +            if hDst:
          171  +                echo("§ %d\r" % i, end="", flush=True)
   211    172           if xArgs.json:
   212    173               output("\n]}\n", hDst)
   213    174       else:
   214    175           # pseudo-console
   215    176           sInputText = "\n~==========~ Enter your text [/h /q] ~==========~\n"
   216    177           sText = _getText(sInputText)
   217    178           while True:
   218    179               if sText.startswith("?"):
   219    180                   for sWord in sText[1:].strip().split():
   220    181                       if sWord:
   221    182                           echo("* " + sWord)
   222    183                           for sMorph in oSpellChecker.getMorph(sWord):
   223         -                            echo("  {:<32} {}".format(sMorph, oLexGraphe.formatTags(sMorph)))
          184  +                            echo("  {:<32} {}".format(sMorph, oLexicographer.formatTags(sMorph)))
   224    185               elif sText.startswith("!"):
   225    186                   for sWord in sText[1:].strip().split():
   226    187                       if sWord:
   227    188                           for lSugg in oSpellChecker.suggest(sWord):
   228    189                               echo(" | ".join(lSugg))
   229    190               elif sText.startswith(">"):
   230    191                   oSpellChecker.drawPath(sText[1:].strip())
   231    192               elif sText.startswith("="):
   232    193                   for sRes in oSpellChecker.select(sText[1:].strip()):
   233    194                       echo(sRes)
   234    195               elif sText.startswith("/+ "):
   235         -                gce.setOptions({ opt:True  for opt in sText[3:].strip().split()  if opt in gce.getOptions() })
          196  +                oGrammarChecker.gce.setOptions({ opt:True  for opt in sText[3:].strip().split()  if opt in oGrammarChecker.gce.getOptions() })
   236    197                   echo("done")
   237    198               elif sText.startswith("/- "):
   238         -                gce.setOptions({ opt:False  for opt in sText[3:].strip().split()  if opt in gce.getOptions() })
          199  +                oGrammarChecker.gce.setOptions({ opt:False  for opt in sText[3:].strip().split()  if opt in oGrammarChecker.gce.getOptions() })
   239    200                   echo("done")
   240    201               elif sText.startswith("/-- "):
   241    202                   for sRule in sText[3:].strip().split():
   242         -                    gce.ignoreRule(sRule)
          203  +                    oGrammarChecker.gce.ignoreRule(sRule)
   243    204                   echo("done")
   244    205               elif sText.startswith("/++ "):
   245    206                   for sRule in sText[3:].strip().split():
   246         -                    gce.reactivateRule(sRule)
          207  +                    oGrammarChecker.gce.reactivateRule(sRule)
   247    208                   echo("done")
   248    209               elif sText == "/debug" or sText == "/d":
   249    210                   xArgs.debug = not(xArgs.debug)
   250    211                   echo("debug mode on"  if xArgs.debug  else "debug mode off")
   251    212               elif sText == "/textformatter" or sText == "/tf":
   252    213                   xArgs.textformatter = not(xArgs.textformatter)
   253    214                   echo("textformatter on"  if xArgs.debug  else "textformatter off")
   254    215               elif sText == "/help" or sText == "/h":
   255    216                   echo(_HELP)
   256    217               elif sText == "/lopt" or sText == "/lo":
   257         -                gce.displayOptions("fr")
          218  +                oGrammarChecker.gce.displayOptions("fr")
   258    219               elif sText.startswith("/lr"):
   259    220                   sText = sText.strip()
   260    221                   sFilter = sText[sText.find(" "):].strip()  if sText != "/lr" and sText != "/rules"  else None
   261         -                gce.displayRules(sFilter)
          222  +                oGrammarChecker.gce.displayRules(sFilter)
   262    223               elif sText == "/quit" or sText == "/q":
   263    224                   break
   264    225               elif sText.startswith("/rl"):
   265    226                   # reload (todo)
   266    227                   pass
   267    228               else:
   268    229                   for sParagraph in txt.getParagraph(sText):
   269    230                       if xArgs.textformatter:
   270         -                        sText = oTF.formatText(sText)
   271         -                    sRes = generateText(sText, oTokenizer, oSpellChecker, bDebug=xArgs.debug, bEmptyIfNoErrors=xArgs.only_when_errors, nWidth=xArgs.width)
          231  +                        sText = oTextFormatter.formatText(sText)
          232  +                    sRes = oGrammarChecker.generateParagraph(sText, bEmptyIfNoErrors=xArgs.only_when_errors, nWidth=xArgs.width, bDebug=xArgs.debug)
   272    233                       if sRes:
   273    234                           echo("\n" + sRes)
   274    235                       else:
   275    236                           echo("\nNo error found.")
   276    237               sText = _getText(sInputText)
   277    238   
   278    239   
   279    240   if __name__ == '__main__':
   280    241       main()