X-Git-Url: http://iramuteq.org/git?a=blobdiff_plain;f=textcheckcorpus.py;h=5ac7539f683c2ec800af14aa392b9d957b80c631;hb=82dde3ff5f415750e7968fcacf8b0b7d18d2ce53;hp=1c527398c99cae56ee4cb4c1396daf08bd3f4acf;hpb=22cd27b2bbe9ab1ffa7ef06fa764b5147ae17dad;p=iramuteq diff --git a/textcheckcorpus.py b/textcheckcorpus.py index 1c52739..5ac7539 100644 --- a/textcheckcorpus.py +++ b/textcheckcorpus.py @@ -1,38 +1,46 @@ -#!/bin/env python # -*- coding: utf-8 -*- #Author: Pierre Ratinaud -#Copyright (c) 2010, Pierre Ratinaud -#Lisense: GNU/GPL -from corpus import Corpus +#Copyright (c) 2008-2020 Pierre Ratinaud +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 +#License: GNU/GPL + +#------------------------------------ +# import des modules wx +#------------------------------------ import wx import wx.lib.dialogs +#------------------------------------ +# import des fichiers du projet +#------------------------------------ +from corpus import Corpus + def checkline(line, lnb) : - if line.startswith(u'****') or (line[0:4].isdigit() and u'*' in line) : - if u' * ' in line : + if line.startswith('****') or (line[0:4].isdigit() and '*' in line) : + if ' * ' in line : return [False, 1, lnb] else : lp = line.split() lp.pop(0) - gv = [val for val in lp if not val.startswith(u'*') or (u'-' in val)] + gv = [val for val in lp if not val.startswith('*') or ('-' in val)] if len(gv) != 0 : return [False, 4, lnb] else : return [True] - - elif line.startswith(u'-*') : - if u' ' in line.strip() : + elif line.startswith('-*') : + if ' ' in line.strip() : return [False, 2, lnb] else : return [True] - elif u'*' in line : + elif '*' in line : return [False, 3, lnb] else : return [True] class checkcorpus : + def __init__(self, parent): self.parent = parent self.corpus = Corpus(parent) @@ -42,19 +50,19 @@ class checkcorpus : res = [checkline(line, i) for i, line in enumerate(self.corpus.content.strip().splitlines())] res_nok = [val for val in res if not val[0]] if len(res_nok) != 0 : - erreur_label = {1 : u"une variable étoilée contient un espace", - 2 : u"une thématique contient un espace", - 3 : u"étoile dans ligne de texte", - 4 : u"une variable étoilée contient un espace ou un -" + erreur_label = {1 : "une variable étoilée contient un espace", + 2 : "une thématique contient un espace", + 3 : "étoile dans ligne de texte", + 4 : "une variable étoilée contient un espace ou un -" } - erreur = [[u'ligne %i' % val[2], erreur_label[val[1]]] for val in res_nok] + erreur = [['ligne %i' % val[2], erreur_label[val[1]]] for val in res_nok] txt = '\n----------------\n'.join(['\t'.join(line) for line in erreur]) for val in res_nok : deb = self.parent.text_ctrl_txt.XYToPosition(0,val[2]) fin = deb + self.parent.text_ctrl_txt.GetLineLength(val[2]) self.parent.text_ctrl_txt.SetStyle(deb, fin, wx.TextAttr("#ff9c00", "#000000")) - msg = u"Veuillez corriger les fautes suivantes dans un éditeur de texte\npuis rechargez le corpus :\n\n" + txt - win = wx.lib.dialogs.ScrolledMessageDialog(self.parent, msg, u"Erreurs") + msg = "Veuillez corriger les fautes suivantes dans un éditeur de texte\npuis rechargez le corpus :\n\n" + txt + win = wx.lib.dialogs.ScrolledMessageDialog(self.parent, msg, "Erreurs") win.CenterOnParent() win.ShowModal() win.Destroy()