From 6a2251a854e50e060627cc83b619b396b17d0ecb Mon Sep 17 00:00:00 2001
From: bniton <bartek.niton@gmail.com>
Date: Tue, 9 Oct 2018 16:02:02 +0200
Subject: [PATCH] Add stats by POS printing to create_TEI_walenty script.
---
dictionary/management/commands/create_TEI_walenty.py | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/dictionary/management/commands/create_TEI_walenty.py b/dictionary/management/commands/create_TEI_walenty.py
index ce766a4..2a73eac 100644
--- a/dictionary/management/commands/create_TEI_walenty.py
+++ b/dictionary/management/commands/create_TEI_walenty.py
@@ -7,7 +7,7 @@ import tarfile
from django.core.management.base import BaseCommand
from optparse import make_option
-from dictionary.models import Lemma, Frame_Opinion_Value, \
+from dictionary.models import Lemma, Frame_Opinion_Value, POS, \
get_statuses
from dictionary.teixml import createteixml, write_phrase_types_expansions_in_TEI
from settings import WALENTY_PATH
@@ -126,6 +126,10 @@ class Command(BaseCommand):
return Lemma.objects.filter(pk__in=all_lemmas_pks)
def print_statistics(self, lemmas):
+ self.print_total_statistics(lemmas)
+ self.print_statistics_by_pos(lemmas)
+
+ def print_total_statistics(self, lemmas):
count = {'frames': 0,
'arguments': 0}
for lemma in lemmas:
@@ -133,6 +137,23 @@ class Command(BaseCommand):
count['frames'] += frames.count()
for frame in frames.all():
count['arguments'] += frame.complements.count()
- print (u'Lemmas:\t%d' % lemmas.count())
- print (u'Frames:\t%d' % count['frames'])
- print (u'Arguments:\t%d' % count['arguments'])
+ print (u'Total:')
+ print (u'-- Lemmas:\t%d' % lemmas.count())
+ print (u'-- Frames:\t%d' % count['frames'])
+ print (u'-- Arguments:\t%d' % count['arguments'])
+
+ def print_statistics_by_pos(self, lemmas):
+ for pos in POS.objects.all():
+ pos_lemmas = lemmas.filter(entry_obj__tag=pos)
+ if pos_lemmas.exists():
+ count = {'frames': 0,
+ 'arguments': 0}
+ for lemma in pos_lemmas:
+ frames = lemma.entry_obj.visible_frames()
+ count['frames'] += frames.count()
+ for frame in frames.all():
+ count['arguments'] += frame.complements.count()
+ print (u'%s (%s):' % (pos.name, pos.tag))
+ print (u'-- Lemmas:\t%d' % pos_lemmas.count())
+ print (u'-- Frames:\t%d' % count['frames'])
+ print (u'-- Arguments:\t%d' % count['arguments'])
--
libgit2 0.22.2