Commit 0c1adb0e17ef35263236fe076a4984bd5a6a74ab

Authored by Tomasz Bartosiak
2 parents e9aff2d8 7c0a7888

Merge branch 'master' into tomek

1 1 Slowal, a web tool designed for creating, editing and browsing valence dictionaries.
2 2 http://zil.ipipan.waw.pl/Slowal
3 3  
4   -Copyright (c) 2012-2016 by Institute of Computer Science, Polish Academy of Sciences (IPI PAN)
  4 +Copyright (c) 2012-2018 by Institute of Computer Science, Polish Academy of Sciences (IPI PAN)
5 5 All rights reserved.
6 6  
7 7 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
... ...
dictionary/ajax_vocabulary_management.py
... ... @@ -121,7 +121,7 @@ def create_copyrights_str(dictionary_file, frame_opinions_pks,
121 121 license_clause.extend([u"% http://zil.ipipan.waw.pl/Walenty",
122 122 u"%% version: %s" % date.strftime(month + ' %d, %Y'),
123 123 u"%",
124   - u"% © Copyright 2012–2017 by the Institute of Computer Science, Polish",
  124 + u"% © Copyright 2012–2018 by the Institute of Computer Science, Polish",
125 125 u"% Academy of Sciences (IPI PAN)",
126 126 u"%",
127 127 u"% This work is distributed under a CC BY-SA license:",
... ...
dictionary/management/commands/add_new_control_types.py 0 → 100644
  1 +# -*- coding:utf-8 -*-
  2 +
  3 +from django.core.management.base import BaseCommand
  4 +
  5 +from dictionary.models import POS, PositionCategory
  6 +
  7 +
  8 +class Command(BaseCommand):
  9 +
  10 + def handle(self, **options):
  11 + add_new_controll_types()
  12 +
  13 +
  14 +def add_new_controll_types():
  15 + poss = POS.objects.all()
  16 +
  17 + pred_controller, xx = PositionCategory.objects.get_or_create(category='pred_controller',
  18 + control=True,
  19 + priority=70)
  20 + for pos in poss:
  21 + if pos.tag != 'noun':
  22 + pred_controller.poss.add(pos)
  23 +
  24 + pred_controllee, xx = PositionCategory.objects.get_or_create(category='pred_controllee',
  25 + control=True,
  26 + priority=80)
  27 + for pos in poss:
  28 + if pos.tag != 'noun':
  29 + pred_controllee.poss.add(pos)
... ...
dictionary/management/commands/change_control2pred_control.py 0 → 100644
  1 +# -*- coding:utf-8 -*-
  2 +
  3 +from django.contrib.auth.models import User
  4 +from django.core.management.base import BaseCommand
  5 +
  6 +from dictionary.models import Change, Frame, Frame_Opinion, Lemma, Position, PositionCategory, \
  7 + get_or_create_nkjp_arg_selection, get_or_create_nkjp_example, get_ready_statuses, sortArguments, \
  8 + sortFrameChars, sortPosCatsAsStrTab, sortPositions
  9 +from dictionary.saving import create_argument_ref, create_operation, create_phrase_type_ref, \
  10 + reconnect_examples, update_connections
  11 +from semantics.models import LexicalUnitExamples
  12 +
  13 +
  14 +class Command(BaseCommand):
  15 +
  16 + def handle(self, **options):
  17 + self.print_schema4manual_change()
  18 + self.change_control2pred_control()
  19 +
  20 + def print_schema4manual_change(self):
  21 + ready_statuses = get_ready_statuses()
  22 + for lemma in Lemma.objects.filter(old=False, status__in=ready_statuses).order_by('entry_obj__name'):
  23 + for schema in lemma.frames.all():
  24 + for position in schema.positions.all():
  25 + if self.position_need_manual_change(position):
  26 + print (lemma, schema.pk)
  27 + break
  28 +
  29 + def position_need_manual_change(self, position):
  30 + if position.categories.filter(category='controllee').exists():
  31 + for phrase_type in position.arguments.all():
  32 + if self.phrase_type_is_infp(phrase_type):
  33 + return True
  34 + return False
  35 +
  36 + def phrase_type_is_infp(self, phrase_type):
  37 + if (phrase_type.type == 'infp'):
  38 + return True
  39 + if (phrase_type.type == 'lex' and
  40 + phrase_type.atributes.get(type='TYP FRAZY').values.all()[0].argument.type == 'infp'):
  41 + return True
  42 + return False
  43 +
  44 + def change_control2pred_control(self):
  45 + ready_statuses = get_ready_statuses()
  46 + for lemma in Lemma.objects.filter(old=False, status__in=ready_statuses).order_by('entry_obj__name'):
  47 + print (lemma)
  48 + changes = {'schemata': [],
  49 + 'schemata2change': []}
  50 + for schema in lemma.frames.all():
  51 + if self.schema_need_auto_change(schema):
  52 + changes['schemata2change'].append(schema)
  53 + else:
  54 + changes['schemata'].append(schema)
  55 +
  56 + if changes['schemata2change']:
  57 + self.save_new_lemma_version(lemma, changes)
  58 +
  59 + def schema_need_auto_change(self, schema):
  60 + for position in schema.positions.all():
  61 + if self.controllee_need_auto_change(position):
  62 + return True
  63 + return False
  64 +
  65 + def controllee_need_auto_change(self, position):
  66 + auto_change = False
  67 + if position.categories.filter(category__startswith='controllee').exists():
  68 + auto_change = True
  69 + for phrase_type in position.arguments.all():
  70 + if self.phrase_type_is_infp(phrase_type):
  71 + auto_change = False
  72 + return auto_change
  73 +
  74 + def save_new_lemma_version(self, old_lemma, changes):
  75 + admin_user = User.objects.get(username='bniton')
  76 +
  77 + old_lemma.old = True
  78 + old_lemma.save()
  79 +
  80 + # tworzenie nowej wersji hasla
  81 + new_lemma = Lemma(entry=old_lemma.entry_obj.name,
  82 + entry_obj=old_lemma.entry_obj,
  83 + owner=old_lemma.owner,
  84 + phraseologist=old_lemma.phraseologist,
  85 + semanticist=old_lemma.semanticist,
  86 + vocabulary=old_lemma.vocabulary,
  87 + status=old_lemma.status,
  88 + old=False,
  89 + frequency_1M=old_lemma.frequency_1M,
  90 + frequency_300M=old_lemma.frequency_300M)
  91 + new_lemma.save()
  92 +
  93 + # tworzenie zmiany do systemu kontroli zmian
  94 + if (old_lemma.owner):
  95 + lemma_change = Change(user=admin_user, entry=old_lemma, act_owner=old_lemma.owner)
  96 + lemma_change.save()
  97 + else:
  98 + lemma_change = Change(user=admin_user, entry=old_lemma)
  99 + lemma_change.save()
  100 +
  101 + # przepisywanie starych wersji dla kontroli zmian i dodanie nowej
  102 + for version in old_lemma.old_versions.all():
  103 + new_lemma.old_versions.add(version)
  104 + new_lemma.old_versions.add(lemma_change)
  105 +
  106 + # przepisywanie historii zmian statusow
  107 + for status_change in old_lemma.status_history.all():
  108 + new_lemma.status_history.add(status_change)
  109 +
  110 + # przepisywanie wiadomosci
  111 + for message in old_lemma.messages.all():
  112 + new_lemma.messages.add(message)
  113 +
  114 + # przepisywanie starych ramek
  115 + for old_frame in old_lemma.old_frames.all():
  116 + new_lemma.old_frames.add(old_frame)
  117 +
  118 + # przepisywanie ramek skladnicowych
  119 + for skladnica_frame in old_lemma.skladnica_frames.all():
  120 + new_lemma.skladnica_frames.add(skladnica_frame)
  121 +
  122 + # przepisywanie ramek B
  123 + for B_frame in old_lemma.B_frames.all():
  124 + new_lemma.B_frames.add(B_frame)
  125 +
  126 + # przepisywanie opinii o schematach
  127 + for schema_opinion in old_lemma.frame_opinions.all():
  128 + new_lemma.frame_opinions.add(schema_opinion)
  129 +
  130 + # przepisywanie przykladow niepasujacych do zadnego schematu
  131 + for example in old_lemma.lemma_nkjp_examples.all():
  132 + new_lemma.lemma_nkjp_examples.add(example)
  133 +
  134 + # dodawanie niezmienionych schematow
  135 + for schema in changes['schemata']:
  136 + new_lemma.frames.add(schema)
  137 +
  138 + # tworzenie nowych schematow i dolaczanie ich do czasownika
  139 + schemata_conversions = []
  140 + for old_schema in changes['schemata2change']:
  141 + new_schema, positions_changes = self.get_or_create_new_schema(old_schema)
  142 +
  143 + # przepinanie opinii o ramce
  144 + try:
  145 + old_opinion = old_lemma.frame_opinions.get(frame=old_schema)
  146 + opinion_value = old_opinion.value
  147 + new_lemma.frame_opinions.remove(old_opinion)
  148 + try:
  149 + new_opinion = Frame_Opinion.objects.get(frame=new_schema,
  150 + value=opinion_value)
  151 + except Frame_Opinion.DoesNotExist:
  152 + new_opinion = Frame_Opinion(frame=new_schema,
  153 + value=opinion_value)
  154 + new_opinion.save()
  155 + new_lemma.frame_opinions.add(new_opinion)
  156 + except Frame_Opinion.DoesNotExist:
  157 + pass
  158 +
  159 + new_lemma.frames.add(new_schema)
  160 + schemata_conversions.append({'old_schema': old_schema,
  161 + 'new_schema': new_schema,
  162 + 'positions_changes': positions_changes})
  163 +
  164 + # przepisywanie semantyki
  165 + sem_reconnect_operations = self.get_semantic_operations(new_lemma, schemata_conversions)
  166 + update_connections(new_lemma.id, sem_reconnect_operations, admin_user)
  167 +
  168 + # przepisywanie/dodawanie nowych przykladow do schematow
  169 + examples_operations = []
  170 + for old_example in old_lemma.nkjp_examples.all():
  171 + if new_lemma.frames.filter(pk=old_example.frame.pk).exists():
  172 + new_lemma.nkjp_examples.add(old_example)
  173 + else:
  174 + conversion = (conv for conv in schemata_conversions if conv['old_schema'] == old_example.frame).next()
  175 +
  176 + argument_selections = []
  177 + for old_arg_selection in old_example.arguments.all():
  178 +
  179 + position_conversion = next((pos_conv for pos_conv in conversion['positions_changes']
  180 + if pos_conv['from'].pk == old_arg_selection.position.pk), None)
  181 +
  182 + if position_conversion:
  183 + new_arg_selection, xx = get_or_create_nkjp_arg_selection(position_conversion['to'],
  184 + old_arg_selection.arguments.all())
  185 + argument_selections.append(new_arg_selection)
  186 + else:
  187 + argument_selections.append(old_arg_selection)
  188 +
  189 + # sprawdzanie czy dany obiekt klasy NKJP_Example istnieje
  190 + new_example, xx = get_or_create_nkjp_example(conversion['new_schema'], argument_selections,
  191 + old_example.sentence, old_example.source,
  192 + old_example.comment, old_example.opinion,
  193 + old_example.approvers.all(),
  194 + old_example.approved, old_example.semantic)
  195 + new_lemma.nkjp_examples.add(new_example)
  196 +
  197 + # reconnect examples in semantic layer
  198 + for frame in new_lemma.entry_obj.visible_frames(): # czy actual ??
  199 + for lu in frame.lexical_units.all():
  200 + if LexicalUnitExamples.objects.filter(lexical_unit=lu, example=old_example).exists():
  201 + examples_operations.append(self.disconnect_example_operation(lu, old_example))
  202 + examples_operations.append(self.connect_example_operation(lu, new_example))
  203 +
  204 + reconnect_examples(new_lemma, examples_operations)
  205 +
  206 + def get_or_create_new_schema(self, old_schema):
  207 + positions = []
  208 + positions_changes = []
  209 + for position in old_schema.positions.all():
  210 + if self.position_need_manual_change(position):
  211 + new_position = self.get_or_create_new_position(position)
  212 + positions.append(new_position)
  213 + positions_changes.append({'from': position, 'to': new_position})
  214 + else:
  215 + positions.append(position)
  216 +
  217 + sorted_positions = []
  218 + sorted_positions_dict = sortPositions(positions)
  219 + for position_dict in sorted_positions_dict:
  220 + sorted_positions.append(position_dict['position'])
  221 +
  222 + sorted_positions_strs = []
  223 + for position in sorted_positions:
  224 + sorted_positions_strs.append(position.text_rep)
  225 +
  226 + sorted_schema_chars = sortFrameChars(old_schema.characteristics.all())
  227 + sorted_schema_chars_strs = [char.value.value for char in sorted_schema_chars]
  228 +
  229 + text_rep = u'%s:%s' % (':'.join(sorted_schema_chars_strs),
  230 + '+'.join(sorted_positions_strs))
  231 +
  232 + try:
  233 + new_schema = Frame.objects.get(text_rep=text_rep)
  234 + except Frame.DoesNotExist:
  235 + new_schema = Frame(text_rep=text_rep)
  236 + new_schema.save()
  237 +
  238 + last_pos_obj = None
  239 + pos_obj_count = 0
  240 + for pos_obj in sorted_positions:
  241 + same_pos_db = Position.objects.filter(text_rep=pos_obj.text_rep).order_by('id')
  242 + if not last_pos_obj or last_pos_obj.text_rep != pos_obj.text_rep:
  243 + pos_obj_count = 1
  244 + new_schema.positions.add(same_pos_db[0])
  245 + else:
  246 + pos_obj_count = pos_obj_count + 1
  247 + if pos_obj_count <= len(same_pos_db):
  248 + same_pos_obj = same_pos_db[pos_obj_count - 1]
  249 + new_schema.positions.add(same_pos_obj)
  250 + else:
  251 + same_pos_obj = Position(text_rep=pos_obj.text_rep)
  252 + same_pos_obj.save()
  253 + for category in pos_obj.categories.all():
  254 + same_pos_obj.categories.add(category)
  255 + for arg in pos_obj.arguments.all():
  256 + same_pos_obj.arguments.add(arg)
  257 + new_schema.positions.add(same_pos_obj)
  258 + last_pos_obj = pos_obj
  259 + for schema_char in old_schema.characteristics.all():
  260 + new_schema.characteristics.add(schema_char)
  261 + if new_schema.has_phraseologic_arguments():
  262 + new_schema.phraseologic = True
  263 + new_schema.save()
  264 +
  265 + return new_schema, positions_changes
  266 +
  267 + def position_need_manual_change(self, position):
  268 + if position.categories.filter(category__in=['controllee', 'controller']).exists():
  269 + return True
  270 + return False
  271 +
  272 + def get_or_create_new_position(self, old_position):
  273 + categories_strs = []
  274 + for category in old_position.categories.all():
  275 + if category.category == 'controllee':
  276 + categories_strs.append('pred_controllee')
  277 + elif category.category == 'controller':
  278 + categories_strs.append('pred_controller')
  279 + else:
  280 + categories_strs.append(category.category)
  281 +
  282 + sorted_categories_strs = sortPosCatsAsStrTab(categories_strs)
  283 + sorted_arguments = sortArguments(old_position.arguments.all())
  284 +
  285 + args_strs = []
  286 + for arg in sorted_arguments:
  287 + args_strs.append(arg.text_rep)
  288 +
  289 + pos_text_rep = '%s{%s}' % (','.join(sorted_categories_strs), ';'.join(args_strs))
  290 +
  291 + try:
  292 + new_position = Position.objects.get(text_rep=pos_text_rep)
  293 + except Position.DoesNotExist:
  294 + new_position = Position(text_rep=pos_text_rep)
  295 + new_position.save()
  296 +
  297 + for category_name in sorted_categories_strs:
  298 + category = PositionCategory.objects.get(category=category_name)
  299 + new_position.categories.add(category)
  300 +
  301 + for arg in old_position.arguments.all():
  302 + new_position.arguments.add(arg)
  303 +
  304 + return new_position
  305 +
  306 + def get_semantic_operations(self, lemma, schemata_conversions):
  307 + operations = []
  308 +
  309 + frames = lemma.entry_obj.visible_frames() # czy actual??
  310 +
  311 + for conv in schemata_conversions:
  312 + schema_operations = self.get_reconnect_operations(frames, conv)
  313 + operations.extend(schema_operations)
  314 +
  315 + return operations
  316 +
  317 +
  318 + def get_reconnect_operations(self, frames, conversion):
  319 + operations = []
  320 +
  321 + for frame in frames:
  322 + for compl in frame.complements.all():
  323 + arg_ref = create_argument_ref(frame, compl)
  324 + for rel in compl.realizations.all():
  325 + schema_change = False
  326 + position_change = None
  327 + if rel.frame.pk == conversion['old_schema'].pk:
  328 + schema_change = True
  329 + for change in conversion['positions_changes']:
  330 + if change['from'].pk == rel.position.pk:
  331 + position_change = change
  332 + if schema_change:
  333 + old_phrase_type_ref = create_phrase_type_ref(rel.frame, rel.position,
  334 + rel.argument, rel.alternation)
  335 + if position_change:
  336 + new_phrase_type_ref = create_phrase_type_ref(conversion['new_schema'],
  337 + position_change['to'],
  338 + rel.argument,
  339 + rel.alternation)
  340 + else:
  341 + new_phrase_type_ref = create_phrase_type_ref(conversion['new_schema'],
  342 + rel.position,
  343 + rel.argument,
  344 + rel.alternation)
  345 + if new_phrase_type_ref != old_phrase_type_ref:
  346 + operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref))
  347 + operations.append(create_operation('connect', arg_ref, new_phrase_type_ref))
  348 + return operations
  349 +
  350 + def disconnect_example_operation(self, lu, example):
  351 + return {'operation': 'remove_example', 'unit': lu.id, 'example': example.id}
  352 +
  353 + def connect_example_operation(self, lu, example):
  354 + return {'operation': 'add_example', 'unit': lu.id, 'example': example.id}
... ...
dictionary/management/commands/check_text_reps.py 0 → 100644
  1 +# -*- coding:utf-8 -*-
  2 +
  3 +import codecs
  4 +import os
  5 +
  6 +from django.core.management.base import BaseCommand
  7 +from django.db.models import Count
  8 +
  9 +from dictionary.common_func import frame_data_to_text_rep, \
  10 + position_data_to_text_rep
  11 +from dictionary.models import Argument, Argument_Model, Frame, \
  12 + Position, sortatributes, AttributeParameter
  13 +from settings import PROJECT_PATH
  14 +
  15 +WRONG_PARAMETERS_PATH = os.path.join(PROJECT_PATH, 'data', 'wrong', 'wrong_parameters_po_reperacji_20180801.txt')
  16 +WRONG_ARGUMENTS_PATH = os.path.join(PROJECT_PATH, 'data', 'wrong', 'wrong_arguments_po_reperacji_20180801.txt')
  17 +WRONG_POSITIONS_PATH = os.path.join(PROJECT_PATH, 'data', 'wrong', 'wrong_positions_po_reperacji_20180801.txt')
  18 +WRONG_FRAMES_PATH = os.path.join(PROJECT_PATH, 'data', 'wrong', 'wrong_frames_po_reperacji_20180801.txt')
  19 +
  20 +class Command(BaseCommand):
  21 + args = 'none'
  22 + help = 'Looking for wrong text_reps.'
  23 +
  24 + def handle(self, **options):
  25 + check_attr_parameters()
  26 + check_arguments_text_reps()
  27 + check_positions_text_reps()
  28 + check_frames_text_reps()
  29 +
  30 +
  31 +def check_attr_parameters():
  32 + print 'Checking parameters.'
  33 + # try:
  34 + wrong_parameters_file = codecs.open(WRONG_PARAMETERS_PATH, 'wt', 'utf-8')
  35 + for attr_param in AttributeParameter.objects.all():
  36 + print attr_param
  37 + possible_param_objs = AttributeParameter.objects.annotate(subparams_count=Count('subparameters')).filter(
  38 + subparams_count=attr_param.subparameters.count())
  39 + for subparam in attr_param.subparameters.all():
  40 + possible_param_objs = possible_param_objs.filter(subparameters=subparam)
  41 + # possible_param_objs = possible_param_objs.distinct()
  42 + possible_param_objs = possible_param_objs.filter(type=attr_param.type)
  43 + if possible_param_objs.count() > 1:
  44 + wrong_parameters_file.write(u'%s' % unicode(attr_param))
  45 + # finally:
  46 + wrong_parameters_file.close()
  47 +
  48 +
  49 +def check_arguments_text_reps():
  50 + print 'Checking arguments.'
  51 + # try:
  52 + wrong_arguments_file = codecs.open(WRONG_ARGUMENTS_PATH, 'wt', 'utf-8')
  53 + for argument in Argument.objects.all():
  54 + print argument
  55 + proper_text_rep = arg_data_to_text_rep(argument)
  56 + if proper_text_rep != argument.text_rep:
  57 + wrong_arguments_file.write(u'%s --> proper: %s\n' % (argument.text_rep, proper_text_rep))
  58 + # finally:
  59 + wrong_arguments_file.close()
  60 +
  61 +
  62 +def check_positions_text_reps():
  63 + print 'Checking positions.'
  64 + # try:
  65 + wrong_positions_file = codecs.open(WRONG_POSITIONS_PATH, 'wt', 'utf-8')
  66 + for position in Position.objects.all():
  67 + print position
  68 + proper_text_rep = position_data_to_text_rep(position.categories, position.arguments)
  69 + if proper_text_rep != position.text_rep:
  70 + wrong_positions_file.write(u'%s --> proper: %s\n' % (position.text_rep, proper_text_rep))
  71 + # finally:
  72 + wrong_positions_file.close()
  73 +
  74 +
  75 +def check_frames_text_reps():
  76 + print 'Checking frames.'
  77 + # try:
  78 + wrong_frames_file = codecs.open(WRONG_FRAMES_PATH, 'wt', 'utf-8')
  79 + for frame in Frame.objects.all():
  80 + print frame
  81 + proper_text_rep = frame_data_to_text_rep(frame.characteristics, frame.positions)
  82 + if proper_text_rep != frame.text_rep:
  83 + wrong_frames_file.write(u'%s --> proper: %s\n' % (frame.text_rep, proper_text_rep))
  84 + for lemma in frame.lemmas.all():
  85 + if lemma.old:
  86 + wrong_frames_file.write(u'\t\told: %s\n' % (lemma.entry))
  87 + else:
  88 + wrong_frames_file.write('u\t\tnew: %s\n' % (lemma.entry))
  89 + for opinion in frame.opinions.all():
  90 + wrong_frames_file.write(u'\t\topinion: %s\n' % (opinion.frame.text_rep))
  91 + for example in frame.nkjp_examples.all():
  92 + wrong_frames_file.write(u'\t\texample: %s\n' % (example.sentence))
  93 + # finally:
  94 + wrong_frames_file.close()
  95 +
  96 +
  97 +def arg_data_to_text_rep(argument):
  98 + sorted_attributes = sortatributes(argument)
  99 + arg_model = Argument_Model.objects.get(arg_model_name=argument.type)
  100 + # sorted_attributes = sort_arg_attributes(arg_model, attributes)
  101 + attributes_text_reps = [unicode(attr) for attr in sorted_attributes]
  102 + if len(sorted_attributes) == 0:
  103 + arg_text_rep = argument.type
  104 + elif arg_model.hide_type:
  105 + arg_text_rep = u'%s' % (','.join(attributes_text_reps))
  106 + else:
  107 + arg_text_rep = u'%s(%s)' % (argument.type, ','.join(attributes_text_reps))
  108 + return arg_text_rep
... ...
dictionary/management/commands/get_stats_from.py
... ... @@ -11,7 +11,7 @@ from django.db.models import Count, Max
11 11 from dictionary.models import get_ready_statuses
12 12  
13 13  
14   -STARTDATE = datetime.datetime(2017, 1, 1, 00, 00)
  14 +STARTDATE = datetime.datetime(2016, 7, 1, 00, 00)
15 15  
16 16  
17 17 class Command(BaseCommand):
... ... @@ -113,8 +113,6 @@ def get_stats(pos):
113 113 stats_dict[u'frames_with_shared'] += visible_frames.count()
114 114 stats_dict[u'sem_lemmas'] += 1
115 115  
116   -
117   -
118 116 return stats_dict
119 117  
120 118  
... ...
dictionary/models.py
... ... @@ -501,12 +501,13 @@ class NKJP_Example(Model):
501 501 )
502 502  
503 503 def get_or_create_nkjp_example(frame, arguments, sentence, source,
504   - comment, opinion, approvers, approved):
  504 + comment, opinion, approvers, approved, semantic):
505 505 created = False
506 506 example = None
507 507 possible_examples = NKJP_Example.objects.filter(frame=frame, sentence=sentence,
508 508 source=source, comment=comment,
509   - opinion=opinion, approved=approved)
  509 + opinion=opinion, approved=approved,
  510 + semantic=semantic)
510 511 if possible_examples.exists():
511 512 for arg_sel in arguments:
512 513 possible_examples = possible_examples.filter(arguments=arg_sel)
... ... @@ -522,27 +523,31 @@ def get_or_create_nkjp_example(frame, arguments, sentence, source,
522 523 example = create_nkjp_example(frame=frame, arguments=arguments,
523 524 sentence=sentence, source=source,
524 525 comment=comment, opinion=opinion,
525   - approvers=approvers, approved=approved)
  526 + approvers=approvers, approved=approved,
  527 + semantic=semantic)
526 528 created = True
527 529 else:
528 530 example = create_nkjp_example(frame=frame, arguments=arguments,
529 531 sentence=sentence, source=source,
530 532 comment=comment, opinion=opinion,
531   - approvers=approvers, approved=approved)
  533 + approvers=approvers, approved=approved,
  534 + semantic=semantic)
532 535 created = True
533 536 else:
534 537 example = create_nkjp_example(frame=frame, arguments=arguments,
535 538 sentence=sentence, source=source,
536 539 comment=comment, opinion=opinion,
537   - approvers=approvers, approved=approved)
  540 + approvers=approvers, approved=approved,
  541 + semantic=semantic)
538 542 created = True
539 543 return example, created
540 544  
541 545 def create_nkjp_example(frame, arguments, sentence, source,
542   - comment, opinion, approvers, approved):
  546 + comment, opinion, approvers, approved, semantic):
543 547 example = NKJP_Example(frame=frame, sentence=sentence,
544 548 source=source, comment=comment,
545   - opinion=opinion, approved=approved)
  549 + opinion=opinion, approved=approved,
  550 + semantic=semantic)
546 551 example.save()
547 552 example.arguments.add(*arguments)
548 553 example.approvers.add(*approvers)
... ...
dictionary/teixml.py
... ... @@ -65,7 +65,7 @@ def write_license_elem(parent_elem):
65 65 licence.attrib['target'] = u'http://creativecommons.org/licenses/by-sa/4.0/'
66 66  
67 67 p = etree.SubElement(licence, 'p')
68   - p.text = u'(C) Copyright 2012–2017 by the Institute of Computer Science, Polish Academy of Sciences (IPI PAN)'
  68 + p.text = u'(C) Copyright 2012–2018 by the Institute of Computer Science, Polish Academy of Sciences (IPI PAN)'
69 69  
70 70 p = etree.SubElement(licence, 'p')
71 71 p.text = u'This work is distributed under a CC BY-SA license: http://creativecommons.org/licenses/by-sa/4.0/'
... ...
semantics/management/commands/adjectives_todo.py
1 1 #! /usr/bin/python
2 2 # -*- coding: utf-8 -*-
3 3  
4   -import sys, os, codecs
5   -
6 4 from django.core.management.base import BaseCommand
7 5  
8 6 from django.core.exceptions import ObjectDoesNotExist
9 7 from dictionary.models import Entry, POS
10   -from wordnet.models import LexicalUnit
11   -from settings import PROJECT_PATH
  8 +
  9 +
  10 +REL_POS = 'noun'
  11 +REL_STATUS = '(S) sprawdzone'
  12 +
12 13  
13 14 class Command(BaseCommand):
14 15 args = 'none'
15 16 help = ''
16 17  
17 18 def handle(self, **options):
18   - nouns_todo()
  19 + adj_todo()
  20 +
19 21  
20   -def nouns_todo():
  22 +def adj_todo():
21 23 adj = POS.objects.get(tag='adj')
22   - verb = POS.objects.get(tag='verb')
23 24 entries = Entry.objects.filter(pos=adj).order_by('name')
24 25 for entry in entries:
25 26 try:
26   - temp = entry.actual_lemma()
  27 + entry.actual_lemma()
27 28 except ObjectDoesNotExist:
28 29 continue
29   - rel_entries = entry.rel_entries.filter(pos=verb)
  30 +
  31 + rel_entries = entry.rel_entries.filter(pos__tag=REL_POS)
30 32 for rel_entry in rel_entries:
31   - try:
32   - temp = entry.actual_lemma()
33   - except ObjectDoesNotExist:
34   - continue
35   - if rel_entry.actual_lemma().status.priority == 100:
  33 + if rel_entry.actual_lemma().status.status == REL_STATUS:
36 34 print entry.name, ' ', entry.actual_lemma().status.status, '\t->\t', rel_entry.name, ' ', rel_entry.actual_lemma().status.status
37   -
... ...