views.py
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
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 })