Grammalecte  Diff

Differences From Artifact [fab156e863]:

To Artifact [49c48029bd]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
21













-
+







"""
Lexicographer for the French language
"""

# Note:
# This mode must contains at least:
#     <dSugg> : a dictionary for default suggestions.
#     <bLexicographer> : a boolean False
#       if the boolean is True, 4 functions are required:
#           split(sWord) -> returns a list of string (that will be analyzed)
#           analyze(sWord) -> returns a string with the meaning of word
#           readableMorph(sMorph) -> returns a string with the meaning of tags
#           setLabelsOnToken(dToken) -> adds readable information on token
#           filterSugg(aWord) -> returns a filtered list of suggestions
#           isValidSugg(sWord, oSpellChecker) -> returns a filtered list of suggestions


import re

#### Suggestions

dSugg = {
506
507
508
509
510
511
512
513
514
515
516














506
507
508
509
510
511
512




513
514
515
516
517
518
519
520
521
522
523
524
525
526







-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
            dToken["aLabels"] = ["token de nature inconnue"]
    except:
        return


# Other functions

def filterSugg (aSuggs):
    "exclude suggestions"
    return [ sSugg  for sSugg in aSuggs  if not sSugg.endswith(("è", "È")) ]
    #return filter(lambda sSugg: not sSugg.endswith(("è", "È")), aSuggs) # return an object filter
def isValidSugg (sSugg, oSpellChecker):
    "return True if <sSugg> is valid"
    if sSugg.endswith(("è", "È")):
        return False
    if "’" in sSugg:
        if sSugg.startswith(("d’", "D’")) and not oSpellChecker.morph(sSugg[2:], ":[YNAW]"):
            return False
        if sSugg.startswith(("n’", "m’", "t’", "s’", "N’", "M’", "T’", "S’")) and not oSpellChecker.morph(sSugg[2:], ":V"):
            return False
        if sSugg.startswith(("j’", "J’")) and not oSpellChecker.morph(sSugg[2:], ":(?:Y|[123][sp])"):
            return False
        if sSugg.startswith(("c’", "C’")) and not oSpellChecker.morph(sSugg[2:], ":3[sp]"):
            return False
    return True