Skip to content
Snippets Groups Projects
Select Git revision
  • a994d25f90d2c04879f80d6f9df44878a6ee2428
  • master default protected
  • vertical_relations
  • lu_without_semantic_frames
  • hierarchy
  • additional-unification-filters
  • v0.1.1
  • v0.1.0
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
17 results

views.py

Blame
  • user avatar
    dcz authored
    4627f766
    History
    views.py 2.19 KiB
    from django.contrib.auth.decorators import login_required
    from django.shortcuts import render
    from django.utils.translation import gettext as _
    
    from connections.models import Entry, POS, Status
    from syntax.models import Schema, SchemaOpinion
    from semantics.models import Frame, FrameOpinion
    
    from entries.polish_strings import POS as POS_names, STATUS, SCHEMA_OPINION, FRAME_OPINION
    
    
    @login_required
    def dictionary_statistics(request):
        ALL = _('wszystkie')
    
        # ENTRIES
        entries = Entry.objects.filter(import_error=False)
        pos_names = POS_names()
        status_names = STATUS()
        entry_statuses = list(Status.objects.all())
        all_pos = ['verb', 'noun', 'adj', 'adv']
        entry_stats = {ALL: [entries.count()] + [entries.filter(pos__tag=pos).count() for pos in all_pos]}
        used_statuses = set()
        for status in entry_statuses:
            c = entries.filter(status=status).count()
            if c:
                used_statuses.add(status)
                entry_stats[status_names[status.key]] = [entries.filter(status=status).count()] + [
                    entries.filter(status=status, pos__tag=pos).count() for pos in all_pos]
        all_statuses = [ALL] + [status_names[status.key] for status in entry_statuses if status in used_statuses]
        all_pos = [ALL] + [pos_names[pos] for pos in all_pos]
    
        # SCHEMATA
        schemata = Schema.objects.filter(subentries__entry__import_error=False)
        schema_opinions = SCHEMA_OPINION()
        schema_stats = [(ALL, 'all', schemata.count())] + [
            (schema_opinions[opinion.key], opinion.key, schemata.filter(opinion=opinion).count()) for opinion in
            SchemaOpinion.objects.all()]
    
        # FRAMES
        frames = Frame.objects.all()  # filter(arguments__argument_connections__schema_connections__subentry__entry__import_error=False)
        frame_opinions = FRAME_OPINION()
        frame_stats = [(ALL, 'all', frames.count())] + [
            (frame_opinions[opinion.key], opinion.key, frames.filter(opinion=opinion).count()) for opinion in
            FrameOpinion.objects.all()]
    
        return render(request, 'dictionary_statistics.html',
                      {'all_statuses': all_statuses, 'all_pos': all_pos, 'entry_stats': entry_stats,
                       'schema_stats': schema_stats, 'frame_stats': frame_stats})