Index: gc_core/js/lang_core/gc_engine.js ================================================================== --- gc_core/js/lang_core/gc_engine.js +++ gc_core/js/lang_core/gc_engine.js @@ -323,11 +323,11 @@ try { if (typeof(require) !== 'undefined') { var spellchecker = require("resource://grammalecte/graphspell/spellchecker.js"); _oSpellChecker = new spellchecker.SpellChecker("${lang}", "", "${dic_filename}.json"); } else { - _oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_filename}.json"); + _oSpellChecker = new SpellChecker("${lang}", sPath, "${dic_main_filename_js}", "${dic_extended_filename_js}", "${dic_personal_filename_js}"); } _sAppContext = sContext; _dOptions = gc_options.getOptions(sContext).gl_shallowCopy(); // duplication necessary, to be able to reset to default } catch (e) { Index: gc_core/py/lang_core/gc_engine.py ================================================================== --- gc_core/py/lang_core/gc_engine.py +++ gc_core/py/lang_core/gc_engine.py @@ -290,11 +290,11 @@ def load (sContext="Python"): global _oSpellChecker global _sAppContext global _dOptions try: - _oSpellChecker = SpellChecker("${lang}", "${dic_filename}.bdic") + _oSpellChecker = SpellChecker("${lang}", "${dic_main_filename_py}", "${dic_extended_filename_py}", "${dic_personal_filename_py}") _sAppContext = sContext _dOptions = dict(gc_options.getOptions(sContext)) # duplication necessary, to be able to reset to default except: traceback.print_exc() Index: gc_lang/fr/config.ini ================================================================== --- gc_lang/fr/config.ini +++ gc_lang/fr/config.ini @@ -12,22 +12,21 @@ link = http://grammalecte.net description = Correcteur grammatical pour le français. extras = README_fr.txt logo = logo.png -# lexicon source +# main dictionary lexicon_src = lexicons/French.lex -# binary dictionary file name (no extension filename) dic_filename = fr dic_name = French -# extended dictionary (with extension filename) -lexicon_extended_src = fr.extended.lex -dic_extended_filename = fr.extended.json +# extended dictionary +lexicon_extended_src = lexicons/French.extended.lex +dic_extended_filename = fr.extended dic_extended_name = Français - dictionnaire étendu -# personal dictionary (with extension filename) -lexicon_personal_src = fr.personal.lex -dic_personal_filename = fr.personal.json +# personal dictionary +lexicon_personal_src = lexicons/French.personal.lex +dic_personal_filename = fr.personal dic_personal_name = Français - dictionnaire personnel # Finite state automaton compression: 1, 2 (experimental) or 3 (experimental) fsa_method = 1 # stemming method: S for suffixes only, A for prefixes and suffixes stemming_method = S Index: make.py ================================================================== --- make.py +++ make.py @@ -76,11 +76,11 @@ print("Building extension for Writer") spfZip = "_build/" + dVars['name'] + "-"+ dVars['lang'] +"-v" + dVars['version'] + '.oxt' hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) # Package and parser - copyGrammalectePyPackageInZipFile(hZip, spLangPack, dVars['dic_filename']+".bdic", "pythonpath/") + copyGrammalectePyPackageInZipFile(hZip, spLangPack, "pythonpath/") hZip.write("grammalecte-cli.py", "pythonpath/grammalecte-cli.py") # Extension files hZip.writestr("META-INF/manifest.xml", helpers.fileFile("gc_core/py/oxt/manifest.xml", dVars)) hZip.writestr("description.xml", helpers.fileFile("gc_core/py/oxt/description.xml", dVars)) @@ -154,26 +154,28 @@ def createPackageZip (sLang, dVars, spLangPack): "create server zip" spfZip = "_build/" + dVars['name'] + "-"+ dVars['lang'] +"-v" + dVars['version'] + '.zip' hZip = zipfile.ZipFile(spfZip, mode='w', compression=zipfile.ZIP_DEFLATED) - copyGrammalectePyPackageInZipFile(hZip, spLangPack, dVars['dic_filename']+".bdic") + copyGrammalectePyPackageInZipFile(hZip, spLangPack) for spf in ["grammalecte-cli.py", "grammalecte-server.py", "bottle.py", \ "grammalecte-server-options._global.ini", "grammalecte-server-options."+sLang+".ini", \ "README.txt", "LICENSE.txt", "LICENSE.fr.txt"]: hZip.write(spf) hZip.writestr("setup.py", helpers.fileFile("gc_lang/fr/setup.py", dVars)) -def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sfDict, sAddPath=""): +def copyGrammalectePyPackageInZipFile (hZip, spLangPack, sAddPath=""): for sf in os.listdir("grammalecte"): if not os.path.isdir("grammalecte/"+sf): hZip.write("grammalecte/"+sf, sAddPath+"grammalecte/"+sf) for sf in os.listdir("grammalecte/graphspell"): if not os.path.isdir("grammalecte/graphspell/"+sf): hZip.write("grammalecte/graphspell/"+sf, sAddPath+"grammalecte/graphspell/"+sf) - hZip.write("grammalecte/graphspell/_dictionaries/"+sfDict, sAddPath+"grammalecte/graphspell/_dictionaries/"+sfDict) + for sf in os.listdir("grammalecte/graphspell/_dictionaries"): + if not os.path.isdir("grammalecte/graphspell/_dictionaries/"+sf): + hZip.write("grammalecte/graphspell/_dictionaries/"+sf, sAddPath+"grammalecte/graphspell/_dictionaries/"+sf) for sf in os.listdir(spLangPack): if not os.path.isdir(spLangPack+"/"+sf): hZip.write(spLangPack+"/"+sf, sAddPath+spLangPack+"/"+sf) @@ -302,24 +304,50 @@ if not os.path.isdir("graphspell-js/"+sf): file_util.copy_file("graphspell-js/"+sf, "grammalecte-js/graphspell") helpers.copyAndFileTemplate("graphspell-js/"+sf, "grammalecte-js/graphspell/"+sf, dVars) -def copyGraphspellDictionary (dVars, bJavaScript=False): - spfPyDic = "graphspell/_dictionaries/"+dVars['dic_filename']+".bdic" - spfJSDic = "graphspell-js/_dictionaries/"+dVars['dic_filename']+".json" - if not os.path.isfile(spfPyDic) or (bJavaScript and not os.path.isfile(spfJSDic)): - buildDictionary(dVars, bJavaScript) - file_util.copy_file(spfPyDic, "grammalecte/graphspell/_dictionaries") - file_util.copy_file(spfPyDic[:-5]+".info.txt", "grammalecte/graphspell/_dictionaries") - if bJavaScript: - file_util.copy_file(spfJSDic, "grammalecte-js/graphspell/_dictionaries") +def copyGraphspellDictionaries (dVars, bJavaScript=False, bExtendedDict=False, bPersonalDict=False): + dVars["dic_main_filename_py"] = "" + dVars["dic_main_filename_js"] = "" + dVars["dic_extended_filename_py"] = "" + dVars["dic_extended_filename_js"] = "" + dVars["dic_personal_filename_py"] = "" + dVars["dic_personal_filename_js"] = "" + lDict = [ ("main", dVars['dic_filename']) ] + if bExtendedDict: + lDict.append(("extended", dVars['dic_extended_filename'])) + if bPersonalDict: + lDict.append(("personal", dVars['dic_personal_filename'])) + for sType, sFileName in lDict: + spfPyDic = "graphspell/_dictionaries/" + sFileName + ".bdic" + spfJSDic = "graphspell-js/_dictionaries/" + sFileName + ".json" + if not os.path.isfile(spfPyDic) or (bJavaScript and not os.path.isfile(spfJSDic)): + buildDictionary(dVars, sType, bJavaScript) + print(spfPyDic) + file_util.copy_file(spfPyDic, "grammalecte/graphspell/_dictionaries") + dVars['dic_'+sType+'_filename_py'] = sFileName + '.bdic' + if bJavaScript: + file_util.copy_file(spfJSDic, "grammalecte-js/graphspell/_dictionaries") + dVars['dic_'+sType+'_filename_js'] = sFileName + '.json' -def buildDictionary (dVars, bJavaScript): - lex_build.build(dVars['lexicon_src'], dVars['lang'], dVars['lang_name'], dVars['dic_filename'], \ - bJavaScript, dVars['dic_name'], dVars['stemming_method'], int(dVars['fsa_method'])) +def buildDictionary (dVars, sType, bJavaScript=False): + if sType == "main": + spfLexSrc = dVars['lexicon_src'] + sfDictDst = dVars['dic_filename'] + sDicName = dVars['dic_name'] + elif sType == "extended": + spfLexSrc = dVars['lexicon_extended_src'] + sfDictDst = dVars['dic_extended_filename'] + sDicName = dVars['dic_extended_name'] + elif sType == "personal": + spfLexSrc = dVars['lexicon_personal_src'] + sfDictDst = dVars['dic_personal_filename'] + sDicName = dVars['dic_personal_name'] + lex_build.build(spfLexSrc, dVars['lang'], dVars['lang_name'], sfDictDst, bJavaScript, sDicName, dVars['stemming_method'], int(dVars['fsa_method'])) + def main (): print("Python: " + sys.version) xParser = argparse.ArgumentParser() @@ -330,10 +358,12 @@ xParser.add_argument("-d", "--dict", help="generate FSA dictionary", action="store_true") xParser.add_argument("-t", "--tests", help="run unit tests", action="store_true") xParser.add_argument("-p", "--perf", help="run performance tests", action="store_true") xParser.add_argument("-pm", "--perf_memo", help="run performance tests and store results in perf_memo.txt", action="store_true") xParser.add_argument("-js", "--javascript", help="JavaScript build for Firefox", action="store_true") + xParser.add_argument("-aed", "--add_extended_dictionary", help="add extended dictionary to the build", action="store_true") + xParser.add_argument("-apd", "--add_personal_dictionary", help="add personal dictionary to the build", action="store_true") xParser.add_argument("-fx", "--firefox", help="Launch Firefox Developper for WebExtension testing", action="store_true") xParser.add_argument("-we", "--web_ext", help="Launch Firefox Nightly for WebExtension testing", action="store_true") xParser.add_argument("-tb", "--thunderbird", help="Launch Thunderbird", action="store_true") xParser.add_argument("-i", "--install", help="install the extension in Writer (path of unopkg must be set in config.ini)", action="store_true") xArgs = xParser.parse_args() @@ -352,10 +382,15 @@ for sLang in xArgs.lang: if os.path.exists("gc_lang/"+sLang) and os.path.isdir("gc_lang/"+sLang): xConfig = getConfig(sLang) dVars = xConfig._sections['args'] + if not dVars["lexicon_extended_src"]: + xArgs.add_extended_dictionary = False + if not dVars["lexicon_personal_src"]: + xArgs.add_personal_dictionary = False + # build data build_data_module = None if xArgs.build_data_before or xArgs.build_data_after: # lang data try: @@ -363,16 +398,20 @@ except ImportError: print("# Error. Couldn’t import file build_data.py in folder gc_lang/"+sLang) if build_data_module and xArgs.build_data_before: build_data_module.before('gc_lang/'+sLang, dVars, xArgs.javascript) if xArgs.dict: - buildDictionary(dVars, xArgs.javascript) + buildDictionary(dVars, "main", xArgs.javascript) + if xArgs.add_extended_dictionary: + buildDictionary(dVars, "extended", xArgs.javascript) + if xArgs.add_personal_dictionary: + buildDictionary(dVars, "personal", xArgs.javascript) if build_data_module and xArgs.build_data_after: build_data_module.after('gc_lang/'+sLang, dVars, xArgs.javascript) # copy dictionaries from Graphspell - copyGraphspellDictionary(dVars, xArgs.javascript) + copyGraphspellDictionaries(dVars, xArgs.javascript, xArgs.add_extended_dictionary, xArgs.add_personal_dictionary) # make sVersion = create(sLang, xConfig, xArgs.install, xArgs.javascript, ) # tests