Exemplo n.º 1
0
    def handle(self, *args, **options):
        test = options.get('test')
        self.verbosity = options.get('verbosity') if not test else 3
        self.dry_run = options.get('dry_run')

        if self.verbosity == 0:
            log.setLevel(logging.WARN)
        elif self.verbosity == 1:  # default
            log.setLevel(logging.INFO)
        elif self.verbosity > 1:
            log.setLevel(logging.DEBUG)
        if self.verbosity > 2:
            log.setLevel(logging.DEBUG)

        if test:
            self.stdout.write("Execute test:")
            r1, r2 = gender_split(test)
            self.stdout.write("{:>20} ==>\t{:>20}\t{:>20}".format(
                test, r1, r2))
            exit()

        qs = None
        if options.get('all'):
            qs = Word.objects.filter(word__icontains=',')
        else:
            qs = Word.objects.valid().filter(word__icontains=',')

        total = len(qs)
        self.stdout.write("Found {} words".format(total))
        try:
            i = 0

            for w in qs:
                r1, r2 = gender_split(w.word)
                if not self.dry_run and r1 and r2:
                    Word.objects.get_or_create(
                        word=r1, defaults={'excluded': w.excluded})
                    Word.objects.get_or_create(
                        word=r2, defaults={'excluded': w.excluded})
                    if not w.excluded:
                        w.excluded = True
                        w.save()
                    i += 1

        except KeyboardInterrupt:
            self.stdout.write("User interrupt! Exit gracefully...")
        except Exception as e:
            self.stderr.write("Unhandled exception: {}".format(e))

        self.stdout.write("Done for {}/{}!".format(i, total))
Exemplo n.º 2
0
    def handle(self, *args, **options):
        test = options.get('test')
        self.verbosity = options.get('verbosity') if not test else 3
        self.dry_run = options.get('dry_run')

        if self.verbosity == 0:
            log.setLevel(logging.WARN)
        elif self.verbosity == 1:  # default
            log.setLevel(logging.INFO)
        elif self.verbosity > 1:
            log.setLevel(logging.DEBUG)
        if self.verbosity > 2:
            log.setLevel(logging.DEBUG)

        if test:
            self.stdout.write("Execute test:")
            r1, r2 = gender_split(test)
            self.stdout.write("{:>20} ==>\t{:>20}\t{:>20}".format(test, r1, r2))
            exit()

        qs = None
        if options.get('all'):
            qs = Word.objects.filter(word__icontains=',')
        else:
            qs = Word.objects.valid().filter(word__icontains=',')

        total = len(qs)
        self.stdout.write("Found {} words".format(total))
        try:
            i = 0

            for w in qs:
                r1, r2 = gender_split(w.word)
                if not self.dry_run and r1 and r2:
                    Word.objects.get_or_create(word=r1, defaults={'excluded': w.excluded})
                    Word.objects.get_or_create(word=r2, defaults={'excluded': w.excluded})
                    if not w.excluded:
                        w.excluded = True
                        w.save()
                    i += 1

        except KeyboardInterrupt:
            self.stdout.write("User interrupt! Exit gracefully...")
        except Exception as e:
            self.stderr.write("Unhandled exception: {}".format(e))

        self.stdout.write("Done for {}/{}!".format(i, total))
Exemplo n.º 3
0
 def test_mery(self):
     self.assertCountEqual(gender_split("sacristán, na"), ("sacristán", "sacristana"))
     self.assertCountEqual(gender_split("saltarín, na"), ("saltarín", "saltarina"))
     self.assertCountEqual(gender_split("sirviente, ta"), ("sirviente", "sirvienta"))
     self.assertCountEqual(gender_split("danzarín, na"), ("danzarín", "danzarina"))
     self.assertCountEqual(gender_split("dios, sa"), ("dios", "diosa"))
     self.assertCountEqual(gender_split("gigante, ta"), ("gigante", "giganta"))
     self.assertCountEqual(gender_split("guardián, na"), ("guardián", "guardiana"))
     self.assertCountEqual(gender_split("jefe, fa"), ("jefe", "jefa"))
     self.assertCountEqual(gender_split("infante, ta"), ("infante", "infanta"))
     self.assertCountEqual(gender_split("alazán, na"), ("alazán", "alazana"))
     self.assertCountEqual(gender_split("alcahuete, ta"), ("alcahuete", "alcahueta"))
     self.assertCountEqual(gender_split("alemán, na"), ("alemán", "alemana"))
     self.assertCountEqual(gender_split("regordete, ta"), ("regordete", "regordeta"))
     self.assertCountEqual(gender_split("parlanchín, na"), ("parlanchín", "parlanchina"))
     self.assertCountEqual(gender_split("presidente, ta"), ("presidente", "presidenta"))
     self.assertCountEqual(gender_split("nene, na"), ("nene", "nena"))
     self.assertCountEqual(gender_split("mastín, na"), ("mastín", "mastina"))
     self.assertCountEqual(gender_split("musulmán, na"), ("musulmán", "musulmana"))
     self.assertCountEqual(gender_split("cacique, ca"), ("cacique", "cacica"))
Exemplo n.º 4
0
 def test_regular(self):
     self.assertCountEqual(gender_split("zafio, fia"), ("zafio", "zafia"))
     self.assertCountEqual(gender_split("zagal, la"), ("zagal", "zagala"))
     self.assertCountEqual(gender_split("ciudadrealeño, ña"), ("ciudadrealeño", "ciudadrealeña"))
     self.assertCountEqual(gender_split("cingalés, sa"), ("cingalés", "cingalesa"))
     self.assertCountEqual(gender_split("cimarrón, na"), ("cimarrón", "cimarrona"))