Commit dbf1c0e07ea2d407ebc2d5b8aa69b68cf71f0c61
1 parent
aa27b539
Added possibility to copy schema elements between nouns and adjectives.
Showing
4 changed files
with
59 additions
and
19 deletions
dictionary/ajax_lemma_view.py
... | ... | @@ -44,7 +44,7 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ |
44 | 44 | sorted_default_frame_char_vals, XcpExample, \ |
45 | 45 | POS, get_frame_char_and_its_value, get_frame_char_by_type_and_value_pk, \ |
46 | 46 | sortFrameChars, sortArguments, sortPositions, \ |
47 | - get_or_create_position, get_phraseologic_frames_only | |
47 | + get_or_create_position, get_phraseologic_frames_only, pos_compatible | |
48 | 48 | from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ |
49 | 49 | AddNkjpExampleForm, MessageForm, SortForm, FilterForm, \ |
50 | 50 | SimilarLemmasNewForm, ChangeUserFunctionForm, \ |
... | ... | @@ -1395,24 +1395,30 @@ def need_conversion(request, from_lemma_id, to_lemma_id): |
1395 | 1395 | from_entry = Entry.objects.get(name=from_lemma.entry) |
1396 | 1396 | to_lemma = Lemma.objects.get(id=to_lemma_id) |
1397 | 1397 | to_entry = Entry.objects.get(name=to_lemma.entry) |
1398 | - if not from_entry.pos.tag == to_entry.pos.tag: | |
1398 | + if not pos_compatible(from_entry.pos, to_entry.pos): | |
1399 | 1399 | need_conversion = True |
1400 | - if (to_entry.rel_entries.filter(pk=from_entry.pk).exists() and | |
1401 | - from_entry.pos.tag == 'verb' and | |
1402 | - (to_entry.pos.tag == 'noun' or to_entry.pos.tag == 'adj')): | |
1400 | + if conversion_possible(from_entry, to_entry): | |
1403 | 1401 | can_be_converted = True |
1404 | 1402 | return {'can_be_converted': can_be_converted, |
1405 | 1403 | 'need_conversion': need_conversion} |
1406 | 1404 | |
1405 | +def conversion_possible(from_entry, to_entry): | |
1406 | + can_be_converted = False | |
1407 | + if (to_entry.rel_entries.filter(pk=from_entry.pk).exists() and | |
1408 | + from_entry.pos.tag == 'verb' and | |
1409 | + (to_entry.pos.tag == 'noun' or to_entry.pos.tag == 'adj')): | |
1410 | + can_be_converted = True | |
1411 | + return can_be_converted | |
1412 | + | |
1407 | 1413 | @ajax(method='get') |
1408 | 1414 | def get_compatible_schema_chars(request, lemma_id, schema_id): |
1409 | 1415 | schema_chars = [] |
1416 | + lemma = Lemma.objects.get(id=lemma_id) | |
1410 | 1417 | schema = Frame.objects.get(id=schema_id) |
1411 | 1418 | schema_char_objs = sortFrameChars(schema.characteristics.all()) |
1412 | 1419 | |
1413 | 1420 | if (not request.user.has_perm('dictionary.add_syntactic_frames') and |
1414 | 1421 | not request.user.is_superuser): |
1415 | - lemma = Lemma.objects.get(id=lemma_id) | |
1416 | 1422 | for char in schema_char_objs: |
1417 | 1423 | possible_values = get_frame_char_values(char.type, lemma, True) |
1418 | 1424 | if possible_values.filter(id=char.value.id).exists(): |
... | ... | @@ -1420,7 +1426,12 @@ def get_compatible_schema_chars(request, lemma_id, schema_id): |
1420 | 1426 | else: |
1421 | 1427 | schema_chars.append(possible_values.all()[0].value) |
1422 | 1428 | else: |
1423 | - schema_chars = [char.value.value for char in schema_char_objs] | |
1429 | + for char in schema_char_objs: | |
1430 | + possible_values = get_frame_char_values(char.type, lemma, False) | |
1431 | + if possible_values.filter(id=char.value.id).exists(): | |
1432 | + schema_chars.append(char.value.value) | |
1433 | + else: | |
1434 | + schema_chars.append(possible_values.all()[0].value) | |
1424 | 1435 | |
1425 | 1436 | return {'schema_chars': schema_chars} |
1426 | 1437 | |
... | ... | @@ -2569,7 +2580,7 @@ def validate_new_frames(request, data, id, examples, lemma_examples, |
2569 | 2580 | |
2570 | 2581 | serialized_frames = [] |
2571 | 2582 | error = False |
2572 | - if status_need_examples_check and not status_need_validation: #z tymi warunkami jest blad, patrz haslo adresowac | |
2583 | + if status_need_examples_check and not status_need_validation: | |
2573 | 2584 | serialized_frames, error = validate_examples_and_mark_errors(old_object, status_obj, selected_frame_id) |
2574 | 2585 | elif status_need_validation or not status_obj: |
2575 | 2586 | serialized_frames, error = validate_schemas_and_mark_errors(old_object, status_obj, selected_frame_id) |
... | ... | @@ -2611,6 +2622,7 @@ def validate_new_frames(request, data, id, examples, lemma_examples, |
2611 | 2622 | for miss_frame in missmatched_B_frames: |
2612 | 2623 | message_content += u'\t- %s\n' % (miss_frame.text_rep) |
2613 | 2624 | message_content += '\n' |
2625 | + message_content += deriv_miss_frames_msg | |
2614 | 2626 | if len(frames_to_merge) > 0: |
2615 | 2627 | message_content += u'Sugerowane jest połączenie poniższych schematów, zawierają one często koordynujące się typy fraz:\n' |
2616 | 2628 | for comb in frames_to_merge: |
... | ... | @@ -2618,7 +2630,6 @@ def validate_new_frames(request, data, id, examples, lemma_examples, |
2618 | 2630 | comb['frames'][1].id, comb['frames'][1].text_rep, |
2619 | 2631 | comb['occurrences']) |
2620 | 2632 | message_content += '\n' |
2621 | - message_content += deriv_miss_frames_msg | |
2622 | 2633 | if message_content: |
2623 | 2634 | if status_need_validation: |
2624 | 2635 | message_content += u'Czy jesteś pewien, że chcesz zmienić status hasła?' |
... | ... |
dictionary/convert_frames.py
... | ... | @@ -41,6 +41,12 @@ def frame_conversion(frame, from_pos, to_pos): |
41 | 41 | elif from_pos.tag == 'verb' and to_pos.tag == 'adj': |
42 | 42 | arg_conversion_function = verb_to_adj_arg_conversion |
43 | 43 | frame_realizations = verb_to_adj_conversion(frame) |
44 | + elif from_pos.tag == 'noun' and to_pos.tag == 'adj': | |
45 | + arg_conversion_function = noun_to_adj_arg_conversion | |
46 | + frame_realizations = noun_to_adj_conversion(frame) | |
47 | + elif from_pos.tag == 'adj' and to_pos.tag == 'noun': | |
48 | + arg_conversion_function = adj_to_noun_arg_conversion | |
49 | + frame_realizations = adj_to_noun_conversion(frame) | |
44 | 50 | frame_versions = create_frame_versions(frame_realizations, arg_conversion_function) |
45 | 51 | return frame_versions |
46 | 52 | |
... | ... | @@ -79,6 +85,12 @@ def verb_to_adj_arg_conversion(position_category, argument): |
79 | 85 | argument = change_str_to_gen(argument) |
80 | 86 | return argument |
81 | 87 | |
88 | +def noun_to_adj_arg_conversion(position_category, argument): | |
89 | + return argument | |
90 | + | |
91 | +def adj_to_noun_arg_conversion(position_category, argument): | |
92 | + return argument | |
93 | + | |
82 | 94 | def change_str_to_gen(argument): |
83 | 95 | arg_type, attributes_strs = get_arg_parts(argument.text_rep) |
84 | 96 | attributes_strs = ['gen' if attr_str=='str' else attr_str for attr_str in attributes_strs] |
... | ... | @@ -211,6 +223,14 @@ def verb_to_adj_conversion(frame): |
211 | 223 | convert([{'from': ur'^subj\{np\(str\)\}$', 'to': ur'{prepnp(dla,gen)}'}, |
212 | 224 | {'from': ur'^obj\{np\(str\)\}$', 'to': None}], frame_realizations) |
213 | 225 | return frame_realizations |
226 | + | |
227 | +def noun_to_adj_conversion(frame): | |
228 | + frame_realizations = [frame_to_rule_format(frame)] | |
229 | + return frame_realizations | |
230 | + | |
231 | +def adj_to_noun_conversion(frame): | |
232 | + frame_realizations = [frame_to_rule_format(frame)] | |
233 | + return frame_realizations | |
214 | 234 | |
215 | 235 | def frame_to_rule_format(frame): |
216 | 236 | positions = [position_to_rule_format(position) |
... | ... |
dictionary/models.py
... | ... | @@ -1341,6 +1341,15 @@ class POS(Model): |
1341 | 1341 | def __unicode__(self): |
1342 | 1342 | return self.name |
1343 | 1343 | |
1344 | +def pos_compatible(from_pos, to_pos): | |
1345 | + compatible = False | |
1346 | + if from_pos == to_pos: | |
1347 | + compatible = True | |
1348 | + elif ((from_pos.tag == 'noun' and to_pos.tag == 'adj') or | |
1349 | + (from_pos.tag == 'adj' and to_pos.tag == 'noun')): | |
1350 | + compatible = True | |
1351 | + return compatible | |
1352 | + | |
1344 | 1353 | class XcpExample(Model): |
1345 | 1354 | arg_regex = CharField(max_length=64, db_column='wzor_argumentu') |
1346 | 1355 | #examples = ManyToManyField('NKJP_Example', related_name='xcp_examples') |
... | ... |
dictionary/validation.py
... | ... | @@ -210,16 +210,6 @@ def find_similar_frames(frames): |
210 | 210 | |
211 | 211 | ###################### walidacja powiazanych hasel (nieczasownikowe) ####################################### |
212 | 212 | |
213 | -def get_deriv_related_lemmas(entry): | |
214 | - deriv_related_lemmas = [] | |
215 | - for rel_entry in entry.rel_entries.order_by('name'): | |
216 | - try: | |
217 | - rel_lemma = Lemma.objects.get(entry_obj=rel_entry, old=False) | |
218 | - deriv_related_lemmas.append(rel_lemma) | |
219 | - except Lemma.DoesNotExist: | |
220 | - pass | |
221 | - return deriv_related_lemmas | |
222 | - | |
223 | 213 | def get_deriv_miss_frames_message(lemma): |
224 | 214 | message_content = '' |
225 | 215 | missing_frames = get_deriv_miss_frames(lemma) |
... | ... | @@ -248,6 +238,16 @@ def get_deriv_miss_frames(lemma): |
248 | 238 | add_missing_deriv_frame(missing_frames, frame, deriv_rel_lemma.entry_obj) |
249 | 239 | return missing_frames |
250 | 240 | |
241 | +def get_deriv_related_lemmas(entry): | |
242 | + deriv_related_lemmas = [] | |
243 | + for rel_entry in entry.rel_entries.order_by('name'): | |
244 | + try: | |
245 | + rel_lemma = Lemma.objects.get(entry_obj=rel_entry, old=False) | |
246 | + deriv_related_lemmas.append(rel_lemma) | |
247 | + except Lemma.DoesNotExist: | |
248 | + pass | |
249 | + return deriv_related_lemmas | |
250 | + | |
251 | 251 | def get_deriv_frames_to_check(lemma): |
252 | 252 | lemma_frames = lemma.frames.order_by('text_rep') |
253 | 253 | frames = [frame for frame in lemma_frames |
... | ... |