Overview
Comment: | [core][cli][graphsell][lo][py] move lexicographer from gc engine to graphspell |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | cli | core | lo | graphspell | gcerw |
Files: | files | file ages | folders |
SHA3-256: |
ba3c939f60235746d8f4a0ab60c71649 |
User & Date: | olr on 2020-04-05 08:39:44 |
Original Comment: | [core][cli][graphsell][lo] move lexicographer from gc engine to graphspell |
Other Links: | branch diff | manifest | tags |
Context
2020-04-06
| ||
13:15 | merge trunk check-in: 1c5bdb25b6 user: olr tags: gcerw | |
2020-04-05
| ||
08:39 | [core][cli][graphsell][lo][py] move lexicographer from gc engine to graphspell check-in: ba3c939f60 user: olr tags: cli, core, lo, graphspell, gcerw | |
2020-04-04
| ||
15:54 | [core][fr][py] gc_engine.py as primary module check-in: 759321730c user: olr tags: fr, core, gcerw | |
Changes
Deleted gc_lang/fr/modules/lexicographe.py version [36a85305ff].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified gc_lang/fr/oxt/ContextMenu/ContextMenu.py from [f06cffc0e3] to [172f2404b4].
1 2 3 4 5 6 7 8 9 10 11 12 | # Grammalecte - Lexicographe # by Olivier R. License: MPL 2 import uno import unohelper import traceback from com.sun.star.task import XJob from com.sun.star.ui import XContextMenuInterceptor #from com.sun.star.ui.ContextMenuInterceptorAction import IGNORED #from com.sun.star.ui.ContextMenuInterceptorAction import EXECUTE_MODIFIED | < < | | | | > | < | | | | | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # Grammalecte - Lexicographe # by Olivier R. License: MPL 2 import uno import unohelper import traceback from com.sun.star.task import XJob from com.sun.star.ui import XContextMenuInterceptor #from com.sun.star.ui.ContextMenuInterceptorAction import IGNORED #from com.sun.star.ui.ContextMenuInterceptorAction import EXECUTE_MODIFIED from grammalecte.graphspell.spellchecker import SpellChecker from grammalecte.graphspell.echo import echo import helpers xDesktop = None oSpellChecker = None class MyContextMenuInterceptor (XContextMenuInterceptor, unohelper.Base): def __init__ (self, ctx): self.ctx = ctx def notifyContextMenuExecute (self, xEvent): sWord = self._getWord() try: lWordAndMorph = oSpellChecker.analyze(sWord) if not lWordAndMorph: return uno.Enum("com.sun.star.ui.ContextMenuInterceptorAction", "IGNORED") # don’t work on AOO, have to import the value #return IGNORED xContextMenu = xEvent.ActionTriggerContainer if xContextMenu: # entries index i = xContextMenu.Count nUnoConstantLine = uno.getConstantByName("com.sun.star.ui.ActionTriggerSeparatorType.LINE") # word analysis i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine) for sWord, lMorph in lWordAndMorph: if len(lMorph) == 1: sMorph, sReadableMorph = lMorph[0] i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord + " : " + sReadableMorph, CommandURL="service:net.grammalecte.AppLauncher?None") elif len(lMorph) >= 1: # submenu xSubMenuContainer = xContextMenu.createInstance("com.sun.star.ui.ActionTriggerContainer") for j, (sMorph, sReadableMorph) in enumerate(lMorph): self._addItemToContextMenu(xSubMenuContainer, j, "ActionTrigger", Text=sReadableMorph, CommandURL="service:net.grammalecte.AppLauncher?None") # create root menu entry i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord, SubContainer=xSubMenuContainer) else: i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text=sWord + " : [erreur] aucun résultat trouvé.") # Links to Conjugueur aVerb = { sMorph[1:sMorph.find("/")] for sMorph in oSpellChecker.getMorph(sWord) if ":V" in sMorph } if aVerb: i = self._addItemToContextMenu(xContextMenu, i, "ActionTriggerSeparator", SeparatorType=nUnoConstantLine) for sVerb in aVerb: i = self._addItemToContextMenu(xContextMenu, i, "ActionTrigger", Text="Conjuguer “{}”…".format(sVerb), \ CommandURL="service:net.grammalecte.AppLauncher?CJ/"+sVerb) # Search xDoc = xDesktop.getCurrentComponent() xViewCursor = xDoc.CurrentController.ViewCursor if not xViewCursor.isCollapsed(): sSelec = xViewCursor.getString() if sSelec.count(" ") <= 2: |
︙ | ︙ | |||
114 115 116 117 118 119 120 | class JobExecutor (XJob, unohelper.Base): def __init__ (self, ctx): self.ctx = ctx global xDesktop global oSpellChecker | < < < | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | class JobExecutor (XJob, unohelper.Base): def __init__ (self, ctx): self.ctx = ctx global xDesktop global oSpellChecker try: if not xDesktop: xDesktop = self.ctx.getServiceManager().createInstanceWithContext('com.sun.star.frame.Desktop', self.ctx) if not oSpellChecker: xCurCtx = uno.getComponentContext() oGC = self.ctx.ServiceManager.createInstanceWithContext("org.openoffice.comp.pyuno.Lightproof.grammalecte", self.ctx) if hasattr(oGC, "getSpellChecker"): # https://bugs.documentfoundation.org/show_bug.cgi?id=97790 oSpellChecker = oGC.getSpellChecker() else: oSpellChecker = SpellChecker("${lang}", "fr-allvars.bdic") except: traceback.print_exc() def execute (self, args): if not args: return try: |
︙ | ︙ |
Modified grammalecte-cli.py from [edd4f4bf7e] to [1c366da1c4].
︙ | ︙ | |||
150 151 152 153 154 155 156 | xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options") xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules") xParser.add_argument("-d", "--debug", help="debugging mode (only in interactive mode)", action="store_true") xArgs = xParser.parse_args() grammalecte.load() oSpellChecker = grammalecte.getSpellChecker() | < | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | xParser.add_argument("-off", "--opt_off", nargs="+", help="deactivate options") xParser.add_argument("-roff", "--rule_off", nargs="+", help="deactivate rules") xParser.add_argument("-d", "--debug", help="debugging mode (only in interactive mode)", action="store_true") xArgs = xParser.parse_args() grammalecte.load() oSpellChecker = grammalecte.getSpellChecker() if xArgs.personal_dict: oJSON = loadDictionary(xArgs.personal_dict) if oJSON: oSpellChecker.setPersonalDictionary(oJSON) if not xArgs.json: echo("Python v" + sys.version) |
︙ | ︙ | |||
267 268 269 270 271 272 273 | sInputText = "\n~==========~ Enter your text [/h /q] ~==========~\n" sText = _getText(sInputText) while True: if sText.startswith("?"): for sWord in sText[1:].strip().split(): if sWord: echo("* " + sWord) | | > > | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | sInputText = "\n~==========~ Enter your text [/h /q] ~==========~\n" sText = _getText(sInputText) while True: if sText.startswith("?"): for sWord in sText[1:].strip().split(): if sWord: echo("* " + sWord) for sElem, aRes in oSpellChecker.analyze(sWord): echo(" - " + sElem) for sMorph, sMeaning in aRes: echo(" {:<40} {}".format(sMorph, sMeaning)) elif sText.startswith("!"): for sWord in sText[1:].strip().split(): if sWord: for lSugg in oSpellChecker.suggest(sWord): echo(" | ".join(lSugg)) elif sText.startswith(">"): oSpellChecker.drawPath(sText[1:].strip()) |
︙ | ︙ |
Modified graphspell/fr.py from [ec94a3663c] to [f127f4b49a].
1 | """ | | > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | """ 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, 3 functions are required: # split(sWord) -> returns a list of string (that will be analyzed) # analyze(sWord) -> returns a string with the meaning of word # formatTags(sTags) -> returns a string with the meaning of tags import re #### Suggestions dSugg = { "bcp": "beaucoup", "ca": "ça", "cad": "c’est-à-dire", "cb": "combien|CB", "cdlt": "cordialement", "construirent": "construire|construisirent|construisent|construiront", |
︙ | ︙ | |||
80 81 82 83 84 85 86 87 88 89 90 91 92 93 | "XXIVième": "XXIVᵉ", "XXVième": "XXVᵉ", "XXVIième": "XXVIᵉ", "XXVIIième": "XXVIIᵉ", "XXVIIIième": "XXVIIIᵉ", "XXIXième": "XXIXᵉ", "XXXième": "XXXᵉ", "Ier": "Iᵉʳ", "Ière": "Iʳᵉ", "IIème": "IIᵉ", "IIIème": "IIIᵉ", "IVème": "IVᵉ", "Vème": "Vᵉ", "VIème": "VIᵉ", | > | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | "XXIVième": "XXIVᵉ", "XXVième": "XXVᵉ", "XXVIième": "XXVIᵉ", "XXVIIième": "XXVIIᵉ", "XXVIIIième": "XXVIIIᵉ", "XXIXième": "XXIXᵉ", "XXXième": "XXXᵉ", "Ier": "Iᵉʳ", "Ière": "Iʳᵉ", "IIème": "IIᵉ", "IIIème": "IIIᵉ", "IVème": "IVᵉ", "Vème": "Vᵉ", "VIème": "VIᵉ", |
︙ | ︙ | |||
112 113 114 115 116 117 118 | "XXVème": "XXVᵉ", "XXVIème": "XXVIᵉ", "XXVIIème": "XXVIIᵉ", "XXVIIIème": "XXVIIIᵉ", "XXIXème": "XXIXᵉ", "XXXème": "XXXᵉ" } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | "XXVème": "XXVᵉ", "XXVIème": "XXVIᵉ", "XXVIIème": "XXVIIᵉ", "XXVIIIème": "XXVIIIᵉ", "XXIXème": "XXIXᵉ", "XXXème": "XXXᵉ" } #### Lexicographer bLexicographer = True _dTAGS = { ':N': (" nom,", "Nom"), ':A': (" adjectif,", "Adjectif"), ':M1': (" prénom,", "Prénom"), ':M2': (" patronyme,", "Patronyme, matronyme, nom de famille…"), ':MP': (" nom propre,", "Nom propre"), ':W': (" adverbe,", "Adverbe"), ':J': (" interjection,", "Interjection"), ':B': (" nombre,", "Nombre"), ':T': (" titre,", "Titre de civilité"), ':e': (" épicène", "épicène"), ':m': (" masculin", "masculin"), ':f': (" féminin", "féminin"), ':s': (" singulier", "singulier"), ':p': (" pluriel", "pluriel"), ':i': (" invariable", "invariable"), ':V1': (" verbe (1ᵉʳ gr.),", "Verbe du 1ᵉʳ groupe"), ':V2': (" verbe (2ᵉ gr.),", "Verbe du 2ᵉ groupe"), ':V3': (" verbe (3ᵉ gr.),", "Verbe du 3ᵉ groupe"), ':V0e': (" verbe,", "Verbe auxiliaire être"), ':V0a': (" verbe,", "Verbe auxiliaire avoir"), ':Y': (" infinitif,", "infinitif"), ':P': (" participe présent,", "participe présent"), ':Q': (" participe passé,", "participe passé"), ':Ip': (" présent,", "indicatif présent"), ':Iq': (" imparfait,", "indicatif imparfait"), ':Is': (" passé simple,", "indicatif passé simple"), ':If': (" futur,", "indicatif futur"), ':K': (" conditionnel présent,", "conditionnel présent"), ':Sp': (" subjonctif présent,", "subjonctif présent"), ':Sq': (" subjonctif imparfait,", "subjonctif imparfait"), ':E': (" impératif,", "impératif"), ':1s': (" 1ʳᵉ p. sg.,", "verbe : 1ʳᵉ personne du singulier"), ':1ŝ': (" présent interr. 1ʳᵉ p. sg.,", "verbe : 1ʳᵉ personne du singulier (présent interrogatif)"), ':1ś': (" présent interr. 1ʳᵉ p. sg.,", "verbe : 1ʳᵉ personne du singulier (présent interrogatif)"), ':2s': (" 2ᵉ p. sg.,", "verbe : 2ᵉ personne du singulier"), ':3s': (" 3ᵉ p. sg.,", "verbe : 3ᵉ personne du singulier"), ':1p': (" 1ʳᵉ p. pl.,", "verbe : 1ʳᵉ personne du pluriel"), ':2p': (" 2ᵉ p. pl.,", "verbe : 2ᵉ personne du pluriel"), ':3p': (" 3ᵉ p. pl.,", "verbe : 3ᵉ personne du pluriel"), ':3p!': (" 3ᵉ p. pl.,", "verbe : 3ᵉ personne du pluriel (prononciation distinctive)"), ':G': ("", "Mot grammatical"), ':X': (" adverbe de négation,", "Adverbe de négation"), ':U': (" adverbe interrogatif,", "Adverbe interrogatif"), ':R': (" préposition,", "Préposition"), ':Rv': (" préposition verbale,", "Préposition verbale"), ':D': (" déterminant,", "Déterminant"), ':Dd': (" déterminant démonstratif,", "Déterminant démonstratif"), ':De': (" déterminant exclamatif,", "Déterminant exclamatif"), ':Dp': (" déterminant possessif,", "Déterminant possessif"), ':Di': (" déterminant indéfini,", "Déterminant indéfini"), ':Dn': (" déterminant négatif,", "Déterminant négatif"), ':Od': (" pronom démonstratif,", "Pronom démonstratif"), ':Oi': (" pronom indéfini,", "Pronom indéfini"), ':On': (" pronom indéfini négatif,", "Pronom indéfini négatif"), ':Ot': (" pronom interrogatif,", "Pronom interrogatif"), ':Or': (" pronom relatif,", "Pronom relatif"), ':Ow': (" pronom adverbial,", "Pronom adverbial"), ':Os': (" pronom personnel sujet,", "Pronom personnel sujet"), ':Oo': (" pronom personnel objet,", "Pronom personnel objet"), ':Ov': (" préverbe,", "Préverbe (pronom personnel objet, +ne)"), ':O1': (" 1ʳᵉ pers.,", "Pronom : 1ʳᵉ personne"), ':O2': (" 2ᵉ pers.,", "Pronom : 2ᵉ personne"), ':O3': (" 3ᵉ pers.,", "Pronom : 3ᵉ personne"), ':C': (" conjonction,", "Conjonction"), ':Ĉ': (" conjonction (él.),", "Conjonction (élément)"), ':Cc': (" conjonction de coordination,", "Conjonction de coordination"), ':Cs': (" conjonction de subordination,", "Conjonction de subordination"), ':Ĉs': (" conjonction de subordination (él.),", "Conjonction de subordination (élément)"), ':Ñ': (" locution nominale (él.),", "Locution nominale (élément)"), ':Â': (" locution adjectivale (él.),", "Locution adjectivale (élément)"), ':Ṽ': (" locution verbale (él.),", "Locution verbale (élément)"), ':Ŵ': (" locution adverbiale (él.),", "Locution adverbiale (élément)"), ':Ŕ': (" locution prépositive (él.),", "Locution prépositive (élément)"), ':Ĵ': (" locution interjective (él.),", "Locution interjective (élément)"), ':Zp': (" préfixe,", "Préfixe"), ':Zs': (" suffixe,", "Suffixe"), ':H': ("", "<Hors-norme, inclassable>"), ':@': ("", "<Caractère non alpha-numérique>"), ':@p': ("signe de ponctuation", "Signe de ponctuation"), ':@s': ("signe", "Signe divers"), ';S': (" : symbole (unité de mesure)", "Symbole (unité de mesure)"), '/*': ("", "Sous-dictionnaire <Commun>"), '/C': (" <classique>", "Sous-dictionnaire <Classique>"), '/M': ("", "Sous-dictionnaire <Moderne>"), '/R': (" <réforme>", "Sous-dictionnaire <Réforme 1990>"), '/A': ("", "Sous-dictionnaire <Annexe>"), '/X': ("", "Sous-dictionnaire <Contributeurs>") } _dValues = { 'd’': "(de), préposition ou déterminant épicène invariable", 'l’': "(le/la), déterminant ou pronom personnel objet, masculin/féminin singulier", 'j’': "(je), pronom personnel sujet, 1ʳᵉ pers., épicène singulier", 'm’': "(me), pronom personnel objet, 1ʳᵉ pers., épicène singulier", 't’': "(te), pronom personnel objet, 2ᵉ pers., épicène singulier", 's’': "(se), pronom personnel objet, 3ᵉ pers., épicène singulier/pluriel", 'n’': "(ne), adverbe de négation", 'c’': "(ce), pronom démonstratif, masculin singulier/pluriel", 'ç’': "(ça), pronom démonstratif, masculin singulier", 'qu’': "(que), conjonction de subordination", 'lorsqu’': "(lorsque), conjonction de subordination", 'puisqu’': "(puisque), conjonction de subordination", 'quoiqu’': "(quoique), conjonction de subordination", 'jusqu’': "(jusque), préposition", '-je': " pronom personnel sujet, 1ʳᵉ pers. sing.", '-tu': " pronom personnel sujet, 2ᵉ pers. sing.", '-il': " pronom personnel sujet, 3ᵉ pers. masc. sing.", '-on': " pronom personnel sujet, 3ᵉ pers. sing. ou plur.", '-elle': " pronom personnel sujet, 3ᵉ pers. fém. sing.", '-t-il': " “t” euphonique + pronom personnel sujet, 3ᵉ pers. masc. sing.", '-t-on': " “t” euphonique + pronom personnel sujet, 3ᵉ pers. sing. ou plur.", '-t-elle': " “t” euphonique + pronom personnel sujet, 3ᵉ pers. fém. sing.", '-nous': " pronom personnel sujet/objet, 1ʳᵉ pers. plur. ou COI (à nous), plur.", '-vous': " pronom personnel sujet/objet, 2ᵉ pers. plur. ou COI (à vous), plur.", '-ils': " pronom personnel sujet, 3ᵉ pers. masc. plur.", '-elles': " pronom personnel sujet, 3ᵉ pers. masc. plur.", "-là": " particule démonstrative", "-ci": " particule démonstrative", '-le': " COD, masc. sing.", '-la': " COD, fém. sing.", '-les': " COD, plur.", '-moi': " COI (à moi), sing.", '-toi': " COI (à toi), sing.", '-lui': " COI (à lui ou à elle), sing.", '-leur': " COI (à eux ou à elles), plur.", '-le-moi': " COD, masc. sing. + COI (à moi), sing.", '-le-toi': " COD, masc. sing. + COI (à toi), sing.", '-le-lui': " COD, masc. sing. + COI (à lui ou à elle), sing.", '-le-nous': " COD, masc. sing. + COI (à nous), plur.", '-le-vous': " COD, masc. sing. + COI (à vous), plur.", '-le-leur': " COD, masc. sing. + COI (à eux ou à elles), plur.", '-la-moi': " COD, fém. sing. + COI (à moi), sing.", '-la-toi': " COD, fém. sing. + COI (à toi), sing.", '-la-lui': " COD, fém. sing. + COI (à lui ou à elle), sing.", '-la-nous': " COD, fém. sing. + COI (à nous), plur.", '-la-vous': " COD, fém. sing. + COI (à vous), plur.", '-la-leur': " COD, fém. sing. + COI (à eux ou à elles), plur.", '-les-moi': " COD, plur. + COI (à moi), sing.", '-les-toi': " COD, plur. + COI (à toi), sing.", '-les-lui': " COD, plur. + COI (à lui ou à elle), sing.", '-les-nous': " COD, plur. + COI (à nous), plur.", '-les-vous': " COD, plur. + COI (à vous), plur.", '-les-leur': " COD, plur. + COI (à eux ou à elles), plur.", '-y': " pronom adverbial", "-m’y": " (me) pronom personnel objet + (y) pronom adverbial", "-t’y": " (te) pronom personnel objet + (y) pronom adverbial", "-s’y": " (se) pronom personnel objet + (y) pronom adverbial", '-en': " pronom adverbial", "-m’en": " (me) pronom personnel objet + (en) pronom adverbial", "-t’en": " (te) pronom personnel objet + (en) pronom adverbial", "-s’en": " (se) pronom personnel objet + (en) pronom adverbial", } _zElidedPrefix = re.compile("(?i)^((?:[dljmtsncç]|quoiqu|lorsqu|jusqu|puisqu|qu)’)(.+)") _zCompoundWord = re.compile("(?i)(\\w+)(-(?:(?:les?|la)-(?:moi|toi|lui|[nv]ous|leur)|t-(?:il|elle|on)|y|en|[mts]’(?:y|en)|les?|l[aà]|[mt]oi|leur|lui|je|tu|ils?|elles?|on|[nv]ous))$") _zTag = re.compile("[:;/][\\w*][^:;/]*") def split (sWord): "split word in 3 parts: prefix, root, suffix" sWord = sWord.replace("'", "’") sPrefix = "" sSuffix = "" # préfixe élidé m = _zElidedPrefix.match(sWord) if m: sPrefix = m.group(1) sWord = m.group(2) # mots composés m = _zCompoundWord.match(sWord) if m: sWord = m.group(1) sSuffix = m.group(2) return sPrefix, sWord, sSuffix def analyze (sWord): "return meaning of <sWord> if found else an empty string" sWord = sWord.lower() if sWord in _dValues: return _dValues[sWord] return "" def formatTags (sTags): "returns string: readable tags" sRes = "" sTags = re.sub("(?<=V[1-3])[itpqnmr_eaxz]+", "", sTags) sTags = re.sub("(?<=V0[ea])[itpqnmr_eaxz]+", "", sTags) for m in _zTag.finditer(sTags): sRes += _dTAGS.get(m.group(0), " [{}]".format(m.group(0)))[0] if sRes.startswith(" verbe") and not sRes.endswith("infinitif"): sRes += " [{}]".format(sTags[1:sTags.find("/")]) return sRes.rstrip(",") |
Modified graphspell/spellchecker.py from [114a0237c3] to [a290bf205a].
︙ | ︙ | |||
32 33 34 35 36 37 38 | self.oMainDic = self._loadDictionary(sfMainDic, True) self.oCommunityDic = self._loadDictionary(sfCommunityDic) self.oPersonalDic = self._loadDictionary(sfPersonalDic) self.bCommunityDic = bool(self.oCommunityDic) self.bPersonalDic = bool(self.oPersonalDic) self.oTokenizer = None # Default suggestions | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | self.oMainDic = self._loadDictionary(sfMainDic, True) self.oCommunityDic = self._loadDictionary(sfCommunityDic) self.oPersonalDic = self._loadDictionary(sfPersonalDic) self.bCommunityDic = bool(self.oCommunityDic) self.bPersonalDic = bool(self.oPersonalDic) self.oTokenizer = None # Default suggestions self.lexicographer = None self.loadLang(sLangCode) # storage self.bStorage = False self._dMorphologies = {} # key: flexion, value: list of morphologies self._dLemmas = {} # key: flexion, value: list of lemmas def _loadDictionary (self, source, bNecessary=False): "returns an IBDAWG object" |
︙ | ︙ | |||
98 99 100 101 102 103 104 | def deactivatePersonalDictionary (self): "deactivate personal dictionary" self.bPersonalDic = False # Default suggestions | | | | > > > > > > > > > > > > > > > > | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | def deactivatePersonalDictionary (self): "deactivate personal dictionary" self.bPersonalDic = False # Default suggestions def loadLang (self, sLangCode): "load default suggestion module for <sLangCode>" try: self.lexicographer = importlib.import_module("."+sLangCode, "grammalecte.graphspell") except ImportError: print("No suggestion module for language <"+sLangCode+">") return def analyze (self, sWord): "returns a list of words and their morphologies" if not self.lexicographer: return [] lWordAndMorph = [] for sElem in self.lexicographer.split(sWord): if sElem: lMorph = self.getMorph(sElem) sLex = self.lexicographer.analyze(sElem) if sLex: aRes = [ (" | ".join(lMorph), sLex) ] else: aRes = [ (sMorph, self.lexicographer.formatTags(sMorph)) for sMorph in lMorph ] if aRes: lWordAndMorph.append((sElem, aRes)) return lWordAndMorph # Storage def activateStorage (self): "store all lemmas and morphologies retrieved from the word graph" self.bStorage = True |
︙ | ︙ | |||
157 158 159 160 161 162 163 164 165 166 167 168 169 170 | else: if not bByLemma: dWord[dToken['sValue']] = dWord.get(dToken['sValue'], 0) + 1 else: for sLemma in self.getLemma(dToken['sValue']): dWord[sLemma] = dWord.get(sLemma, 0) + 1 return dWord # IBDAWG functions def isValidToken (self, sToken): "checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)" if self.oMainDic.isValidToken(sToken): return True | > | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | else: if not bByLemma: dWord[dToken['sValue']] = dWord.get(dToken['sValue'], 0) + 1 else: for sLemma in self.getLemma(dToken['sValue']): dWord[sLemma] = dWord.get(sLemma, 0) + 1 return dWord # IBDAWG functions def isValidToken (self, sToken): "checks if sToken is valid (if there is hyphens in sToken, sToken is split, each part is checked)" if self.oMainDic.isValidToken(sToken): return True |
︙ | ︙ | |||
214 215 216 217 218 219 220 | if sWord not in self._dLemmas: self.getMorph(sWord) return self._dLemmas[sWord] return { s[1:s.find("/")] for s in self.getMorph(sWord) } def suggest (self, sWord, nSuggLimit=10): "generator: returns 1, 2 or 3 lists of suggestions" | | | | | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | if sWord not in self._dLemmas: self.getMorph(sWord) return self._dLemmas[sWord] return { s[1:s.find("/")] for s in self.getMorph(sWord) } def suggest (self, sWord, nSuggLimit=10): "generator: returns 1, 2 or 3 lists of suggestions" if self.lexicographer.dSugg: if sWord in self.lexicographer.dSugg: yield self.lexicographer.dSugg[sWord].split("|") elif sWord.istitle() and sWord.lower() in self.lexicographer.dSugg: lRes = self.lexicographer.dSugg[sWord.lower()].split("|") yield list(map(lambda sSugg: sSugg[0:1].upper()+sSugg[1:], lRes)) else: yield self.oMainDic.suggest(sWord, nSuggLimit, True) else: yield self.oMainDic.suggest(sWord, nSuggLimit, True) if self.bCommunityDic: yield self.oCommunityDic.suggest(sWord, (nSuggLimit//2)+1) |
︙ | ︙ |