Index: helpers.py ================================================================== --- helpers.py +++ helpers.py @@ -1,9 +1,10 @@ # Useful tools import os import shutil +import errno import zipfile from string import Template @@ -55,10 +56,20 @@ if not os.path.exists(sp): os.makedirs(sp, exist_ok=True) else: eraseFolder(sp) + +def copyFolderContent (spSrc, spDst): + try: + shutil.copytree(spSrc, spDst) + except OSError as e: + if e.errno == errno.ENOTDIR: + shutil.copy(spSrc, spDst) + else: + raise + def fileFile (spf, dVars): "return file as a text filed with variables from " return Template(open(spf, "r", encoding="utf-8").read()).safe_substitute(dVars) Index: lex_build.py ================================================================== --- lex_build.py +++ lex_build.py @@ -3,24 +3,24 @@ # Lexicon builder import argparse from distutils import dir_util -import grammalecte.dawg as fsa -from grammalecte.ibdawg import IBDAWG +import graphspell.dawg as fsa +from graphspell.ibdawg import IBDAWG def build (spfSrc, sLangName, sDicName, bJSON=False, cStemmingMethod="S", nCompressMethod=1): "transform a text lexicon as a binary indexable dictionary" oDAWG = fsa.DAWG(spfSrc, sLangName, cStemmingMethod) - dir_util.mkpath("grammalecte/_dictionaries") - oDAWG.writeInfo("grammalecte/_dictionaries/" + sDicName + ".info.txt") - oDAWG.createBinary("grammalecte/_dictionaries/" + sDicName + ".bdic", int(nCompressMethod)) + dir_util.mkpath("graphspell/_dictionaries") + oDAWG.writeInfo("graphspell/_dictionaries/" + sDicName + ".info.txt") + oDAWG.createBinary("graphspell/_dictionaries/" + sDicName + ".bdic", int(nCompressMethod)) if bJSON: - dir_util.mkpath("grammalecte-js/_dictionaries") + dir_util.mkpath("graphspell-js/_dictionaries") oDic = IBDAWG(sDicName + ".bdic") - oDic.writeAsJSObject("grammalecte-js/_dictionaries/" + sDicName + ".json", bBinaryDictAsHexString=True) + oDic.writeAsJSObject("graphspell-js/_dictionaries/" + sDicName + ".json", bBinaryDictAsHexString=True) def main (): xParser = argparse.ArgumentParser() xParser.add_argument("src_lexicon", type=str, help="path and file name of the source lexicon") Index: make.py ================================================================== --- make.py +++ make.py @@ -274,10 +274,29 @@ else: build_module.build(sLang, dVars, spLangPack) return dVars['version'] + +def copyGraphspellCore (): + helpers.createCleanFolder("grammalecte/graphspell") + helpers.createCleanFolder("grammalecte-js/graphspell") + dir_util.mkpath("grammalecte/graphspell/_dictionaries") + dir_util.mkpath("grammalecte-js/graphspell/_dictionaries") + for sf in os.listdir("graphspell"): + if not os.path.isdir("graphspell/"+sf): + file_util.copy_file("graphspell/"+sf, "grammalecte/graphspell") + for sf in os.listdir("graphspell-js"): + if not os.path.isdir("graphspell-js/"+sf): + file_util.copy_file("graphspell-js/"+sf, "grammalecte-js/graphspell") + + +def copyGraphspellDictionary (sDicName): + file_util.copy_file("graphspell/_dictionaries/"+sDicName.strip()+".bdic", "grammalecte/graphspell/_dictionaries") + file_util.copy_file("graphspell/_dictionaries/"+sDicName.strip()+".info.txt", "grammalecte/graphspell/_dictionaries") + file_util.copy_file("graphspell-js/_dictionaries/"+sDicName.strip()+".json", "grammalecte-js/graphspell/_dictionaries") + def main (): print("Python: " + sys.version) xParser = argparse.ArgumentParser() xParser.add_argument("lang", type=str, nargs='+', help="lang project to generate (name of folder in /lang)") @@ -300,10 +319,12 @@ xArgs.build_data_after = True dir_util.mkpath("_build") dir_util.mkpath("grammalecte") dir_util.mkpath("grammalecte-js") + + copyGraphspellCore() 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'] @@ -322,16 +343,20 @@ build_data_module = importlib.import_module("gc_lang."+sLang+".build_data") 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 or not os.path.exists("grammalecte/_dictionaries"): + if xArgs.dict: import lex_build lex_build.build(dVars['lexicon_src'], dVars['lang_name'], dVars['dic_name'], xArgs.javascript, dVars['stemming_method'], int(dVars['fsa_method'])) if build_data_module and xArgs.build_data_after: build_data_module.after('gc_lang/'+sLang, dVars, xArgs.javascript) + # copy dictionaries from Graphspell + for sDicName in dVars['dic_name'].split(","): + copyGraphspellDictionary(sDicName) + # make sVersion = create(sLang, xConfig, xArgs.install, xArgs.javascript, ) # tests if xArgs.tests or xArgs.perf or xArgs.perf_memo: