Index: doc/syntax.txt ================================================================== --- doc/syntax.txt +++ doc/syntax.txt @@ -1,8 +1,8 @@ WRITING RULES FOR GRAMMALECTE -Note: This documentation is a draft. Information may be obsolete. +Note: This documentation is a draft. Information may be obsolete or incomplete. # Principles # Grammalecte is a bi-passes grammar checker engine. On the first pass, the engine checks the text paragraph by paragraph. On the second pass, the engine @@ -10,11 +10,11 @@ The command to switch to the second pass is `[++]`. In each pass, you can write as many rules as you need. -There is two kinds of rules: +There are two kinds of rules: * regex rules (triggered by a regular expression) * token rules (triggered by a succession of tokens) A regex rule is defined by: @@ -35,26 +35,27 @@ Each graph is defined within the second pass with the command: @@@@GRAPH: graph_name -A graph ends when another graph is defined or when is defined the command: +A graph ends when another graph is defined or when is found the command: @@@@END_GRAPH There is no limit to the number of actions and the type of actions a rule can launch. Each action has its own condition to be triggered. -There are three kind of actions: +There are several kinds of actions: * Error warning, with a message, and optionally suggestions, and optionally an URL * Text transformation, modifying internally the checked text * Disambiguation action, setting tags on a position +* Tagging -The rules file for your language must be named “rules.grx”. -The settings file must be named “config.ini”. +The rules file for your language must be named `rules.grx`. +The settings file must be named `config.ini`. All these files are simple utf-8 text file. UTF-8 is mandatory. @@ -187,11 +188,11 @@ Example: Recognize double or more spaces and suggests a single space: ____ " +" <<- ->> " " # Extra space(s). -ASCII " characters protect spaces in the pattern and in the replacement text. +Characters `"` protect spaces in the pattern and in the replacement text. ## Pattern groups and back references ## It is usually useful to retrieve parts of the matched pattern. We simply use @@ -213,15 +214,15 @@ ## Pattern matching ## Repeating pattern matching of a single rule continues after the previous matching, so instead of general multiword patterns, like -(\w+) (\w+) <<- some_check(\1, \2) ->> \1, \2 # foo + (\w+) (\w+) <<- some_check(\1, \2) ->> \1, \2 # foo use -(\w+) <<- some_check(\1, word(1)) ->> \1, # foo + (\w+) <<- some_check(\1, word(1)) ->> \1, # foo ## Name definitions ## Grammalecte supports name definitions to simplify the description of the @@ -342,15 +343,15 @@ The text preprocessor is useful to simplify texts and write simplier checking rules. For example, sentences with the same grammar mistake: - These “cats” are blacks. - These cats are “blacks”. - These cats are absolutely blacks. - These stupid “cats” are all blacks. - These unknown cats are as per usual blacks. + These “cats” are black. + These cats are “black”. + These cats are absolutely black. + These stupid “cats” are all black. + These unknown cats are as per usual black. Instead of writting complex rules or several rules to find mistakes for all possible cases, you can use the text preprocessor to simplify the text. To remove the chars “”, write: @@ -368,15 +369,15 @@ these (\w+) (\w+) <<- morph(\1, "adjective") and morph(\2, "noun") -1>> * (am|are|is|were|was) (all) <<- -2>> * With these rules, you get the following sentences: - These cats are blacks. - These cats are blacks . - These cats are blacks. - These cats are blacks. - These cats are blacks. + These cats are black. + These cats are black . + These cats are black. + These cats are black. + These cats are black. These grammar mistakes can be detected with one simple rule: these +(\w+) +are +(\w+s) <<- morph(\1, "noun") and morph(\2, "plural") @@ -395,11 +396,11 @@ (Mrs?)[.] <<- ->> \1 # Disambiguation # -When Grammalecte analyses a word with morph or morphex, before requesting the +When Grammalecte analyses a word with morph, before requesting the POS tags to the dictionary, it checks if there is a stored marker for the position where the word is. If there is a marker, Grammalecte uses the stored data and don’t make request to the dictionary. The disambiguation commands store POS tags at the position of a word. @@ -413,33 +414,28 @@ `exclude(n, pattern)` > stores at position n the POS tags of the word, except those matching the pattern. -`define(n, definition)` +`define(n, [definitions])` -> stores at position n the POS tags in definition. +> stores at position n the POS tags in definitions (a list of strings). Examples: =>> select(\1, "po:noun is:pl") =>> exclude(\1, "po:verb") - =>> define(\1, "po:adv") - =>> exclude(\1, "po:verb") and define(\2, "po:adv") and select(\3, "po:adv") + =>> define(\1, ["po:adv"]) + =>> exclude(\1, "po:verb") and define(\2, ["po:adv"]) and select(\3, "po:adv") Note: select, exclude and define ALWAYS return True. If select and exclude generate an empty list, no marker is set. -With define, you can set a list of POS tags. Example: - - define(\1, "po:nom is:plur|po:adj is:sing|po:adv") - -This will store a list of tags at the position of the first group: - - ["po:nom is:plur", "po:adj is:sing", "po:adv"] - +With define, you must set a list of POS tags. Example: + + define(\1, ["po:nom is:plur", "po:adj is:sing", "po:adv"]) # Conditions # Conditions are Python expressions, they must return a value, which will be Index: gc_lang/fr/rules.grx ================================================================== --- gc_lang/fr/rules.grx +++ gc_lang/fr/rules.grx @@ -2017,11 +2017,11 @@ __inte_verbes_composés_interrogatifs_impératifs__ ~\w-[nN]ous$ <<- /inte/ morphVC(\1, ":V", ":(?:1p|E:2[sp])") ->> =suggVerb(\1, ":1p", None, True) # Forme interrogative ou impérative incorrecte. - <<- /inte/ __else__ and morphVC(\1, ":", ":V|>chez/") ->> =suggSimil(\1, ":1p", False, True) # Forme interrogative ou impérative incorrecte. + <<- /inte/ __else__ and morphVC(\1, ":", ":V|>(?:chez|malgré)/") ->> =suggSimil(\1, ":1p", False, True) # Forme interrogative ou impérative incorrecte. <<- />> -nous|VCint ~\w-[vV]ous$ <<- /inte/ morphVC(\1, ":V", ":2p") ->> =suggVerb(\1, ":2p", None, True) # Forme interrogative ou impérative. Désaccord avec “vous”. Le verbe n’est pas à la 2ᵉ personne du pluriel. <<- /inte/ __else__ and morphVC(\1, ":", ":V|>chez/") ->> =suggSimil(\1, ":2p", False, True) # Forme interrogative ou impérative. Désaccord avec “vous”. Le verbe n’est pas à la 2ᵉ personne du pluriel. @@ -2032,10 +2032,11 @@ TEST: {{Attaquait-vous}} ->> Attaquiez-vous TEST: Elle a de nombreux rendez-vous ce matin. TEST: êtes-vous là ? TEST: C’est notre chez-nous. TEST: Dans votre chez-vous, faites comme bon vous semble. +TEST: Libérée en grande majorité durant l’automne 1945, une partie des « Malgré-nous » passe pourtant plusieurs années supplémentaires en captivité. __inte_rendez_vous__ ne [le|la|les] [lui|leur] rendez-vous ne me [le|la|les] rendez-vous @@ -2153,10 +2154,14 @@ <<- morph(<1, ":D.*:[mp]") ~>> ␣ <<- __also__ =>> define(\1, [":N:m:i"]) __immunités__ + il y a + il n’ y a + <<- %-1>> + à l’ arrache <<- %3>> à ce point en tout point @@ -15263,11 +15268,11 @@ [de|d’] ?[ne|n’]¿ [lui|leur] en @:V¬:Y <<- /infi/ --1>> =suggVerbInfi(\-1) # Après “de”, le verbe devrait être à l’infinitif. [de|d’] @:V1.*:Q¬:N <<- /infi/ not \2[0:1].isupper() and not morph(<1, ">(?:en|passer)/") - and not before("(?i)\\b(?:quelqu(?:e chose|’une?)|(?:l(es?|a)|nous|vous|me|te|se) trait|personne|point +$|rien(?: +[a-zéèêâîûù]+|) +$)") + and not before("(?i)\\b(?:quelqu(?:e chose|’une?)|(?:l(es?|a)|nous|vous|me|te|se) trait|personne|points? +$|rien(?: +[a-zéèêâîûù]+|) +$)") -2>> =suggVerbInfi(\2) # Le verbe devrait être à l’infinitif. TEST: d’en {{parlé}} sans cesse TEST: cela suffit de les {{aimait}} TEST: de ne leur en {{avancé}} que le nécessaire. @@ -15288,10 +15293,11 @@ TEST: de n’importe quelle manière TEST: un libéralisme trop « individualiste » s’est transformé en de supposées demandes de droits spécifiques TEST: soit 40 % de plus comparé au quinquennat précédent TEST: On passe de sophistiqué à classique. TEST: Les « événements » d’il y a cinquante ans n’ont sans doute « rien à voir » avec le mouvement des « gilets jaunes » +TEST: Quelques points de gagnés avec cette astuce, ne faisons pas la fine bouche. __infi_y_verbe!3__ y ~ée?s?$ <<- /infi/ morph(\2, ":V", ":[123][sp]") -2>> _ # Le verbe ne devrait pas être un participe passé.