Grammalecte  Diff

Differences From Artifact [48e0746ca6]:

To Artifact [fce132f18a]:


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
191
192
193
194
195
196
197






198
199
200
201
202
203
204







-
-
-
-
-
-







    if os.path.isfile(spf):
        with open(spf, "r", encoding="utf-8") as hSrc:
            for sLine in hSrc:
                yield sLine
    else:
        print("# Error: file not found.")


def createFolder (sp):
    "make a folder if it doesn’t exist; don’t change anything if it exists"
    if not os.path.exists(sp):
        os.makedirs(sp, exist_ok=True)


class Dictionnaire:
    def __init__ (self, version, name):
        # Dictionary
        self.sName = name
        self.lEntry = []
        self.nEntry = 0
526
527
528
529
530
531
532
533

534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552




553
554
555
556
557
558
559
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542




543
544
545
546
547
548
549
550
551
552
553







-
+















-
-
-
-
+
+
+
+







            hDst.write(Flexion.simpleHeader())
            for oFlex in self.lFlexions:
                hDst.write(oFlex.getGrammarCheckerRepr())

    def createFiles (self, spDst, lDictVars, nMode, bSimplified):
        sDicName = PREFIX_DICT_PATH + self.sVersion
        spDic = spDst + '/' + sDicName
        createFolder(spDic)
        os.makedirs(spDic, exist_ok=True)
        for dVars in lDictVars:
            # template vars
            dVars['version'] = self.sVersion
            # Dictionaries files (.dic) (.aff)
            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, sThesVer, spDestGL=""):
        # LibreOffice extension
        echo(" * Dictionnaire >> extension pour LibreOffice")
        dTplVars['version'] = self.sVersion
        sExtensionName = EXT_PREFIX_OOO + self.sVersion
        spExt = spBuild + '/' + sExtensionName
        createFolder(spExt+'/META-INF')
        createFolder(spExt+'/ui')
        createFolder(spExt+'/dictionaries')
        createFolder(spExt+'/pythonpath')
        os.makedirs(spExt+'/META-INF', exist_ok=True)
        os.makedirs(spExt+'/ui', exist_ok=True)
        os.makedirs(spExt+'/dictionaries', exist_ok=True)
        os.makedirs(spExt+'/pythonpath', exist_ok=True)
        shutil.copy2('_templates/ooo/manifest.xml', spExt+'/META-INF')
        shutil.copy2('_templates/ooo/DictionarySwitcher.py', spExt)
        shutil.copy2('_templates/ooo/ds_strings.py', spExt+'/pythonpath')
        shutil.copy2('_templates/ooo/addons.xcu', spExt+'/ui')
        shutil.copy2('_templates/ooo/french_flag.png', spExt)
        shutil.copy2('_templates/ooo/french_flag_16.bmp', spExt+'/ui')
        copyTemplate('_templates/ooo', spExt, 'description.xml', dTplVars)
585
586
587
588
589
590
591
592

593
594
595
596
597
598
599
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593







-
+








    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
        createFolder(spExt+'/dictionaries')
        os.makedirs(spExt+'/dictionaries', exist_ok=True)
        copyTemplate('_templates/moz', spExt, 'manifest.json', dTplVars)
        spDict = spBuild + '/' + PREFIX_DICT_PATH + self.sVersion
        shutil.copy2(spDict+'/fr-classique.dic', spExt+'/dictionaries/fr-classic.dic')
        shutil.copy2(spDict+'/fr-classique.aff', spExt+'/dictionaries/fr-classic.aff')
        copyTemplate('orthographe', spExt, 'README_dict_fr.txt', dTplVars)
        createZipFiles(spExt, spBuild, sExtensionName + '.xpi')
        # Grammalecte
611
612
613
614
615
616
617
618

619
620
621
622
623
624
625
605
606
607
608
609
610
611

612
613
614
615
616
617
618
619







-
+







                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, spDestGL=""):
        sLexName = LEX_PREFIX + version
        spLex = spBuild + '/' + sLexName
        createFolder(spLex)
        os.makedirs(spLex, exist_ok=True)
        # write lexicon
        self.sortLexiconByFreq()
        self.writeLexicon(spLex + '/' + sLexName + '.txt', version, oStatsLex)
        self.writeGrammarCheckerLexicon(spBuild + '/' + sLexName + '.lex', version)
        copyTemplate('lexique', spLex, 'README_lexique.txt', {'version': version})
        # zip
        createZipFiles(spLex, spBuild, sLexName + '.zip')
1412
1413
1414
1415
1416
1417
1418
1419

1420
1421
1422
1423
1424
1425
1426
1406
1407
1408
1409
1410
1411
1412

1413
1414
1415
1416
1417
1418
1419
1420







-
+







            for e in self.dFlexions.items():
                hDst.write("{} - {}\n".format(e[0], e[1]))


def createThesaurusPackage (spBuild, sVersion, spCopy="", spDataDestGL=""):
    print(" * Création du thésaurus")
    spThesaurus = spBuild+"/thesaurus-v"+sVersion
    createFolder(spThesaurus)
    os.makedirs(spThesaurus, exist_ok=True)
    thes_build.build("thesaurus/thes_fr.dat", "thesaurus/synsets_fr.dat", spThesaurus)
    shutil.copy2('thesaurus/README_thes_fr.txt', spThesaurus)
    if spCopy:
        # copy in libreoffice extension package
        print("   Copie du thésaurus dans:", spCopy)
        shutil.copy2(spThesaurus+'/thes_fr.dat', spCopy)
        shutil.copy2(spThesaurus+'/thes_fr.idx', spCopy)
1447
1448
1449
1450
1451
1452
1453
1454

1455
1456
1457
1458
1459
1460
1461
1441
1442
1443
1444
1445
1446
1447

1448
1449
1450
1451
1452
1453
1454
1455







-
+







    echo("Version: " + xArgs.verdic)
    echo("Simplify: " + str(xArgs.simplify))
    echo("Mode: " + str(xArgs.mode))
    echo("Compression: " + str(not(xArgs.uncompress)))

    ### création du répertoire
    spBuild = BUILD_PATH + '/' + xArgs.verdic
    createFolder(spBuild)
    os.makedirs(spBuild, exist_ok=True)

    ### Lecture des fichiers et création du dictionnaire
    oFrenchDict = Dictionnaire(xArgs.verdic, "French dictionary")
    for sFile in ['orthographe/FRANCAIS.dic']:
        oFrenchDict.readDictionary(sFile)
    oFrenchDict.readAffixes('orthographe/FRANCAIS_7.aff')