Index: gc_lang/fr/build_data.py ================================================================== --- gc_lang/fr/build_data.py +++ gc_lang/fr/build_data.py @@ -26,11 +26,11 @@ os.chdir(self.savedPath) def makeDictionaries (sp, sVersion): with cd(sp+"/dictionnaire"): - os.system("genfrdic.py -s -v "+sVersion) + os.system("genfrdic.py -s -gl -v "+sVersion) def makeConj (sp, bJS=False): print("> Conjugaisons ", end="") print("(Python et JavaScript)" if bJS else "(Python seulement)") Index: gc_lang/fr/dictionnaire/genfrdic.py ================================================================== --- gc_lang/fr/dictionnaire/genfrdic.py +++ gc_lang/fr/dictionnaire/genfrdic.py @@ -549,11 +549,11 @@ self.writeAffixes(spDic, dVars, nMode, bSimplified) self.writeDictionary(spDic, dVars, nMode, bSimplified) copyTemplate('orthographe', spDic, 'README_dict_fr.txt', dVars) createZipFiles(spDic, spDst, sDicName + '.zip') - def createLibreOfficeExtension (self, spBuild, dTplVars, lDictVars, spGL): + def createLibreOfficeExtension (self, spBuild, dTplVars, lDictVars, spDestGL=""): # LibreOffice extension echo(" * Dictionnaire >> extension pour LibreOffice") dTplVars['version'] = self.sVersion sExtensionName = EXT_PREFIX_OOO + self.sVersion spExt = spBuild + '/' + sExtensionName @@ -588,15 +588,15 @@ file_util.copy_file('césures/README_hyph_fr-3.0.txt', spExt+'/dictionaries') file_util.copy_file('césures/README_hyph_fr-2.9.txt', spExt+'/dictionaries') # zip createZipFiles(spExt, spBuild, sExtensionName + '.oxt') # copy to Grammalecte Project - if spGL: + if spDestGL: echo(" extension copiée dans Grammalecte...") - dir_util.copy_tree(spExt+'/dictionaries', spGL) + dir_util.copy_tree(spExt+'/dictionaries', spDestGL) - def createMozillaExtensions (self, spBuild, dTplVars, lDictVars, spDestGL): + def createMozillaExtensions (self, spBuild, dTplVars, lDictVars, spDestGL=""): # Mozilla extension 1 echo(" * Dictionnaire >> extension pour Mozilla") dTplVars['version'] = self.sVersion sExtensionName = EXT_PREFIX_MOZ + self.sVersion spExt = spBuild + '/' + sExtensionName @@ -606,14 +606,15 @@ file_util.copy_file(spDict+'/fr-classique.dic', spExt+'/dictionaries/fr-classic.dic') file_util.copy_file(spDict+'/fr-classique.aff', spExt+'/dictionaries/fr-classic.aff') copyTemplate('orthographe', spExt, 'README_dict_fr.txt', dTplVars) createZipFiles(spExt, spBuild, sExtensionName + '.xpi') # Grammalecte - echo(" * Dictionnaire >> copie des dicos dans Grammalecte") - for dVars in lDictVars: - file_util.copy_file(spDict+'/'+dVars['asciiName']+'.dic', spDestGL+'/'+dVars['mozAsciiName']+"/"+dVars['mozAsciiName']+'.dic') - file_util.copy_file(spDict+'/'+dVars['asciiName']+'.aff', spDestGL+'/'+dVars['mozAsciiName']+"/"+dVars['mozAsciiName']+'.aff') + if spDestGL: + echo(" * Dictionnaire >> copie des dicos dans Grammalecte") + for dVars in lDictVars: + file_util.copy_file(spDict+'/'+dVars['asciiName']+'.dic', spDestGL+'/'+dVars['mozAsciiName']+"/"+dVars['mozAsciiName']+'.dic') + file_util.copy_file(spDict+'/'+dVars['asciiName']+'.aff', spDestGL+'/'+dVars['mozAsciiName']+"/"+dVars['mozAsciiName']+'.aff') def createFileIfqForDB (self, spBuild): echo(" * Dictionnaire >> indices de fréquence pour la DB...") with open(spBuild+'/dictIdxIfq-'+self.sVersion+'.diff.txt', 'w', encoding='utf-8', newline="\n") as hDiff, \ open(spBuild+'/dictIdxIfq-'+self.sVersion+'.notes.txt', 'w', encoding='utf-8', newline="\n") as hNotes: @@ -620,11 +621,11 @@ for oEntry in self.lEntry: if oEntry.fq != oEntry.oldFq: hDiff.write("{0.iD}\t{0.fq}\n".format(oEntry)) hNotes.write("{0.lemma}/{0.flags}\t{0.oldFq} > {0.fq}\n".format(oEntry)) - def createLexiconPackages (self, spBuild, version, oStatsLex, spLexGL): + def createLexiconPackages (self, spBuild, version, oStatsLex, spDestGL=""): sLexName = LEX_PREFIX + version spLex = spBuild + '/' + sLexName dir_util.mkpath(spLex) # write Dicollecte lexicon self.sortLexiconByFreq() @@ -632,30 +633,33 @@ self.writeGrammarCheckerLexicon(spBuild + '/' + sLexName + '.lex', version) copyTemplate('lexique', spLex, 'README_lexique.txt', {'version': version}) # zip createZipFiles(spLex, spBuild, sLexName + '.zip') # copy GC lexicon to Grammalecte - file_util.copy_file(spBuild + '/' + sLexName + '.lex', spLexGL + '/French.lex') - file_util.copy_file('lexique/French.tagset.txt', spLexGL) + if spDestGL: + file_util.copy_file(spBuild + '/' + sLexName + '.lex', spDestGL + '/French.lex') + file_util.copy_file('lexique/French.tagset.txt', spDestGL) - def createDictConj (self, spBuild, spCopy): + def createDictConj (self, spBuild, spDestGL=""): echo(" * Dictionnaire >> fichier de conjugaison...") with open(spBuild+'/dictConj.txt', 'w', encoding='utf-8', newline="\n") as hDst: for oEntry in self.lEntry: if oEntry.po.startswith("v"): hDst.write(oEntry.getConjugation()) - echo(" Fichier de conjugaison copié dans Grammalecte...") - file_util.copy_file(spBuild+'/dictConj.txt', spCopy) + if spDestGL: + echo(" Fichier de conjugaison copié dans Grammalecte...") + file_util.copy_file(spBuild+'/dictConj.txt', spDestGL) - def createDictDecl (self, spBuild, spCopy): + def createDictDecl (self, spBuild, spDestGL=""): echo(" * Dictionnaire >> fichier de déclinaison...") with open(spBuild+'/dictDecl.txt', 'w', encoding='utf-8', newline="\n") as hDst: for oEntry in self.lEntry: if re.match("[SXFWIA]", oEntry.flags) and (oEntry.po.startswith("nom") or oEntry.po.startswith("adj")): hDst.write(oEntry.getDeclination()) - echo(" Fichier de déclinaison copié dans Grammalecte...") - file_util.copy_file(spBuild+'/dictDecl.txt', spCopy) + if spDestGL: + echo(" Fichier de déclinaison copié dans Grammalecte...") + file_util.copy_file(spBuild+'/dictDecl.txt', spDestGL) def generateSpellVariants (self, nReq, spBuild): if nReq < 1: nReq = 1 if nReq > 2: nReq = 2 echo(" * Lexique >> variantes par suppression... n = " + str(nReq)) @@ -807,13 +811,10 @@ echo(" dans : " + self.lemma) def __str__ (self): return "{0.lemma}/{0.flags} {1}".format(self, self.getMorph(2)) - def display (self): - echo(self.__str__()) - def check (self): sErr = '' if self.lemma == '': sErr += 'lemme vide' if not re.match(r"[a-zA-ZéÉôÔàâÂîÎïèÈêÊÜœŒæÆçÇ0-9µåÅΩ&αβγδεζηθικλμνξοπρστυφχψωΔℓΩ_]", self.lemma): @@ -1077,11 +1078,11 @@ def solveOccurMultipleFlexions (self, hDst, oStatsLex): sBlank = " " if self.nAKO >= 0: for oFlex in self.lFlexions: - if oFlex.nMulti > 0 and not oFlex.bFixed: + if oFlex.nMulti > 0 and not oFlex.bBlocked: # on trie les entrées avec AKO et sans AKO lEntWithAKO = [] lEntNoAKO = [] for oEntry in oFlex.lMulti: if oEntry.nAKO >= 0: @@ -1101,25 +1102,25 @@ hDst.write(" * {0.sFlexion}\n".format(oFlex)) hDst.write(" moyenne connue\n") for oFlexD in self.lFlexions: if oFlex.sFlexion == oFlexD.sFlexion: hDst.write(sBlank + "{2:<30} {0.sMorph:<30} {0.nOccur:>10} >> {1:>10}\n".format(oFlexD, self.nAKO, self.getShortDescr())) - oFlexD.setOccur(self.nAKO) + oFlexD.setOccurAndBlock(self.nAKO) for oEntry in lEntWithAKO: hDst.write(" moyenne connue\n") for oFlexM in oEntry.lFlexions: if oFlex.sFlexion == oFlexM.sFlexion: hDst.write(sBlank + "{2:<30} {0.sMorph:<30} {0.nOccur:>10} >> {1:>10}\n".format(oFlexM, oEntry.nAKO, oEntry.getShortDescr())) - oFlexM.setOccur(oEntry.nAKO) + oFlexM.setOccurAndBlock(oEntry.nAKO) # on répercute nDiff sur les flexions sans AKO for oEntry in lEntNoAKO: hDst.write(" sans moyenne connue\n") for oFlexM in oEntry.lFlexions: if oFlex.sFlexion == oFlexM.sFlexion: nNewOccur = oFlexM.nOccur + math.ceil((nDiff / len(lEntNoAKO)) / oFlexM.nDup) hDst.write(sBlank + "{2:<30} {0.sMorph:<30} {0.nOccur:>10} +> {1:>10}\n".format(oFlexM, nNewOccur, oEntry.getShortDescr())) - oFlexM.setOccur(nNewOccur) + oFlexM.setOccurAndBlock(nNewOccur) else: # Toutes les entrées sont avec AKO : on pondère nFlexOccur = oStatsLex.getFlexionOccur(oFlex.sFlexion) nTotAKO = self.nAKO for oEnt in oFlex.lMulti: @@ -1129,17 +1130,17 @@ hDst.write(" moyennes connues\n") for oFlexD in self.lFlexions: if oFlex.sFlexion == oFlexD.sFlexion: nNewOccur = math.ceil((nFlexOccur * (self.nAKO / nTotAKO)) / oFlexD.nDup) if nTotAKO else 0 hDst.write(sBlank + "{2:<30} {0.sMorph:<30} {0.nOccur:>10} %> {1:>10}\n".format(oFlexD, nNewOccur, self.getShortDescr())) - oFlexD.setOccur(nNewOccur) + oFlexD.setOccurAndBlock(nNewOccur) for oEntry in oFlex.lMulti: for oFlexM in oEntry.lFlexions: if oFlex.sFlexion == oFlexM.sFlexion: nNewOccur = math.ceil((nFlexOccur * (oEntry.nAKO / nTotAKO)) / oFlexM.nDup) if nTotAKO else 0 hDst.write(sBlank + "{2:<30} {0.sMorph:<30} {0.nOccur:>10} %> {1:>10}\n".format(oFlexM, nNewOccur, oEntry.getShortDescr())) - oFlexM.setOccur(nNewOccur) + oFlexM.setOccurAndBlock(nNewOccur) def calcFreq (self, nTot): self.fFreq = (self.nOccur * 100) / nTot self.oldFq = self.fq self.fq = getIfq(self.fFreq) @@ -1151,22 +1152,25 @@ self.oEntry = oEntry self.sFlexion = sFlex self.sMorph = sMorph self.cDic = cDic self.nOccur = 0 - self.bFixed = False + self.bBlocked = False self.nDup = 0 # duplicates in the same entry self.nMulti = 0 # duplicates with other entries self.lMulti = [] # list of similar flexions self.fFreq = 0 self.cFq = '' self.metagfx = '' # métagraphe self.metaph2 = '' # métaphone 2 - + def setOccur (self, n): self.nOccur = n - self.bFixed = True + + def setOccurAndBlock (self, n): + self.nOccur = n + self.bBlocked = True def calcOccur (self): self.nOccur = math.ceil((self.nOccur / (self.nMulti+1)) / self.nDup) def calcFreq (self, nTot): @@ -1192,13 +1196,10 @@ sOccurs = '' for v in oStatsLex.dFlexions[self.sFlexion]: sOccurs += str(v) + "\t" return "{0.oEntry.iD}\t{0.sFlexion}\t{0.oEntry.sRadical}\t{0.sMorph}\t{0.metagfx}\t{0.metaph2}\t{0.oEntry.lx}\t{0.oEntry.se}\t{0.oEntry.et}\t{0.oEntry.di}{2}\t{1}{0.nOccur}\t{0.nDup}\t{0.nMulti}\t{0.fFreq:.15f}\t{0.cFq}\n".format(self, sOccurs, "/"+self.cDic if self.cDic != "*" else "") - def display (self): - echo(self.__str__()) - @classmethod def simpleHeader (cls): return "# :POS ;LEX ~SEM =FQ /DIC\n" def getGrammarCheckerRepr (self): @@ -1506,10 +1507,11 @@ xParser.add_argument("-v", "--verdic", help="set dictionary version, i.e. 5.4", type=str, default="X.Y.z") xParser.add_argument("-m", "--mode", help="0: no tags, 1: Hunspell tags (default), 2: All tags", type=int, choices=[0, 1, 2], default=1) xParser.add_argument("-u", "--uncompress", help="do not use Hunspell compression", action="store_true") xParser.add_argument("-s", "--simplify", help="no virtual lemmas", action="store_true") xParser.add_argument("-sv", "--spellvariants", help="generate spell variants", action="store_true") + xParser.add_argument("-gl", "--grammalecte", help="copy generated files to Grammalecte folders", action="store_true") xArgs = xParser.parse_args() if xArgs.simplify: xArgs.mode = 0 xArgs.uncompress = True @@ -1553,19 +1555,25 @@ oStatsLex.write(spBuild+'/test_lex.txt') oFrenchDict.calculateStats(oStatsLex, spfStats) ### écriture des paquets echo("Création des paquets...") + + spLexiconDestGL = "../../../lexicons" if xArgs.grammalecte else "" + spLibreOfficeExtDestGL = "../oxt/Dictionnaires/dictionaries" if xArgs.grammalecte else "" + spMozillaExtDestGL = "../xpi/data/dictionaries" if xArgs.grammalecte else "" + spDataDestGL = "../data" if xArgs.grammalecte else "" + if not xArgs.uncompress: oFrenchDict.defineAbreviatedTags(xArgs.mode, spfStats) oFrenchDict.createFiles(spBuild, [dMODERNE, dTOUTESVAR, dCLASSIQUE, dREFORME1990], xArgs.mode, xArgs.simplify) - oFrenchDict.createLibreOfficeExtension(spBuild, dMOZEXT, [dMODERNE, dTOUTESVAR, dCLASSIQUE, dREFORME1990], "../oxt/Dictionnaires/dictionaries") - oFrenchDict.createMozillaExtensions(spBuild, dMOZEXT, [dMODERNE, dTOUTESVAR, dCLASSIQUE, dREFORME1990], "../xpi/data/dictionaries") - oFrenchDict.createLexiconPackages(spBuild, xArgs.verdic, oStatsLex, "../../../lexicons") + oFrenchDict.createLexiconPackages(spBuild, xArgs.verdic, oStatsLex, spLexiconDestGL) oFrenchDict.createFileIfqForDB(spBuild) - oFrenchDict.createDictConj(spBuild, "../data") - oFrenchDict.createDictDecl(spBuild, "../data") + oFrenchDict.createLibreOfficeExtension(spBuild, dMOZEXT, [dMODERNE, dTOUTESVAR, dCLASSIQUE, dREFORME1990], spLibreOfficeExtDestGL) + oFrenchDict.createMozillaExtensions(spBuild, dMOZEXT, [dMODERNE, dTOUTESVAR, dCLASSIQUE, dREFORME1990], spMozillaExtDestGL) + oFrenchDict.createDictConj(spBuild, spDataDestGL) + oFrenchDict.createDictDecl(spBuild, spDataDestGL) if __name__ == '__main__': main()