<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.core.management import BaseCommand

from ielex.lexicon.models import LanguageList, \
                                 MeaningList, \
                                 Meaning, \
                                 Lexeme, \
                                 CognateClass, \
                                 CognateJudgement, \
                                 LanguageClade, \
                                 Clade


class Command(BaseCommand):

    help = "Computes statistics for https://github.com/lingdb/CoBL/issues/236"\
           "\nPossible parameters are: {1, 2, 3} for task number."

    def add_arguments(self, parser):
        parser.add_argument('task', type=int)

    missing_args_message = "Please provide a task number of {1,2,3}."

    def handle(self, *args, **options):
        # Data to work with:
        current = LanguageList.objects.get(name='Current')
        jena200 = MeaningList.objects.get(name='Jena200')
        languageIds = set(current.languages.values_list('id', flat=True))
        meaningIds = jena200.meanings.values_list('id', flat=True)
        lexemeIds = Lexeme.objects.filter(
            language_id__in=languageIds,
            meaning_id__in=meaningIds).values_list('id', flat=True)
        cognateClassIds = CognateJudgement.objects.filter(
            lexeme_id__in=lexemeIds).values_list(
            'cognate_class_id', flat=True)
        cognateClasses = CognateClass.objects.filter(
            id__in=cognateClassIds,
            root_form='').all()  # Only without root_form is wanted.

        if(options['task'] == 1):
            self.stdout.write('Task 1')
            self.report(self.compute(2, cognateClasses,
                                     meaningIds, languageIds), meaningIds)
        elif(options['task'] == 2):
            self.stdout.write('Task 2')
            task1 = self.compute(2, cognateClasses, meaningIds, languageIds)
            task1CCIds = set([c.id for c in task1 if c is not None])
            self.report([c for c in self.compute(
                1, cognateClasses, meaningIds, languageIds)
                if c is not None and c.id not in task1CCIds], meaningIds)
        elif(options['task'] == 3):
            self.stdout.write('Task 3')
            unwantedCognateClassIds = set(
                [c.id for c in self.compute(1, cognateClasses,
                                            meaningIds,
                                            languageIds) if c is not None])
            cIdcladeMap = {c.id: c for c in Clade.objects.exclude(
                cladeLevel0=0).all()}
            # Computing ._cognateClasses for each clade:
            for _, clade in cIdcladeMap.iteritems():
                inCladeLanguageIds = set(LanguageClade.objects.filter(
                    clade=clade).values_list('language_id', flat=True))
                lexemes = Lexeme.objects.filter(<commit_msg>Codebeauty in stats236.py<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.core.management import BaseCommand

from ielex.lexicon.models import LanguageList, \
                                 MeaningList, \
                                 Meaning, \
                                 Lexeme, \
                                 CognateClass, \
                                 CognateJudgement, \
                                 LanguageClade, \
                                 Clade


class Command(BaseCommand):

    help = "Computes statistics for https://github.com/lingdb/CoBL/issues/236"\
           "\nPossible parameters are: {1, 2, 3} for task number."

    def add_arguments(self, parser):
        parser.add_argument('task', type=int)

    missing_args_message = "Please provide a task number of {1,2,3}."

    def handle(self, *args, **options):
        # Data to work with:
        current = LanguageList.objects.get(name='Current')
        jena200 = MeaningList.objects.get(name='Jena200')
        languageIds = set(current.languages.values_list('id', flat=True))
        meaningIds = jena200.meanings.values_list('id', flat=True)
        lexemeIds = Lexeme.objects.filter(
            language_id__in=languageIds,
            meaning_id__in=meaningIds).values_list('id', flat=True)
        cognateClassIds = CognateJudgement.objects.filter(
            lexeme_id__in=lexemeIds).values_list(
            'cognate_class_id', flat=True)
        cognateClasses = CognateClass.objects.filter(
            id__in=cognateClassIds,
            root_form='').all()  # Only without root_form is wanted.

        if options['task'] == 1:
            self.stdout.write('Task 1')
            self.report(self.compute(2, cognateClasses,
                                     meaningIds, languageIds), meaningIds)
        elif options['task'] == 2:
            self.stdout.write('Task 2')
            task1 = self.compute(2, cognateClasses, meaningIds, languageIds)
            task1CCIds = set([c.id for c in task1 if c is not None])
            self.report([c for c in self.compute(
                1, cognateClasses, meaningIds, languageIds)
                if c is not None and c.id not in task1CCIds], meaningIds)
        elif options['task'] == 3:
            self.stdout.write('Task 3')
            unwantedCognateClassIds = set(
                [c.id for c in self.compute(1, cognateClasses,
                                            meaningIds,
                                            languageIds) if c is not None])
            cIdcladeMap = {c.id: c for c in Clade.objects.exclude(
                cladeLevel0=0).all()}
            # Computing ._cognateClasses for each clade:
            for _, clade in cIdcladeMap.iteritems():
                inCladeLanguageIds = set(LanguageClade.objects.filter(
                    clade=clade).values_list('language_id', flat=True))
                lexemes = Lexeme.objects.filter(
{'fraction_non_alphanumeric': 0.09830280625105024, 'fraction_numerical': 0.012266845908250714, 'mean_word_length': 1.7215363511659807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264590', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1596, 'n_words': 362}