From 3ad52b13a56f9b536ff84948d9ab21fe31e3b5a9 Mon Sep 17 00:00:00 2001 From: Bartłomiej Nitoń <bartomiej@raven.(none)> Date: Mon, 5 Oct 2015 16:55:22 +0200 Subject: [PATCH] Added instalation files and informations to repository. --- INSTALL | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- dictionary/management/commands/create_walenty.py | 12 ++---------- dictionary/management/commands/get_stats.py | 1095 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ dictionary/models.py | 8 ++++++++ 4 files changed, 244 insertions(+), 1021 deletions(-) diff --git a/INSTALL b/INSTALL index cb2ee02..d74213e 100644 --- a/INSTALL +++ b/INSTALL @@ -1,27 +1,123 @@ -Slowal installation guide: -To run Slowal you will need at least: - - python (tested on 2.7 version); - - django with django-registration (tested on version 0.7) and django-extensions packages; - - database system (tested on PostgreSQL 9.1); - - morphological analyser Morfeusz (http://sgjp.pl/morfeusz/). - - Slowal can be installed on production server as any other Django application. Comprehensive tutorial for setting Django on production server can be found at: http://bailey.st/blog/2012/05/02/ubuntu-django-postgresql-and-nginx-a-rock-solid-web-stack/. Tutorial can also be helpful for setting database for Slowal project. - -Installation: - 1) Change database_data.py file to get connection to yours database (see: http://bailey.st/blog/2012/05/02/ubuntu-django-postgresql-and-nginx-a-rock-solid-web-stack/ for hints). -When you are creating database it is important to make database coding 'utf8' and locale Polish. -In PostgreSQL such database would be created by command: ->>> createdb databaseName -E UTF8 -T template0 -l pl_PL.utf8 - 2) If you want to run Slowal in the domain subfolder change SITE_PREFIX = '' value to other, for example SITE_PREFIX = '/Slowal' - 3) Create database table running: ->>> python manage.py syncdb -command in the main folder of project. Remember to create superuser it will help you in managing database and give access to all Slowal functionalities. - 4) Fill database with initial values running: ->>> python manage.py import_models -command in the main folder of project. - 5) Create default user groups running: ->>> python manage.py create_groups.py -command in the main folder of project. - 6) Slowal is ready to run. - -Slowal was tested on Safari, Opera, Firefox and Chrome web browsers. Working on Internet Explorer compatibility is still in progress +Zainstaluj pipa: +>> apt-get update +>> apt-get -y install python-pip + +Zainstaluj Django w wersji 1.4.8: +>> pip install Django==1.4.8 + +Zainstaluj Django south: +>> apt-get install python-django-south + +Zainstaluj Django extensions: +>> apt-get install python-django-extensions + +Zainstaluj Django registration: +>> apt-get install python-django-registration + +Zainstaluj pythonowy moduł lxml: +>> apt-get install python-lxml + +Zainstaluj Postgresa: +>> sudo apt-get update +>> sudo apt-get install postgresql postgresql-contrib +Zmień użytkownika na postgres: +>> sudo -i -u postgres +A następnie dodaj poszczególne role do postgresa komendą: +>> createuser --interactive +Stwórz pustą bazę danych dla Slowala: +>> createdb slowal -E UTF8 -T template0 -l pl_PL.utf8 +Jeśli locale pl_PL.utf8 nie istnieje dodatkowo należy uruchomić komendy: +>> sudo locale-gen pl_PL.utf8 +>> service postgresql restart +Załaduj dump bazy danych poleceniem (zrzut bazy umieszczony jest w archiwum INSTALL_PACK.zip): +>> psql slowal < obraz_bazy.db + +Zainstaluj gita: +>> apt-get install git + +Sklonuj repozytorium gitowe z GitLaba: +>> git clone http://git.nlp.ipipan.waw.pl/walenty/Slowal.git + +Stwórz folder "Walenty" w folderze "data": +>> cd data +>> mkdir Walenty + +Dodaj w głównym folderze projektu plik konfiguracyjny settings.py (plik umieszczony jest w archiwum INSTALL_PACK.zip): + Zmień w nim zmienną STATIC_ROOT, tak by wskazywała na położenie plików statycznych strony, np.: + STATIC_ROOT = "/home/zil/static/Slowal" + +Dodaj w głównym folderze projektu plik konfiguracyjny database_data.py oraz zdefiniuj w nim połączenie z bazą danych, np.: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'slowal', + 'USER': 'zil', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '5432', + } + } + +Zainstaluj moduł psycopg2: +>> sudo apt-get install python-psycopg2 + +Zgraj pliki statyczne do dedykowanego katalogu poleceniem: +>> python manage.py collectstatic + +Zainstaluj Apacha: +>> apt-get install apache2 + +Zainstaluj mod-wsgi: +>> apt-get install libapache2-mod-wsgi + +Utwórz plik slowal.wsgi odpowiednio definiując w nim ścieżki do plików statycznych. Przykładowa treść pliku poniżej: +-------------------------------------------- +import os, sys + +sys.path.append('/home/zil/static') +sys.path.append('/home/zil/static/Slowal') +os.environ['DJANGO_SETTINGS_MODULE'] = 'Slowal.settings' + +import django.core.handlers.wsgi + +application = django.core.handlers.wsgi.WSGIHandler() +-------------------------------------------- + +Skonfiguruj apacha dodając plik konfiguracyjny (np. o nazwie slowal.conf) do folderu sites-available apacha (domyślnie /etc/apache2/sites-enabled/), ścieżka WSGIScriptAlias musi wskazywać na plik slowal.wsgi. Przykładowy plik konfiguracyjny poniżej: +-------------------------------------------- +<VirtualHost *:80> + ServerAdmin bartek.niton@gmail.com + ServerName slowal.nlp.ipipan.waw.pl + + ServerAlias walenty.ipipan.waw.pl + + DocumentRoot /home/zil/Slowal/templates/ + <Directory /> + Options FollowSymLinks + AllowOverride None + Require all granted + </Directory> + WSGIScriptAlias / /home/zil/scripts/slowal.wsgi + WSGIDaemonProcess Slowal user=zil group=zil processes=2 threads=15 + WSGIProcessGroup Slowal + Alias /static/ /home/zil/static/Slowal/ + <Directory "/home/zil/static/Slowal"> + Require all granted + </Directory> + + ErrorLog /home/zil/logs/Slowal/error.log + CustomLog /home/zil/logs/Slowal/access.log combined +</VirtualHost> +-------------------------------------------- + +Uruchom stronę poleceniem: +>> a2ensite slowal.conf + +Zrestartuj apacha: +>> sudo service apache2 restart + +Zainstaluj Morfeusza2 zgodnie z instrukcjami na stronie http://sgjp.pl/morfeusz/dopobrania.html. + +Ustaw w crontabie cykliczne uruchamianie komend create_walenty i count_positions_occurrences: +1 0 * * 5 python /home/zil/Slowal/manage.py create_walenty +0 1 * * * python /home/zil/Slowal/manage.py count_positions_occurrences diff --git a/dictionary/management/commands/create_walenty.py b/dictionary/management/commands/create_walenty.py index 4b6e173..2347c12 100644 --- a/dictionary/management/commands/create_walenty.py +++ b/dictionary/management/commands/create_walenty.py @@ -29,8 +29,8 @@ from django.core.management.base import BaseCommand from accounts.models import User from dictionary.ajax_vocabulary_management import create_text_walenty from dictionary.ajax_argument_realizations import create_realizations_file -from dictionary.models import Frame_Opinion, Lemma, Lemma_Status, \ - LemmaStatusType, Vocabulary, POS +from dictionary.models import Frame_Opinion, Lemma, Vocabulary, POS, \ + get_checked_statuses, get_ready_statuses from settings import WALENTY_PATH class Command(BaseCommand): @@ -87,12 +87,4 @@ def create_pos_archive(archive, pos, filename_base): finally: os.remove(walenty_path_checked) os.remove(walenty_path_ready) - -def get_checked_statuses(): - checked_type = LemmaStatusType.objects.get(sym_name='checked') - return Lemma_Status.objects.filter(type__priority__gte=checked_type.priority).distinct() - -def get_ready_statuses(): - ready_type = LemmaStatusType.objects.get(sym_name='ready') - return Lemma_Status.objects.filter(type__priority__gte=ready_type.priority).distinct() \ No newline at end of file diff --git a/dictionary/management/commands/get_stats.py b/dictionary/management/commands/get_stats.py index 45bc85d..ed86d14 100644 --- a/dictionary/management/commands/get_stats.py +++ b/dictionary/management/commands/get_stats.py @@ -2,1018 +2,145 @@ # author: B.Niton import codecs -import operator +import datetime from collections import Counter from django.core.management.base import BaseCommand +from django.db.models import Count, Max -from dictionary.models import * +from dictionary.models import Lemma, get_checked_statuses, get_ready_statuses, \ + sorted_frame_char_values_dict -#PHRASEOLOGIC_TYPES = ['comprepnp', 'preplexnp', 'lexnp', 'lex', -# 'fixed'] +LEX_TYPES = ['lex', 'fixed', 'comprepnp'] class Command(BaseCommand): - help = 'Get slowal statistics.' + help = 'Get Walenty statistics.' def handle(self, **options): - all_statuses = [Q(status__status=u'gotowe'), - Q(status__status=u'zalążkowe'), - Q(status__status=u'sprawdzone'), - Q(status__status=u'(F) w obróbce'), - Q(status__status=u'(F) gotowe'), - Q(status__status=u'(F) sprawdzone'), - Q(status__status=u'(S) w obróbce'), - Q(status__status=u'(S) gotowe'), - Q(status__status=u'(S) sprawdzone')] - verified_statuses = [Q(status__status=u'zalążkowe'), - Q(status__status=u'sprawdzone'), - Q(status__status=u'(F) w obróbce'), - Q(status__status=u'(F) gotowe'), - Q(status__status=u'(F) sprawdzone'), - Q(status__status=u'(S) w obróbce'), - Q(status__status=u'(S) gotowe'), - Q(status__status=u'(S) sprawdzone')] + now = datetime.datetime.now().strftime('%Y%m%d') + all_statuses = get_ready_statuses() + verified_statuses = get_checked_statuses() - nouns_stats_dict_all = Counter(get_nouns_stats('data/statystyki_2015_06_30_nouns_all.txt', all_statuses)) - nouns_stats_dict_verified = Counter(get_nouns_stats('data/statystyki_2015_06_30_nouns_verified.txt', verified_statuses)) - - adjs_stats_dict_all = Counter(get_adjs_stats('data/statystyki_2015_06_30_adjs_all.txt', all_statuses)) - adjs_stats_dict_verified = Counter(get_adjs_stats('data/statystyki_2015_06_30_adjs_verified.txt', verified_statuses)) +# nouns_stats_dict_all = Counter(get_stats('data/statystyki_2015_06_30_nouns_all.txt', all_statuses, 'noun')) +# nouns_stats_dict_verified = Counter(get_stats('data/statystyki_2015_06_30_nouns_verified.txt', verified_statuses, 'noun')) + +# adjs_stats_dict_all = Counter(get_stats('data/statystyki_2015_06_30_adjs_all.txt', all_statuses, 'adj')) +# adjs_stats_dict_verified = Counter(get_stats('data/statystyki_2015_06_30_adjs_verified.txt', verified_statuses, 'adj')) +# +# verbs_stats_dict_all = Counter(get_stats('data/statystyki_2015_06_30_verbs_all.txt', all_statuses, 'verb')) +# verbs_stats_dict_verified = Counter(get_stats('data/statystyki_2015_06_30_verbs_verified.txt', verified_statuses, 'verb')) +# + advs_stats_dict_all = Counter(get_stats(all_statuses, 'adv')) + write_stats('data/stats_%s_advs_all.txt' % now, advs_stats_dict_all) +# advs_stats_dict_verified = Counter(get_stats('data/statystyki_2015_06_30_advs_verified.txt', verified_statuses, 'adv')) +# +# all_stats_dict_all = nouns_stats_dict_all + adjs_stats_dict_all + verbs_stats_dict_all + advs_stats_dict_all +# all_stats_dict_verified = nouns_stats_dict_verified + adjs_stats_dict_verified + verbs_stats_dict_verified + advs_stats_dict_verified +# +# write_all_stats('data/statystyki_2015_06_30_all.txt', all_stats_dict_all) +# write_all_stats('data/statystyki_2015_06_30_verified.txt', all_stats_dict_verified) - verbs_stats_dict_all = Counter(get_verb_stats('data/statystyki_2015_06_30_verbs_all.txt', all_statuses)) - verbs_stats_dict_verified = Counter(get_verb_stats('data/statystyki_2015_06_30_verbs_verified.txt', verified_statuses)) +def write_stats(stats_path, stats_dict): + try: + outfile = codecs.open(stats_path, 'wt', 'utf-8') - advs_stats_dict_all = Counter(get_advs_stats('data/statystyki_2015_06_30_advs_all.txt', all_statuses)) - advs_stats_dict_verified = Counter(get_advs_stats('data/statystyki_2015_06_30_advs_verified.txt', verified_statuses)) + outfile.write(u'Liczba typów fraz:\t%d\n' % stats_path['phrases']) + outfile.write(u'Liczba pozycji:\t%d\n' % stats_path['poss']) + outfile.write(u'Liczba haseł:\t%d\n\n' % stats_path['lemmas']) - all_stats_dict_all = nouns_stats_dict_all + adjs_stats_dict_all + verbs_stats_dict_all + advs_stats_dict_all - all_stats_dict_verified = nouns_stats_dict_verified + adjs_stats_dict_verified + verbs_stats_dict_verified + advs_stats_dict_verified + outfile.write(u'Łączna liczba podhaseł:\t%d\n' % stats_path['sub_lemmas']) + outfile.write(u'Liczba podhaseł postaci (ZWROTNOŚĆ, NEGATYWNOŚĆ, PREDYKATYWNOŚĆ, ASPEKT)\n') +#### dokonczyc + + outfile.write(u'Łączna liczba schematów:\t%d\n' % stats_path['schemata']) + outfile.write(u'Liczba schematów pewnych:\t%d\n' % stats_path['cer_schemata']) + outfile.write(u'Liczba schematów wątpliwych:\t%d\n' % stats_path['uncer_schemata']) + outfile.write(u'Liczba schematów złych:\t%d\n' % stats_path['bad_schemata']) + outfile.write(u'Liczba schematów archaicznych:\t%d\n' % stats_path['arch_schemata']) + outfile.write(u'Liczba schematów potocznych:\t%d\n' % stats_path['col_schemata']) + outfile.write(u'Liczba schematów wulgarnych:\t%d\n\n' % stats_path['vul_schemata']) - write_all_stats('data/statystyki_2015_06_30_all.txt', all_stats_dict_all) - write_all_stats('data/statystyki_2015_06_30_verified.txt', all_stats_dict_verified) + outfile.write(u'Liczba schematów z koordynacją:\t%d\n' % stats_path['coor_schemata']) + outfile.write(u'Liczba schematów zleksykalizowanych:\t%d\n\n' % stats_path['lex_schemata']) -def write_all_stats(stats_path, stats_dict): - outfile = codecs.open(stats_path, 'wt', 'utf-8') - - outfile.write(u'Liczba argumentów: ' + str(stats_dict['arg_count']) + '\n') - outfile.write(u'Liczba pozycji: ' + str(stats_dict['pos_count']) + '\n') - outfile.write(u'Liczba haseł: ' + str(stats_dict['lemma_count']) + '\n') - outfile.write('\n') - outfile.write(u'Liczba podhaseł: ' + str(stats_dict['sub_lemma_count']) + '\n') - - outfile.write(u'Liczba podhaseł postaci (ZWROTNOŚĆ, NEGATYWNOŚĆ, PREDYKATYWNOŚĆ, ASPEKT)\n') - - outfile.write(u'Liczba podhaseł postaci (się, _, , imperf): ' + str(stats_dict['sub_sie_imperf_oboj']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, _, , perf): ' + str(stats_dict['sub_sie_perf_oboj']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, _, , _): ' + str(stats_dict['sub_sie_oboj_oboj']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , imperf): ' + str(stats_dict['sub_imperf_oboj']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , perf): ' + str(stats_dict['sub_perf_oboj']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , _): ' + str(stats_dict['sub_oboj_oboj']) + '\n') - - outfile.write(u'Liczba podhaseł postaci (się, neg, , imperf): ' + str(stats_dict['sub_sie_imperf_neg']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, neg, , perf): ' + str(stats_dict['sub_sie_perf_neg']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, neg, , _): ' + str(stats_dict['sub_sie_oboj_neg']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , imperf): ' + str(stats_dict['sub_imperf_neg']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , perf): ' + str(stats_dict['sub_perf_neg']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , _): ' + str(stats_dict['sub_oboj_neg']) + '\n') - - outfile.write(u'Liczba podhaseł postaci (się, aff, , imperf): ' + str(stats_dict['sub_sie_imperf_aff']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, aff, , perf): ' + str(stats_dict['sub_sie_perf_aff']) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, aff, , _): ' + str(stats_dict['sub_sie_oboj_aff']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , imperf): ' + str(stats_dict['sub_imperf_aff']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , perf): ' + str(stats_dict['sub_perf_aff']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , _): ' + str(stats_dict['sub_oboj_aff']) + '\n') - - outfile.write(u'Liczba podhaseł postaci ( , , pred, ): ' + str(stats_dict['pred_lemma']) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , , , ): ' + str(stats_dict['npred_lemma']) + '\n') - - outfile.write('\n') - outfile.write(u'Liczba ramek: ' + str(stats_dict['all_frames']) + '\n') - outfile.write(u'Liczba ramek pewnych: ' + str(stats_dict['pewna_frames']) + '\n') - outfile.write(u'Liczba ramek wątpliwych: ' + str(stats_dict['watpliwa_frames']) + '\n') - outfile.write(u'Liczba ramek złych: ' + str(stats_dict['zla_frames']) + '\n') - outfile.write(u'Liczba ramek archaicznych: ' + str(stats_dict['arch_frames']) + '\n') - outfile.write(u'Liczba ramek potocznych: ' + str(stats_dict['potoczna_frames']) + '\n') - outfile.write(u'Liczba ramek wulgarnych: ' + str(stats_dict['wulgarna_frames']) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą argumentów: ' + str(stats_dict['spec_pos']) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie argumentów: ' + str(stats_dict['spec_args']) + '\n') - outfile.write(u'Liczba ramek z pozycjami wieloargumentowymi: ' + str(stats_dict['spec_frames']) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą specyfikacji: ' + str(stats_dict['spec_pos_up']) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie specyfikacji: ' + str(stats_dict['spec_args_up']) + '\n') - outfile.write(u'Liczba ramek z pozycjami o większej niż jeden liczbie specyfikacji: ' + str(stats_dict['spec_frames_up']) + '\n') - outfile.write(u'Liczba ramek frazeologicznych: ' + str(stats_dict['frames_with_phraseology']) + '\n') - outfile.write('\n') - outfile.write(u'Hasła zawierające schematy frazeologiczne: ' + str(stats_dict['lemmas_with_phraseology']) + '\n') - outfile.write(u'Hasła zawierające pozycje z koordynacją: ' + str(stats_dict['lemmas_with_coordination']) + '\n') - - outfile.close() - -def get_adjs_stats(stats_path, q_statuses): - print 'Be patient, it can take a while.' - outfile = codecs.open(stats_path, 'wt', 'utf-8') - arg_count = 0 - pos_count = 0 - lemma_count = 0 -######################## - sub_lemma_count = 0 - - pred_lemma = 0 - npred_lemma = 0 -################## - pewna_frames = 0 - watpliwa_frames = 0 - zla_frames = 0 - arch_frames = 0 - potoczna_frames = 0 - wulgarna_frames = 0 - all_frames = 0 - - spec_frames = 0 - spec_pos = 0 - spec_args = 0 - - spec_frames_up = 0 - spec_pos_up = 0 - spec_args_up = 0 - - lemmas_with_phraseology = 0 - lemmas_with_coordination = 0 - - frames_with_phraseology = 0 - - lemmas = Lemma.objects.filter(old=False, - entry_obj__pos__tag='adj').filter(reduce(operator.or_, q_statuses)).distinct().order_by('entry').all() - for lemma in lemmas: - print lemma - lemma_count += 1 + outfile.write(u'Hasła zawierające pozycje z koordynacją:\t%d\n' % stats_path['coor_lemmas']) + outfile.write(u'Hasła zawierające schematy zleksykalizowane:\t%d\n\n' % stats_path['lex_lemmas']) - pewna_frames += lemma.frame_opinions.filter(value__value=u'pewny').count() - watpliwa_frames += lemma.frame_opinions.filter(value__value=u'wątpliwy').count() - zla_frames += lemma.frame_opinions.filter(value__value=u'zły').count() - arch_frames += lemma.frame_opinions.filter(value__value=u'archaiczny').count() - potoczna_frames += lemma.frame_opinions.filter(value__value=u'potoczny').count() - wulgarna_frames += lemma.frame_opinions.filter(value__value=u'wulgarny').count() - all_frames += lemma.frames.count() -# if (lemma.frames.count() != lemma.frame_opinions.filter(value__value=u'pewna').count() + -# lemma.frame_opinions.filter(value__value=u'wątpliwa').count() + -# lemma.frame_opinions.filter(value__value=u'zła').count() + -# lemma.frame_opinions.filter(value__value=u'archaiczna').count() + -# lemma.frame_opinions.filter(value__value=u'potoczna').count() + -# lemma.frame_opinions.filter(value__value=u'wulgarna').count()): -# print lemma -# print lemma.frame_opinions.filter(value__value=u'pewna').count() -# print lemma.frame_opinions.filter(value__value=u'wątpliwa').count() -# print lemma.frame_opinions.filter(value__value=u'zła').count() -# print lemma.frame_opinions.filter(value__value=u'archaiczna').count() -# print lemma.frame_opinions.filter(value__value=u'potoczna').count() -# print lemma.frame_opinions.filter(value__value=u'wulgarna').count() -## break - -################################################################################ - - sub_frame = lemma.frames.filter(characteristics__value__value=u'pred', - characteristics__type=u'PREDYKATYWNOŚĆ') - if sub_frame.count() > 0: - pred_lemma += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'PREDYKATYWNOŚĆ') - if sub_frame.count() > 0: - npred_lemma += 1 - sub_lemma_count += 1 - -################################################################################# - - if lemma.frames.count() != lemma.frame_opinions.count(): - print lemma.entry - - has_phraseology = False - has_coordination = False - for frame in lemma.frames.all(): - phraseologic_frame = False - - pos_count += frame.positions.count() - flat_frames = frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'] - - if flat_frames > 1: - spec_frames += 1 - has_coordination = True - if frame.has_phraseologic_arguments(): - has_phraseology = True - phraseologic_frame = True - - for pos in frame.positions.all(): - args = pos.arguments.count() - arg_count += args -# for arg in pos.arguments.all(): -# if arg.type in PHRASEOLOGIC_TYPES: -# has_phraseology = True -# phraseologic_frame = True -# break - if phraseologic_frame: - frames_with_phraseology += 1 - - if has_phraseology: - lemmas_with_phraseology += 1 - if has_coordination: - lemmas_with_coordination += 1 -# if args > 1: -# spec_pos += 1 -# spec_args += args -# -# prep_args = pos.arguments.filter(Q(type=u'prepnp') | -# Q(type=u'prepncp')) -# np_args = pos.arguments.filter(Q(type=u'np') | -# Q(type=u'ncp')) -# similar_args = True -# if prep_args.count() == args: -# first_arg_case = prep_args.all()[0].atributes.get(type=u'PRZYPADEK').atribute_value.value -# first_arg_prep = prep_args.all()[0].atributes.get(type=u'PRZYIMEK').atribute_value.value -# for arg in prep_args: -# if (first_arg_case != arg.atributes.get(type=u'PRZYPADEK').atribute_value.value or -# first_arg_prep != arg.atributes.get(type=u'PRZYIMEK').atribute_value.value): -# similar_args = False -# break -# elif np_args.count() == args: -# first_arg_case = np_args.all()[0].atributes.get(type=u'PRZYPADEK').atribute_value.value -# for arg in np_args: -# if (first_arg_case != arg.atributes.get(type=u'PRZYPADEK').atribute_value.value): -# similar_args = False -# break -# else: -# similar_args = False -# if not similar_args and args > 1: -# spec_pos_up += 1 -# spec_args_up += args -# add_spec_frame_up = True -# if add_spec_frame_up: -# spec_frames_up += 1 - - outfile.write(u'Liczba argumentów: ' + str(arg_count) + '\n') - outfile.write(u'Liczba pozycji: ' + str(pos_count) + '\n') - outfile.write(u'Liczba haseł: ' + str(lemma_count) + '\n') - outfile.write('\n') - outfile.write(u'Liczba podhaseł: ' + str(sub_lemma_count) + '\n') - outfile.write(u'Liczba podhaseł postaci (ZWROTNOŚĆ, NEGATYWNOŚĆ, PREDYKATYWNOŚĆ, ASPEKT)\n') - outfile.write(u'Liczba podhaseł postaci ( , , pred, ): ' + str(pred_lemma) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , , , ): ' + str(npred_lemma) + '\n') - outfile.write('\n') - outfile.write(u'Liczba ramek: ' + str(all_frames) + '\n') - outfile.write(u'Liczba ramek pewnych: ' + str(pewna_frames) + '\n') - outfile.write(u'Liczba ramek wątpliwych: ' + str(watpliwa_frames) + '\n') - outfile.write(u'Liczba ramek złych: ' + str(zla_frames) + '\n') - outfile.write(u'Liczba ramek archaicznych: ' + str(arch_frames) + '\n') - outfile.write(u'Liczba ramek potocznych: ' + str(potoczna_frames) + '\n') - outfile.write(u'Liczba ramek wulgarnych: ' + str(wulgarna_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą argumentów: ' + str(spec_pos) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie argumentów: ' + str(spec_args) + '\n') - outfile.write(u'Liczba ramek z pozycjami wieloargumentowymi: ' + str(spec_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą specyfikacji: ' + str(spec_pos_up) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie specyfikacji: ' + str(spec_args_up) + '\n') - outfile.write(u'Liczba ramek z pozycjami o większej niż jeden liczbie specyfikacji: ' + str(spec_frames_up) + '\n') - outfile.write(u'Liczba ramek frazeologicznych: ' + str(frames_with_phraseology) + '\n') - outfile.write('\n') - outfile.write(u'Hasła zawierające schematy frazeologiczne: ' + str(lemmas_with_phraseology) + '\n') - outfile.write(u'Hasła zawierające pozycje z koordynacją: ' + str(lemmas_with_coordination) + '\n') - - - - adjs_stats_dict = {'arg_count': arg_count, - 'pos_count': pos_count, - 'lemma_count': lemma_count, - - 'sub_lemma_count': sub_lemma_count, - - 'pred_lemma': pred_lemma, - 'npred_lemma': npred_lemma, - - 'all_frames': all_frames, - 'pewna_frames': pewna_frames, - 'watpliwa_frames': watpliwa_frames, - 'zla_frames': zla_frames, - 'arch_frames': arch_frames, - 'potoczna_frames': potoczna_frames, - 'wulgarna_frames': wulgarna_frames, - - 'spec_pos': spec_pos, - 'spec_args': spec_args, - 'spec_frames': spec_frames, - - 'spec_pos_up': spec_pos_up, - 'spec_args_up': spec_args_up, - 'spec_frames_up': spec_frames_up, - 'frames_with_phraseology': frames_with_phraseology, - - 'lemmas_with_phraseology': lemmas_with_phraseology, - 'lemmas_with_coordination': lemmas_with_coordination - } - - outfile.close() - return adjs_stats_dict - -def get_nouns_stats(stats_path, q_statuses): - print 'Be patient, it can take a while.' - outfile = codecs.open(stats_path, 'wt', 'utf-8') - arg_count = 0 - pos_count = 0 - lemma_count = 0 - -################## - pewna_frames = 0 - watpliwa_frames = 0 - zla_frames = 0 - arch_frames = 0 - potoczna_frames = 0 - wulgarna_frames = 0 - all_frames = 0 - - spec_frames = 0 - spec_pos = 0 - spec_args = 0 - - spec_frames_up = 0 - spec_pos_up = 0 - spec_args_up = 0 - - lemmas_with_phraseology = 0 - lemmas_with_coordination = 0 - - frames_with_phraseology = 0 + except: + outfile.close() + +def get_stats(statuses, pos): + stats_dict = Counter({u'phrases': 0, + u'poss': 0, + u'lemmas': 0, + u'sub_lemmas': 0, + u'schemata': 0, + u'cer_schemata': 0, + u'uncer_schemata': 0, + u'bad_schemata': 0, + u'arch_schemata': 0, + u'col_schemata': 0, + u'vul_schemata': 0, + u'coor_schemata': 0, + u'lex_schemata': 0, + u'coor_lemmas': 0, + u'lex_lemmas': 0}) lemmas = Lemma.objects.filter(old=False, - entry_obj__pos__tag='noun').filter(reduce(operator.or_, q_statuses)).distinct().order_by('entry').all() - for lemma in lemmas: + entry_obj__pos__tag=pos).filter(status__in=statuses).distinct() + for lemma in lemmas.order_by('entry').all(): print lemma - lemma_count += 1 - - pewna_frames += lemma.frame_opinions.filter(value__value=u'pewny').count() - watpliwa_frames += lemma.frame_opinions.filter(value__value=u'wątpliwy').count() - zla_frames += lemma.frame_opinions.filter(value__value=u'zły').count() - arch_frames += lemma.frame_opinions.filter(value__value=u'archaiczny').count() - potoczna_frames += lemma.frame_opinions.filter(value__value=u'potoczny').count() - wulgarna_frames += lemma.frame_opinions.filter(value__value=u'wulgarny').count() - all_frames += lemma.frames.count() -# if (lemma.frames.count() != lemma.frame_opinions.filter(value__value=u'pewna').count() + -# lemma.frame_opinions.filter(value__value=u'wątpliwa').count() + -# lemma.frame_opinions.filter(value__value=u'zła').count() + -# lemma.frame_opinions.filter(value__value=u'archaiczna').count() + -# lemma.frame_opinions.filter(value__value=u'potoczna').count() + -# lemma.frame_opinions.filter(value__value=u'wulgarna').count()): -# print lemma -# print lemma.frame_opinions.filter(value__value=u'pewna').count() -# print lemma.frame_opinions.filter(value__value=u'wątpliwa').count() -# print lemma.frame_opinions.filter(value__value=u'zła').count() -# print lemma.frame_opinions.filter(value__value=u'archaiczna').count() -# print lemma.frame_opinions.filter(value__value=u'potoczna').count() -# print lemma.frame_opinions.filter(value__value=u'wulgarna').count() -## break - - if lemma.frames.count() != lemma.frame_opinions.count(): - print lemma.entry - + stats_dict[u'lemmas'] += 1 + stats_dict[u'cer_schemata'] += lemma.frame_opinions.filter(value__value=u'pewny').count() + stats_dict[u'uncer_schemata'] += lemma.frame_opinions.filter(value__value=u'wątpliwy').count() + stats_dict[u'bad_schemata'] += lemma.frame_opinions.filter(value__value=u'zły').count() + stats_dict[u'arch_schemata'] += lemma.frame_opinions.filter(value__value=u'archaiczny').count() + stats_dict[u'col_schemata'] += lemma.frame_opinions.filter(value__value=u'potoczny').count() + stats_dict[u'vul_schemata'] += lemma.frame_opinions.filter(value__value=u'wulgarny').count() + stats_dict[u'schemata'] += lemma.frames.count() + + stats_dict = stats_dict + Counter(get_sub_entries_dict(lemma)) + has_phraseology = False has_coordination = False for frame in lemma.frames.all(): - phraseologic_frame = False - - pos_count += frame.positions.count() + stats_dict[u'poss'] += frame.positions.count() flat_frames = frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'] - if flat_frames > 1: - spec_frames += 1 + stats_dict[u'coor_schemata'] += 1 has_coordination = True - if frame.has_phraseologic_arguments(): - has_phraseology = True - phraseologic_frame = True - for pos in frame.positions.all(): - args = pos.arguments.count() - arg_count += args -# for arg in pos.arguments.all(): -# if arg.type in PHRASEOLOGIC_TYPES: -# has_phraseology = True -# phraseologic_frame = True -# break - if phraseologic_frame: - frames_with_phraseology += 1 - - if has_phraseology: - lemmas_with_phraseology += 1 - if has_coordination: - lemmas_with_coordination += 1 - - outfile.write(u'Liczba argumentów: ' + str(arg_count) + '\n') - outfile.write(u'Liczba pozycji: ' + str(pos_count) + '\n') - outfile.write(u'Liczba haseł: ' + str(lemma_count) + '\n') - outfile.write('\n') - - outfile.write('\n') - outfile.write(u'Liczba ramek: ' + str(all_frames) + '\n') - outfile.write(u'Liczba ramek pewnych: ' + str(pewna_frames) + '\n') - outfile.write(u'Liczba ramek wątpliwych: ' + str(watpliwa_frames) + '\n') - outfile.write(u'Liczba ramek złych: ' + str(zla_frames) + '\n') - outfile.write(u'Liczba ramek archaicznych: ' + str(arch_frames) + '\n') - outfile.write(u'Liczba ramek potocznych: ' + str(potoczna_frames) + '\n') - outfile.write(u'Liczba ramek wulgarnych: ' + str(wulgarna_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą argumentów: ' + str(spec_pos) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie argumentów: ' + str(spec_args) + '\n') - outfile.write(u'Liczba ramek z pozycjami wieloargumentowymi: ' + str(spec_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą specyfikacji: ' + str(spec_pos_up) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie specyfikacji: ' + str(spec_args_up) + '\n') - outfile.write(u'Liczba ramek z pozycjami o większej niż jeden liczbie specyfikacji: ' + str(spec_frames_up) + '\n') - outfile.write(u'Liczba ramek frazeologicznych: ' + str(frames_with_phraseology) + '\n') - outfile.write('\n') - outfile.write(u'Hasła zawierające schematy frazeologiczne: ' + str(lemmas_with_phraseology) + '\n') - outfile.write(u'Hasła zawierające pozycje z koordynacją: ' + str(lemmas_with_coordination) + '\n') - - noun_stats_dict = {'arg_count': arg_count, - 'pos_count': pos_count, - 'lemma_count': lemma_count, - - 'sub_lemma_count': lemma_count, - - 'npred_lemma': lemma_count, - - 'all_frames': all_frames, - 'pewna_frames': pewna_frames, - 'watpliwa_frames': watpliwa_frames, - 'zla_frames': zla_frames, - 'arch_frames': arch_frames, - 'potoczna_frames': potoczna_frames, - 'wulgarna_frames': wulgarna_frames, - - 'spec_pos': spec_pos, - 'spec_args': spec_args, - 'spec_frames': spec_frames, - - 'spec_pos_up': spec_pos_up, - 'spec_args_up': spec_args_up, - 'spec_frames_up': spec_frames_up, - 'frames_with_phraseology': frames_with_phraseology, - - 'lemmas_with_phraseology': lemmas_with_phraseology, - 'lemmas_with_coordination': lemmas_with_coordination - } - - outfile.close() - return noun_stats_dict - -def get_advs_stats(stats_path, q_statuses): - print 'Be patient, it can take a while.' - outfile = codecs.open(stats_path, 'wt', 'utf-8') - arg_count = 0 - pos_count = 0 - lemma_count = 0 - -################## - pewna_frames = 0 - watpliwa_frames = 0 - zla_frames = 0 - arch_frames = 0 - potoczna_frames = 0 - wulgarna_frames = 0 - all_frames = 0 - - spec_frames = 0 - spec_pos = 0 - spec_args = 0 - - spec_frames_up = 0 - spec_pos_up = 0 - spec_args_up = 0 - - lemmas_with_phraseology = 0 - lemmas_with_coordination = 0 - - frames_with_phraseology = 0 - - lemmas = Lemma.objects.filter(old=False, - entry_obj__pos__tag='adv').filter(reduce(operator.or_, q_statuses)).distinct().order_by('entry').all() - for lemma in lemmas: - print lemma - lemma_count += 1 - - pewna_frames += lemma.frame_opinions.filter(value__value=u'pewny').count() - watpliwa_frames += lemma.frame_opinions.filter(value__value=u'wątpliwy').count() - zla_frames += lemma.frame_opinions.filter(value__value=u'zły').count() - arch_frames += lemma.frame_opinions.filter(value__value=u'archaiczny').count() - potoczna_frames += lemma.frame_opinions.filter(value__value=u'potoczny').count() - wulgarna_frames += lemma.frame_opinions.filter(value__value=u'wulgarny').count() - all_frames += lemma.frames.count() -# if (lemma.frames.count() != lemma.frame_opinions.filter(value__value=u'pewna').count() + -# lemma.frame_opinions.filter(value__value=u'wątpliwa').count() + -# lemma.frame_opinions.filter(value__value=u'zła').count() + -# lemma.frame_opinions.filter(value__value=u'archaiczna').count() + -# lemma.frame_opinions.filter(value__value=u'potoczna').count() + -# lemma.frame_opinions.filter(value__value=u'wulgarna').count()): -# print lemma -# print lemma.frame_opinions.filter(value__value=u'pewna').count() -# print lemma.frame_opinions.filter(value__value=u'wątpliwa').count() -# print lemma.frame_opinions.filter(value__value=u'zła').count() -# print lemma.frame_opinions.filter(value__value=u'archaiczna').count() -# print lemma.frame_opinions.filter(value__value=u'potoczna').count() -# print lemma.frame_opinions.filter(value__value=u'wulgarna').count() -## break - - if lemma.frames.count() != lemma.frame_opinions.count(): - print lemma.entry - - has_phraseology = False - has_coordination = False - for frame in lemma.frames.all(): - phraseologic_frame = False - - pos_count += frame.positions.count() - flat_frames = frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'] - - if flat_frames > 1: - spec_frames += 1 - has_coordination = True - if frame.has_phraseologic_arguments(): + stats_dict[u'phrases'] += pos.arguments.count() + if frame.positions.filter(arguments__type__in=LEX_TYPES).exists(): + stats_dict[u'lex_schemata'] += 1 has_phraseology = True - phraseologic_frame = True - - for pos in frame.positions.all(): - args = pos.arguments.count() - arg_count += args -# for arg in pos.arguments.all(): -# if arg.type in PHRASEOLOGIC_TYPES: -# has_phraseology = True -# phraseologic_frame = True -# break - if phraseologic_frame: - frames_with_phraseology += 1 if has_phraseology: - lemmas_with_phraseology += 1 + stats_dict[u'lex_lemmas'] += 1 if has_coordination: - lemmas_with_coordination += 1 - - outfile.write(u'Liczba argumentów: ' + str(arg_count) + '\n') - outfile.write(u'Liczba pozycji: ' + str(pos_count) + '\n') - outfile.write(u'Liczba haseł: ' + str(lemma_count) + '\n') - outfile.write('\n') - - outfile.write('\n') - outfile.write(u'Liczba ramek: ' + str(all_frames) + '\n') - outfile.write(u'Liczba ramek pewnych: ' + str(pewna_frames) + '\n') - outfile.write(u'Liczba ramek wątpliwych: ' + str(watpliwa_frames) + '\n') - outfile.write(u'Liczba ramek złych: ' + str(zla_frames) + '\n') - outfile.write(u'Liczba ramek archaicznych: ' + str(arch_frames) + '\n') - outfile.write(u'Liczba ramek potocznych: ' + str(potoczna_frames) + '\n') - outfile.write(u'Liczba ramek wulgarnych: ' + str(wulgarna_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą argumentów: ' + str(spec_pos) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie argumentów: ' + str(spec_args) + '\n') - outfile.write(u'Liczba ramek z pozycjami wieloargumentowymi: ' + str(spec_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą specyfikacji: ' + str(spec_pos_up) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie specyfikacji: ' + str(spec_args_up) + '\n') - outfile.write(u'Liczba ramek z pozycjami o większej niż jeden liczbie specyfikacji: ' + str(spec_frames_up) + '\n') - outfile.write(u'Liczba ramek frazeologicznych: ' + str(frames_with_phraseology) + '\n') - outfile.write('\n') - outfile.write(u'Hasła zawierające schematy frazeologiczne: ' + str(lemmas_with_phraseology) + '\n') - outfile.write(u'Hasła zawierające pozycje z koordynacją: ' + str(lemmas_with_coordination) + '\n') - - advs_stats_dict = {'arg_count': arg_count, - 'pos_count': pos_count, - 'lemma_count': lemma_count, - - 'sub_lemma_count': lemma_count, - - 'npred_lemma': lemma_count, - - 'all_frames': all_frames, - 'pewna_frames': pewna_frames, - 'watpliwa_frames': watpliwa_frames, - 'zla_frames': zla_frames, - 'arch_frames': arch_frames, - 'potoczna_frames': potoczna_frames, - 'wulgarna_frames': wulgarna_frames, - - 'spec_pos': spec_pos, - 'spec_args': spec_args, - 'spec_frames': spec_frames, - - 'spec_pos_up': spec_pos_up, - 'spec_args_up': spec_args_up, - 'spec_frames_up': spec_frames_up, - 'frames_with_phraseology': frames_with_phraseology, - - 'lemmas_with_phraseology': lemmas_with_phraseology, - 'lemmas_with_coordination': lemmas_with_coordination - } - - outfile.close() - return advs_stats_dict - -def get_verb_stats(stats_path, q_statuses): - print 'Be patient, it can take a while.' - outfile = codecs.open(stats_path, 'wt', 'utf-8') - arg_count = 0 - pos_count = 0 - lemma_count = 0 -##################3 - sub_lemma_count = 0 - - sub_sie_imperf_oboj = 0 - sub_sie_perf_oboj = 0 - sub_sie_oboj_oboj = 0 - sub_imperf_oboj = 0 - sub_perf_oboj = 0 - sub_oboj_oboj = 0 - - sub_sie_imperf_neg = 0 - sub_sie_perf_neg = 0 - sub_sie_oboj_neg = 0 - sub_imperf_neg = 0 - sub_perf_neg = 0 - sub_oboj_neg = 0 - - sub_sie_imperf_aff = 0 - sub_sie_perf_aff = 0 - sub_sie_oboj_aff = 0 - sub_imperf_aff = 0 - sub_perf_aff = 0 - sub_oboj_aff = 0 - - sie_lemma = 0 - nsie_lemma = 0 -################## - pewna_frames = 0 - watpliwa_frames = 0 - zla_frames = 0 - arch_frames = 0 - potoczna_frames = 0 - wulgarna_frames = 0 - all_frames = 0 - - spec_frames = 0 - spec_pos = 0 - spec_args = 0 - - spec_frames_up = 0 - spec_pos_up = 0 - spec_args_up = 0 - - lemmas_with_phraseology = 0 - lemmas_with_coordination = 0 - - frames_with_phraseology = 0 - - lemmas = Lemma.objects.filter(old=False, - entry_obj__pos__tag='verb').filter(reduce(operator.or_, q_statuses)).distinct().order_by('entry').all() - for lemma in lemmas: - # jak chcemy bez zapłaconych -# if RealizedLemma.objects.filter(Q(status__status=u'sprawdzone') | -# Q(status__status=u'tymczasowy')).filter(lemma__entry=lemma.entry, -# paid=False).exists(): -# pass -# else: -# continue - print lemma - lemma_count += 1 - - pewna_frames += lemma.frame_opinions.filter(value__value=u'pewny').count() - watpliwa_frames += lemma.frame_opinions.filter(value__value=u'wątpliwy').count() - zla_frames += lemma.frame_opinions.filter(value__value=u'zły').count() - arch_frames += lemma.frame_opinions.filter(value__value=u'archaiczny').count() - potoczna_frames += lemma.frame_opinions.filter(value__value=u'potoczny').count() - wulgarna_frames += lemma.frame_opinions.filter(value__value=u'wulgarny').count() - all_frames += lemma.frames.count() -# if (lemma.frames.count() != lemma.frame_opinions.filter(value__value=u'pewna').count() + -# lemma.frame_opinions.filter(value__value=u'wątpliwa').count() + -# lemma.frame_opinions.filter(value__value=u'zła').count() + -# lemma.frame_opinions.filter(value__value=u'archaiczna').count() + -# lemma.frame_opinions.filter(value__value=u'potoczna').count() + -# lemma.frame_opinions.filter(value__value=u'wulgarna').count()): -# print lemma -# print lemma.frame_opinions.filter(value__value=u'pewna').count() -# print lemma.frame_opinions.filter(value__value=u'wątpliwa').count() -# print lemma.frame_opinions.filter(value__value=u'zła').count() -# print lemma.frame_opinions.filter(value__value=u'archaiczna').count() -# print lemma.frame_opinions.filter(value__value=u'potoczna').count() -# print lemma.frame_opinions.filter(value__value=u'wulgarna').count() -## break - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_sie_imperf_oboj += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_sie_perf_oboj += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_sie_oboj_oboj += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_imperf_oboj += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_perf_oboj += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'_') - if sub_frame.count() > 0: - sub_oboj_oboj += 1 - sub_lemma_count += 1 - -################################### neg ######################################### - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_sie_imperf_neg += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_sie_perf_neg += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_sie_oboj_neg += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_imperf_neg += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_perf_neg += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'neg') - if sub_frame.count() > 0: - sub_oboj_neg += 1 - sub_lemma_count += 1 - -#################################### aff ######################################## - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_sie_imperf_aff += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_sie_perf_aff += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_sie_oboj_aff += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'imperf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_imperf_aff += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'perf').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_perf_aff += 1 - sub_lemma_count += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ').filter(characteristics__type=u'ASPEKT', - characteristics__value__value=u'_').filter( - characteristics__type=u'NEGATYWNOŚĆ', - characteristics__value__value=u'aff') - if sub_frame.count() > 0: - sub_oboj_aff += 1 - sub_lemma_count += 1 -################################################################################ - - sub_frame = lemma.frames.filter(characteristics__value__value=u'się', - characteristics__type=u'ZWROTNOŚĆ') - if sub_frame.count() > 0: - sie_lemma += 1 - - sub_frame = lemma.frames.filter(characteristics__value__value=u'', - characteristics__type=u'ZWROTNOŚĆ') - if sub_frame.count() > 0: - nsie_lemma += 1 - - -################################################################################# - - if lemma.frames.count() != lemma.frame_opinions.count(): - print lemma.entry - - has_phraseology = False - has_coordination = False - for frame in lemma.frames.all(): - phraseologic_frame = False - - pos_count += frame.positions.count() - flat_frames = frame.positions.annotate(num_args=Count('arguments')).aggregate(Max('num_args'))['num_args__max'] - - if flat_frames > 1: - spec_frames += 1 - has_coordination = True - if frame.has_phraseologic_arguments(): - has_phraseology = True - phraseologic_frame = True - - for pos in frame.positions.all(): - args = pos.arguments.count() - arg_count += args -# for arg in pos.arguments.all(): -# if arg.type in PHRASEOLOGIC_TYPES: -# has_phraseology = True -# phraseologic_frame = True -# break - if phraseologic_frame: - frames_with_phraseology += 1 + stats_dict[u'coor_lemmas'] += 1 + + return stats_dict + +def get_sub_entries_dict(lemma): + sub_entries_dict = {} + frame_chars_dict = sorted_frame_char_values_dict() + for reflex in frame_chars_dict['sorted_reflex_vals']: + for neg in frame_chars_dict['sorted_neg_vals']: + for pred in frame_chars_dict['sorted_pred_vals']: + for aspect in frame_chars_dict['sorted_aspect_vals']: + matching_frames = lemma.get_frames_by_char_values(reflex_val=reflex, + neg_val=neg, + pred_val=pred, + aspect_val=aspect) + if matching_frames.exists(): + if not u'sub_lemmas' in sub_entries_dict: + sub_entries_dict[u'sub_lemmas'] = 0 + sub_entries_dict[u'sub_lemmas'] += 1 - if has_phraseology: - lemmas_with_phraseology += 1 - if has_coordination: - lemmas_with_coordination += 1 - - outfile.write(u'Liczba argumentów: ' + str(arg_count) + '\n') - outfile.write(u'Liczba pozycji: ' + str(pos_count) + '\n') - outfile.write(u'Liczba haseł: ' + str(lemma_count) + '\n') - outfile.write('\n') - outfile.write(u'Liczba podhaseł: ' + str(sub_lemma_count) + '\n') - - outfile.write(u'Liczba podhaseł postaci (ZWROTNOŚĆ, NEGATYWNOŚĆ, PREDYKATYWNOŚĆ, ASPEKT)\n') - - outfile.write(u'Liczba podhaseł postaci (się, _, , imperf): ' + str(sub_sie_imperf_oboj) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, _, , perf): ' + str(sub_sie_perf_oboj) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, _, , _): ' + str(sub_sie_oboj_oboj) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , imperf): ' + str(sub_imperf_oboj) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , perf): ' + str(sub_perf_oboj) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , _, , _): ' + str(sub_oboj_oboj) + '\n') - - outfile.write(u'Liczba podhaseł postaci (się, neg, , imperf): ' + str(sub_sie_imperf_neg) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, neg, , perf): ' + str(sub_sie_perf_neg) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, neg, , _): ' + str(sub_sie_oboj_neg) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , imperf): ' + str(sub_imperf_neg) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , perf): ' + str(sub_perf_neg) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , neg, , _): ' + str(sub_oboj_neg) + '\n') - - outfile.write(u'Liczba podhaseł postaci (się, aff, , imperf): ' + str(sub_sie_imperf_aff) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, aff, , perf): ' + str(sub_sie_perf_aff) + '\n') - outfile.write(u'Liczba podhaseł postaci (się, aff, , _): ' + str(sub_sie_oboj_aff) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , imperf): ' + str(sub_imperf_aff) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , perf): ' + str(sub_perf_aff) + '\n') - outfile.write(u'Liczba podhaseł postaci ( , aff, , _): ' + str(sub_oboj_aff) + '\n') - - outfile.write('\n') - outfile.write(u'Liczba ramek: ' + str(all_frames) + '\n') - outfile.write(u'Liczba ramek pewnych: ' + str(pewna_frames) + '\n') - outfile.write(u'Liczba ramek wątpliwych: ' + str(watpliwa_frames) + '\n') - outfile.write(u'Liczba ramek złych: ' + str(zla_frames) + '\n') - outfile.write(u'Liczba ramek archaicznych: ' + str(arch_frames) + '\n') - outfile.write(u'Liczba ramek potocznych: ' + str(potoczna_frames) + '\n') - outfile.write(u'Liczba ramek wulgarnych: ' + str(wulgarna_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą argumentów: ' + str(spec_pos) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie argumentów: ' + str(spec_args) + '\n') - outfile.write(u'Liczba ramek z pozycjami wieloargumentowymi: ' + str(spec_frames) + '\n') - outfile.write('\n') - outfile.write(u'Liczba pozycji z większą niż jeden liczbą specyfikacji: ' + str(spec_pos_up) + '\n') - outfile.write(u'Liczba argumentów występujących w pozycjach o większej niż jeden liczbie specyfikacji: ' + str(spec_args_up) + '\n') - outfile.write(u'Liczba ramek z pozycjami o większej niż jeden liczbie specyfikacji: ' + str(spec_frames_up) + '\n') - outfile.write(u'Liczba ramek frazeologicznych: ' + str(frames_with_phraseology) + '\n') - outfile.write('\n') - outfile.write(u'Hasła zawierające schematy frazeologiczne: ' + str(lemmas_with_phraseology) + '\n') - outfile.write(u'Hasła zawierające pozycje z koordynacją: ' + str(lemmas_with_coordination) + '\n') - - - verb_stats_dict = {'arg_count': arg_count, - 'pos_count': pos_count, - 'lemma_count': lemma_count, - - 'sub_lemma_count': sub_lemma_count, - - 'sub_sie_imperf_oboj': sub_sie_imperf_oboj, - 'sub_sie_perf_oboj': sub_sie_perf_oboj, - 'sub_sie_oboj_oboj': sub_sie_oboj_oboj, - 'sub_imperf_oboj': sub_imperf_oboj, - 'sub_perf_oboj': sub_perf_oboj, - 'sub_oboj_oboj': sub_oboj_oboj, - - 'sub_sie_imperf_neg': sub_sie_imperf_neg, - 'sub_sie_perf_neg': sub_sie_perf_neg, - 'sub_sie_oboj_neg': sub_sie_oboj_neg, - 'sub_imperf_neg': sub_imperf_neg, - 'sub_perf_neg': sub_perf_neg, - 'sub_oboj_neg': sub_oboj_neg, - - 'sub_sie_imperf_aff': sub_sie_imperf_aff, - 'sub_sie_perf_aff': sub_sie_perf_aff, - 'sub_sie_oboj_aff': sub_sie_oboj_aff, - 'sub_imperf_aff': sub_imperf_aff, - 'sub_perf_aff': sub_perf_aff, - 'sub_oboj_aff': sub_oboj_aff, - - 'all_frames': all_frames, - 'pewna_frames': pewna_frames, - 'watpliwa_frames': watpliwa_frames, - 'zla_frames': zla_frames, - 'arch_frames': arch_frames, - 'potoczna_frames': potoczna_frames, - 'wulgarna_frames': wulgarna_frames, - - 'spec_pos': spec_pos, - 'spec_args': spec_args, - 'spec_frames': spec_frames, - - 'spec_pos_up': spec_pos_up, - 'spec_args_up': spec_args_up, - 'spec_frames_up': spec_frames_up, - 'frames_with_phraseology': frames_with_phraseology, - - 'lemmas_with_phraseology': lemmas_with_phraseology, - 'lemmas_with_coordination': lemmas_with_coordination - } - - outfile.close() - return verb_stats_dict - \ No newline at end of file + subentry_key = u'Liczba podhaseł postaci: (%s,%s,%s,%s)' % (reflex.value, neg.value, + pred.value, aspect.value) + if not subentry_key in sub_entries_dict: + sub_entries_dict[subentry_key] = 0 + sub_entries_dict[subentry_key] += 1 + return sub_entries_dict diff --git a/dictionary/models.py b/dictionary/models.py index 0cee531..6b02f66 100644 --- a/dictionary/models.py +++ b/dictionary/models.py @@ -107,6 +107,14 @@ class Lemma_Status(Model): ('see_stats', u'Może oglądać swoje statystyki.'), ('see_all_stats', u'Może oglądać statystyki wszystkich.'), ) + +def get_checked_statuses(): + checked_type = LemmaStatusType.objects.get(sym_name='checked') + return Lemma_Status.objects.filter(type__priority__gte=checked_type.priority).distinct() + +def get_ready_statuses(): + ready_type = LemmaStatusType.objects.get(sym_name='ready') + return Lemma_Status.objects.filter(type__priority__gte=ready_type.priority).distinct() class LemmaStatusType(Model): -- libgit2 0.22.2