Commit ca4682686284a70d0908e43ea5b11ca5a8889b7d
Merge branch 'master' into tomek
Showing
26 changed files
with
1043 additions
and
558 deletions
LICENSE
accounts/admin.py
... | ... | @@ -39,7 +39,8 @@ class RealizedPhraseologyAdmin(admin.ModelAdmin): |
39 | 39 | readonly_fields = ('date',) |
40 | 40 | search_fields = ('lemma__entry',) |
41 | 41 | |
42 | -class RealizedSemanticsAdmin(admin.ModelAdmin): | |
42 | +class RealizedSemanticsAdmin(admin.ModelAdmin): | |
43 | + exclude = ('entry',) | |
43 | 44 | list_filter = ('status', 'bonus',) |
44 | 45 | search_fields = ('entry__name',) |
45 | 46 | |
... | ... |
common/js_to_obj.py
... | ... | @@ -43,7 +43,7 @@ def jsFrameToObj(frame, lemma_entry): |
43 | 43 | for position in frame['positions']: |
44 | 44 | if len(position['arguments']) > 0: |
45 | 45 | pos_obj = jsPosToObj(position) |
46 | - positions_objs.append(pos_obj) | |
46 | + positions_objs.append(pos_obj) | |
47 | 47 | |
48 | 48 | sorted_positions = [] |
49 | 49 | sorted_pos_dict = sortPositions(positions_objs) |
... | ... | @@ -125,7 +125,7 @@ def jsArgToObj(argument): |
125 | 125 | arg_obj = Argument.objects.get(text_rep=argument['text_rep']) |
126 | 126 | return arg_obj |
127 | 127 | |
128 | -def frameObjToSerializableDict(lemma, frame): | |
128 | +def frameObjToSerializableDict(lemma, frame, with_connections=False): | |
129 | 129 | frame_opinion = '' |
130 | 130 | frame_opinions_tab = lemma.frame_opinions.filter(frame__text_rep=frame.text_rep) |
131 | 131 | if frame_opinions_tab: |
... | ... | @@ -155,11 +155,16 @@ def frameObjToSerializableDict(lemma, frame): |
155 | 155 | 'tooltip' : ''} |
156 | 156 | |
157 | 157 | for argument in position['arguments']: |
158 | + connections = [] | |
159 | + if with_connections: | |
160 | + entry = lemma.entry_obj | |
161 | + connections = entry.matching_connections(frame, position['position'], argument) | |
158 | 162 | argument_dict = { 'id' : argument.id, |
159 | 163 | 'text_rep': argument.text_rep, |
160 | 164 | 'type' : argument.type, |
161 | 165 | 'error' : False, |
162 | - 'tooltip' : ''} | |
166 | + 'tooltip' : '', | |
167 | + 'connections': connections} | |
163 | 168 | position_dict['arguments'].append(argument_dict) |
164 | 169 | |
165 | 170 | frame_dict['positions'].append(position_dict) |
... | ... | @@ -168,4 +173,4 @@ def frameObjToSerializableDict(lemma, frame): |
168 | 173 | for char in frame_char_objs: |
169 | 174 | frame_dict['characteristics'].append(char.value.value) |
170 | 175 | |
171 | - return frame_dict | |
176 | + return frame_dict | |
... | ... |
dictionary/ajax_lemma_status.py
... | ... | @@ -63,7 +63,8 @@ def get_lemma_status(request, id): |
63 | 63 | return {'lemma': selected_lemma, |
64 | 64 | 'abort_status': abort_status, |
65 | 65 | 'next_statuses': next_statuses, |
66 | - 'pos': pos} | |
66 | + 'pos': pos, | |
67 | + 'status_changes': selected_lemma.status_history.order_by('-date')} | |
67 | 68 | |
68 | 69 | def phraseologic_status_changes(user, selected_lemma): |
69 | 70 | phraseologic_change = False |
... | ... |
dictionary/ajax_lemma_view.py
... | ... | @@ -50,15 +50,20 @@ from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ |
50 | 50 | SimilarLemmasNewForm, ChangeUserFunctionForm, \ |
51 | 51 | ExampleOpinionForm, \ |
52 | 52 | FrameConversionForm, CreatePositionForm, AssignPhraseologicFrameForm |
53 | +from dictionary.saving import connect_example_operation, disconnect_all_examples_operations, \ | |
54 | + get_semantic_operations, update_connections, reconnect_examples, \ | |
55 | + disconnect_example_operation | |
56 | + | |
53 | 57 | from common.decorators import render, ajax, AjaxError |
54 | 58 | from common.util import triple_arg_poss |
55 | 59 | from dictionary.validation import find_similar_frames, get_all_test_missing_frames, get_aspect_rel_lemmas, \ |
56 | 60 | get_wrong_aspect_frames, validate_B_frames, get_deriv_miss_frames_message, \ |
57 | 61 | validate_phraseology_binded_frames, validate_rule_5, \ |
58 | 62 | validate_examples_and_mark_errors, validate_schemas_and_mark_errors, \ |
59 | - get_missing_aspects_msg | |
63 | + get_missing_aspects_msg, validate_same_positions_schemata | |
60 | 64 | |
61 | 65 | from semantics.models import LexicalUnitExamples |
66 | + | |
62 | 67 | from wordnet.models import LexicalUnit |
63 | 68 | |
64 | 69 | from settings import PROJECT_PATH |
... | ... | @@ -160,6 +165,7 @@ def prepareFrameTable(frame): |
160 | 165 | |
161 | 166 | def nkjpExamplesObjToJs(nkjp_examples, user, lemma): |
162 | 167 | example_dict_list = [] |
168 | + lexical_units = lemma.entry_obj.lexical_units() | |
163 | 169 | for example in nkjp_examples: |
164 | 170 | frame = example.frame; |
165 | 171 | frame_table_id = 'frame_'+str(frame.id)+'_' |
... | ... | @@ -193,11 +199,21 @@ def nkjpExamplesObjToJs(nkjp_examples, user, lemma): |
193 | 199 | 'opinion' : example.opinion.opinion, |
194 | 200 | 'comment' : comment, |
195 | 201 | 'confirmed' : confirmed, |
196 | - 'semantic' : example.semantic} | |
202 | + 'semantic' : example.semantic, | |
203 | + 'lexical_unit' : get_example_lexical_unit_id(lexical_units, example)} | |
197 | 204 | example_dict_list.append(example_dict) |
198 | 205 | |
199 | 206 | return example_dict_list |
200 | 207 | |
208 | +def get_example_lexical_unit_id(lexical_units, example): | |
209 | + unit_id = -1 | |
210 | + for lex_unit in lexical_units: | |
211 | + if LexicalUnitExamples.objects.filter(example=example, | |
212 | + lexical_unit=lex_unit).exists(): | |
213 | + unit_id = lex_unit.id | |
214 | + break | |
215 | + return unit_id | |
216 | + | |
201 | 217 | def nkjpLemmaExamplesObjToJs(nkjp_examples, user, lemma): |
202 | 218 | example_dict_list = [] |
203 | 219 | for example in nkjp_examples: |
... | ... | @@ -223,7 +239,9 @@ def nkjpLemmaExamplesObjToJs(nkjp_examples, user, lemma): |
223 | 239 | 'source' : example.source.source, |
224 | 240 | 'opinion' : example.opinion.opinion, |
225 | 241 | 'comment' : comment, |
226 | - 'confirmed' : confirmed} | |
242 | + 'confirmed' : confirmed, | |
243 | + 'semantic' : False, | |
244 | + 'lexical_unit' : -1} | |
227 | 245 | example_dict_list.append(example_dict) |
228 | 246 | |
229 | 247 | return example_dict_list |
... | ... | @@ -369,7 +387,7 @@ def get_new_frames(request, id): |
369 | 387 | |
370 | 388 | serialized_frames = [] |
371 | 389 | for frame in new_frames: |
372 | - serialized_frames.append(frameObjToSerializableDict(selected_lemma, frame)) | |
390 | + serialized_frames.append(frameObjToSerializableDict(selected_lemma, frame, True)) | |
373 | 391 | json_frames = json_encode(serialized_frames) |
374 | 392 | |
375 | 393 | # konwertowanie przykladow na zrozumiale przez java sript |
... | ... | @@ -2067,7 +2085,7 @@ def frame_form_submit(request, form_data): |
2067 | 2085 | text_rep = selected_frame.text_rep |
2068 | 2086 | json_frame = json_encode(frameObjToSerializableDict(lemma_obj, selected_frame)) |
2069 | 2087 | json_examples = json_encode([]) |
2070 | - else: | |
2088 | + elif form_dict['frame_str']: | |
2071 | 2089 | frame = json_decode(form_dict['frame_str']) |
2072 | 2090 | positions_objs = [] |
2073 | 2091 | for position in frame['positions']: |
... | ... | @@ -2104,6 +2122,8 @@ def frame_form_submit(request, form_data): |
2104 | 2122 | frame_id = new_frame_obj.id |
2105 | 2123 | text_rep = new_frame_obj.text_rep |
2106 | 2124 | json_examples = json_encode([]) |
2125 | + else: | |
2126 | + raise AjaxError('data error') | |
2107 | 2127 | |
2108 | 2128 | return {'id' : frame_id, |
2109 | 2129 | 'text_rep': text_rep, |
... | ... | @@ -2405,7 +2425,8 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2405 | 2425 | for B_frame in old_object.B_frames.all(): |
2406 | 2426 | new_lemma_ver.B_frames.add(B_frame) |
2407 | 2427 | |
2408 | - # tworzenie ramek i dolaczanie ich do czasownika | |
2428 | + # tworzenie ramek i dolaczanie ich do czasownika | |
2429 | + schemata_conversions = [] | |
2409 | 2430 | for frame in frames: |
2410 | 2431 | frame_obj = jsFrameToObj(frame, new_lemma_ver.entry) |
2411 | 2432 | # blokuje zapisywanie ramek frazeologicznych bez argumentow frazeologicznych |
... | ... | @@ -2424,8 +2445,14 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2424 | 2445 | frame_opinion_obj.save() |
2425 | 2446 | new_lemma_ver.frame_opinions.add(frame_opinion_obj) |
2426 | 2447 | new_lemma_ver.frames.add(frame_obj) |
2448 | + schemata_conversions.append({'js': frame, 'obj': frame_obj}) | |
2449 | + | |
2450 | + # reconnect semantics | |
2451 | + sem_reconnect_operations = get_semantic_operations(new_lemma_ver, schemata_conversions) | |
2452 | + update_connections(new_lemma_ver.id, sem_reconnect_operations, request.user) | |
2427 | 2453 | |
2428 | 2454 | # dodawanie przykladow do ramek |
2455 | + reconnect_examples_operations = disconnect_all_examples_operations(old_object) | |
2429 | 2456 | for example in decoded_examples: |
2430 | 2457 | frame_obj = jsFrameToObj(example['frame'], new_lemma_ver.entry) |
2431 | 2458 | # blokuje zapisywanie przykladow z ramek frazeologicznych bez argumentow frazeologicznych |
... | ... | @@ -2469,16 +2496,18 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2469 | 2496 | for argument in arg_selection['arguments']: |
2470 | 2497 | try: |
2471 | 2498 | arg_obj = jsArgToObj(argument) |
2472 | - argument_objs.append(arg_obj) | |
2473 | - if len(nkjp_arg_sel_query.all()) > 0: # Q objectem to zalatwic | |
2474 | - nkjp_arg_sel_query = nkjp_arg_sel_query.filter(arguments=arg_obj) | |
2499 | + if arg_obj not in argument_objs: | |
2500 | + argument_objs.append(arg_obj) | |
2501 | + if len(nkjp_arg_sel_query.all()) > 0: # Q objectem to zalatwic | |
2502 | + nkjp_arg_sel_query = nkjp_arg_sel_query.filter(arguments=arg_obj) | |
2475 | 2503 | except TypeError: |
2476 | 2504 | pass |
2477 | - | |
2505 | + | |
2506 | + | |
2478 | 2507 | nkjp_arg_sel_obj = None |
2479 | 2508 | if len(nkjp_arg_sel_query.all()) > 0: |
2480 | 2509 | for nkjp_arg_sel in nkjp_arg_sel_query.all(): |
2481 | - if len(nkjp_arg_sel.arguments.all()) == len(argument_objs): | |
2510 | + if len(nkjp_arg_sel.arguments.all()) == len(argument_objs): # zrobic list(set(argument_objs)) | |
2482 | 2511 | nkjp_arg_sel_obj = nkjp_arg_sel |
2483 | 2512 | break |
2484 | 2513 | if not nkjp_arg_sel_obj: |
... | ... | @@ -2518,7 +2547,13 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2518 | 2547 | nkjp_example_obj.save() |
2519 | 2548 | for argument_selection in argument_selections: |
2520 | 2549 | nkjp_example_obj.arguments.add(argument_selection) |
2521 | - new_lemma_ver.nkjp_examples.add(nkjp_example_obj) | |
2550 | + new_lemma_ver.nkjp_examples.add(nkjp_example_obj) | |
2551 | + if example['lexical_unit'] > 0: | |
2552 | + try: | |
2553 | + reconnect_examples_operations.remove(disconnect_example_operation(example, nkjp_example_obj)) | |
2554 | + except ValueError: | |
2555 | + reconnect_examples_operations.append(connect_example_operation(example, nkjp_example_obj)) | |
2556 | + reconnect_examples(reconnect_examples_operations) | |
2522 | 2557 | |
2523 | 2558 | # dodawanie przykladow nkjp do czasownika |
2524 | 2559 | for example in decoded_lemma_examples: |
... | ... | @@ -2544,23 +2579,23 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2544 | 2579 | nkjp_lemma_example_obj.save() |
2545 | 2580 | new_lemma_ver.lemma_nkjp_examples.add(nkjp_lemma_example_obj) |
2546 | 2581 | |
2547 | - old_object.locker = None; | |
2582 | + old_object.locker = None | |
2548 | 2583 | old_object.save() |
2549 | - new_lemma_ver.locker = None; | |
2584 | + new_lemma_ver.locker = None | |
2550 | 2585 | try: |
2551 | 2586 | new_lemma_ver = Lemma.objects.get(entry=old_object.entry, owner=old_object.owner, |
2552 | 2587 | vocabulary=old_object.vocabulary, status=old_object.status, |
2553 | 2588 | old=False) |
2554 | 2589 | raise AjaxError('concurrent access') |
2555 | 2590 | except: |
2556 | - new_lemma_ver.old = False; | |
2557 | - new_lemma_ver.save(); | |
2591 | + new_lemma_ver.old = False | |
2592 | + new_lemma_ver.save() | |
2558 | 2593 | |
2559 | 2594 | return {'id' : new_lemma_ver.id, |
2560 | 2595 | 'entry' : new_lemma_ver.entry, |
2561 | 2596 | 'error_message': '', |
2562 | 2597 | 'frames' : ''} |
2563 | - | |
2598 | + | |
2564 | 2599 | ############## WALIDACJA ##################### |
2565 | 2600 | |
2566 | 2601 | @ajax(method='post') |
... | ... | @@ -2623,6 +2658,7 @@ def validate_new_frames(request, data, id, examples, lemma_examples, |
2623 | 2658 | message_content += u'\t- %s\n' % (miss_frame.text_rep) |
2624 | 2659 | message_content += '\n' |
2625 | 2660 | message_content += deriv_miss_frames_msg |
2661 | + message_content += validate_same_positions_schemata(old_object) | |
2626 | 2662 | frames_to_merge = find_similar_frames(old_object.frames.all()) |
2627 | 2663 | if len(frames_to_merge) > 0: |
2628 | 2664 | message_content += u'Sugerowane jest połączenie poniższych schematów, zawierają one często koordynujące się typy fraz:\n' |
... | ... | @@ -3157,3 +3193,21 @@ def delete_user(request, user_id): |
3157 | 3193 | def deselect_preview_tab(request): |
3158 | 3194 | request.session['lemma_preview'] = False |
3159 | 3195 | return {} |
3196 | + | |
3197 | +@ajax(method='get') | |
3198 | +def get_schemata(request, lemma_id): | |
3199 | + lemma = Lemma.objects.get(id=lemma_id) | |
3200 | + schemata = lemma.frames.order_by('text_rep') | |
3201 | + serialized_schemata = [frameObjToSerializableDict(lemma, schema, True) for schema in schemata] | |
3202 | + json_schemata = json_encode(serialized_schemata) | |
3203 | + return {'schemata': json_schemata, | |
3204 | + 'can_modify': user_can_modify(lemma, request.user)} | |
3205 | + | |
3206 | +@ajax(method='get') | |
3207 | +def get_examples(request, lemma_id): | |
3208 | + lemma = Lemma.objects.get(id=lemma_id) | |
3209 | + examples = lemma.nkjp_examples.all() | |
3210 | + examples_js = nkjpExamplesObjToJs(examples, request.user, lemma) | |
3211 | + json_examples = json_encode(examples_js) | |
3212 | + return {'examples': json_examples, | |
3213 | + 'can_modify': user_can_modify(lemma, request.user)} | |
... | ... |
dictionary/models.py
... | ... | @@ -328,7 +328,12 @@ class StatusChange(Model): |
328 | 328 | blank=True, null=True) |
329 | 329 | |
330 | 330 | def __unicode__(self): |
331 | - return self.lemma.entry + ':' + str(self.date) | |
331 | + return self.lemma.entry + ':' + str(self.date) | |
332 | + | |
333 | + class Meta: | |
334 | + permissions = ( | |
335 | + ('view_status_changes', u'Może oglądać historię zmian statusu'), | |
336 | + ) | |
332 | 337 | |
333 | 338 | class Frame_Opinion(Model): |
334 | 339 | frame = ForeignKey('Frame', db_column='ramka', related_name='opinions', |
... | ... | @@ -1387,6 +1392,20 @@ class Entry(Model): |
1387 | 1392 | frame_ids.extend([f.id for f in lexical_unit.actual_frames()]) |
1388 | 1393 | return get_model('semantics', 'SemanticFrame').objects.filter(id__in=list(set(frame_ids))) |
1389 | 1394 | |
1395 | + def matching_connections(self, schema, position, phrase_type): | |
1396 | + frames = self.actual_frames() | |
1397 | + matching_connections = [] | |
1398 | + for frame in frames: | |
1399 | + for compl in frame.complements.all(): | |
1400 | + matching_realizations = compl.realizations.filter(frame=schema, | |
1401 | + position=position, | |
1402 | + argument=phrase_type) | |
1403 | + if matching_realizations.exists(): | |
1404 | + realizations_ids = [real.id for real in matching_realizations.all()] | |
1405 | + matching_connections.append({'compl': compl.id, | |
1406 | + 'realizations': realizations_ids}) | |
1407 | + return matching_connections | |
1408 | + | |
1390 | 1409 | def __unicode__(self): |
1391 | 1410 | return self.name |
1392 | 1411 | |
... | ... |
dictionary/saving.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | +from common.js_to_obj import jsPosToObj | |
4 | +from dictionary.models import Argument | |
5 | +from semantics.models import Complement, LexicalUnitExamples | |
6 | +from semantics.saving import modify_frames, update_meanings | |
7 | +from wordnet.models import LexicalUnit | |
8 | + | |
9 | +def get_semantic_operations(lemma, schemata_conversions): | |
10 | + connections = [] | |
11 | + operations = [] | |
12 | + frames = lemma.entry_obj.actual_frames() | |
13 | + for conv in schemata_conversions: | |
14 | + schema_operations = get_reconnect_operations_and_extend_connections(frames, | |
15 | + connections, | |
16 | + conv['obj'], | |
17 | + conv['js']) | |
18 | + operations.extend(schema_operations) | |
19 | + operations.extend(get_disconnect_operations(frames, connections)) | |
20 | + return operations | |
21 | + | |
22 | +def get_reconnect_operations_and_extend_connections(frames, connections, schema, js_schema): | |
23 | + operations = [] | |
24 | + used_poss_ids = [] | |
25 | + for js_position in js_schema['positions']: | |
26 | + if len(js_position['arguments']) > 0: | |
27 | + position = get_position(schema, js_position, used_poss_ids) | |
28 | + for js_phrase_type in js_position['arguments']: | |
29 | + phrase_type = Argument.objects.get(text_rep=js_phrase_type['text_rep']) | |
30 | + new_connection_target = {'schema': schema, | |
31 | + 'position': position, | |
32 | + 'phrase_type': phrase_type} | |
33 | + for conn in js_phrase_type['connections']: | |
34 | + operations.extend(reconnect_operations(frames, conn, new_connection_target)) | |
35 | + conn_dict = next((conn_dict | |
36 | + for conn_dict in connections if conn_dict['compl'] == conn['compl']), None) | |
37 | + if conn_dict: | |
38 | + conn_dict['realizations'].extend(conn['realizations']) | |
39 | + else: | |
40 | + connections.append({'compl': conn['compl'], | |
41 | + 'realizations': conn['realizations']}) | |
42 | + return operations | |
43 | + | |
44 | +def get_position(schema, js_position, used_poss_ids): | |
45 | + position = jsPosToObj(js_position) | |
46 | + same_poss = schema.positions.filter(text_rep=position.text_rep) | |
47 | + unused_same_poss = same_poss.exclude(id__in=used_poss_ids).order_by('id') | |
48 | + position = unused_same_poss[0] | |
49 | + used_poss_ids.append(position.id) | |
50 | + return position | |
51 | + | |
52 | +def reconnect_operations(frames, connection, new_target): | |
53 | + operations = [] | |
54 | + compl = Complement.objects.get(id=connection['compl']) | |
55 | + frame = frames.get(complements=compl) | |
56 | + arg_ref = create_argument_ref(frame, compl) | |
57 | + for real_id in connection['realizations']: | |
58 | + realization = compl.realizations.get(id=real_id) | |
59 | + old_phrase_type_ref = create_phrase_type_ref(realization.frame, realization.position, | |
60 | + realization.argument, realization.alternation) | |
61 | + new_phrase_type_ref = create_phrase_type_ref(new_target['schema'], new_target['position'], | |
62 | + new_target['phrase_type'], realization.alternation) | |
63 | + if new_phrase_type_ref != old_phrase_type_ref: | |
64 | + operations.append(create_operation('disconnect', arg_ref, old_phrase_type_ref)) | |
65 | + operations.append(create_operation('connect', arg_ref, new_phrase_type_ref)) | |
66 | + return operations | |
67 | + | |
68 | +def create_argument_ref(frame, complement): | |
69 | + return 'frame_%d_comp_%d_' % (frame.id, complement.id) | |
70 | + | |
71 | +def create_phrase_type_ref(schema, position, phrase_type, alternation): | |
72 | + return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (schema.id, position.id, | |
73 | + phrase_type.id, alternation) | |
74 | + | |
75 | +def create_operation(operation, arg_ref, phrase_type_ref): | |
76 | + return {'operation': operation, 'arg': arg_ref, 'connect': phrase_type_ref} | |
77 | + | |
78 | +def get_disconnect_operations(frames, connections): | |
79 | + operations = [] | |
80 | + for frame in frames: | |
81 | + for compl in frame.complements.all(): | |
82 | + conn_dict = next((conn_dict | |
83 | + for conn_dict in connections if conn_dict['compl'] == compl.id), None) | |
84 | + for real in compl.realizations.all(): | |
85 | + if not conn_dict or not real.id in conn_dict['realizations']: | |
86 | + phrase_type_ref = create_phrase_type_ref(real.frame, real.position, | |
87 | + real.argument, real.alternation) | |
88 | + arg_ref = create_argument_ref(frame, compl) | |
89 | + operations.append(create_operation('disconnect', arg_ref, phrase_type_ref)) | |
90 | + return operations | |
91 | + | |
92 | +def update_connections(lemma_id, reconnect_operations, user): | |
93 | + modify_frames(lemma_id, reconnect_operations, user) | |
94 | + | |
95 | +def disconnect_all_examples_operations(lemma): | |
96 | + operations = [] | |
97 | + lex_units = lemma.entry_obj.lexical_units().all() | |
98 | + for lu in lex_units: | |
99 | + lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu) | |
100 | + for lu_ex in lu_examples: | |
101 | + example = lu_ex.example | |
102 | + operations.append({'operation': 'remove_example', | |
103 | + 'unit': lu.id, | |
104 | + 'example': example.id}) | |
105 | + return operations | |
106 | + | |
107 | +def connect_example_operation(example_dict, example_obj): | |
108 | + lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) | |
109 | + return {'operation': 'add_example', 'unit': lu.id, 'example': example_obj.id} | |
110 | + | |
111 | +def disconnect_example_operation(example_dict, example_obj): | |
112 | + lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) | |
113 | + return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id} | |
114 | + | |
115 | +def reconnect_examples(operations): | |
116 | + update_meanings(operations) | |
117 | + | |
0 | 118 | \ No newline at end of file |
... | ... |
dictionary/static/js/argument_form_utils.js
... | ... | @@ -11,13 +11,14 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
11 | 11 | */ |
12 | 12 | |
13 | 13 | // argument class |
14 | -function argument(id, text_rep, type) | |
14 | +function argument(id, text_rep, type, connections) | |
15 | 15 | { |
16 | 16 | this.id = id |
17 | 17 | this.text_rep = text_rep; |
18 | 18 | this.type = type; |
19 | 19 | this.error = false; |
20 | 20 | this.tooltip = ''; |
21 | + this.connections = connections; | |
21 | 22 | } |
22 | 23 | |
23 | 24 | function arguments_form_change(lastActualValueIdx, arg_id, this_form, lemma_id) { |
... | ... | @@ -160,7 +161,7 @@ function argument_form_submit() { |
160 | 161 | }, |
161 | 162 | |
162 | 163 | callback: function(result) { |
163 | - var arg = new argument(result["id"], result["text_rep"], result["type"]); | |
164 | + var arg = new argument(result["id"], result["text_rep"], result["type"], []); | |
164 | 165 | |
165 | 166 | // dodawanie argumentow |
166 | 167 | if(this_dialog.dialog( "option" , "title").startsWith("Dodawanie")) |
... | ... |
dictionary/static/js/lemma-view.js
... | ... | @@ -75,6 +75,15 @@ var nkjp_source_tab = ax_nkjp_source_vals; |
75 | 75 | function alertUserNotAuthenticated() { |
76 | 76 | error_alert('Przed wykonaniem działania odśwież okno przeglądarki, a następnie zaloguj się ponownie do narzędzia.'); |
77 | 77 | } |
78 | + | |
79 | +function resetLemmaVersions() { | |
80 | + window.frames_modif = new Array(); | |
81 | + window.frames_modif_idx = 0; | |
82 | + var lemma_version = new Lemma_Version(window.schemas, | |
83 | + window.nkjp_examples, | |
84 | + window.nkjp_lemma_examples); | |
85 | + frames_modif.push(lemma_version); | |
86 | +} | |
78 | 87 | |
79 | 88 | function initiateFrameFilters() |
80 | 89 | { |
... | ... | @@ -437,7 +446,7 @@ function load_content(id) { |
437 | 446 | window.notesNotSaved = false; |
438 | 447 | window.lemmaExNotSaved = false; |
439 | 448 | |
440 | - $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ | |
449 | + $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ | |
441 | 450 | window.lemma_id = id; |
442 | 451 | createSplitter('framesSplit','new-frame-tables', 'tabs'); |
443 | 452 | if(window.can_modify) |
... | ... | @@ -578,9 +587,10 @@ function Nkjp_example(example_id, frame_id, arguments_ids, sentence, source, opi |
578 | 587 | this.opinion = opinion; |
579 | 588 | this.comment = comment; |
580 | 589 | this.semantic = semantic; |
590 | + this.lexical_unit = -1; | |
581 | 591 | } |
582 | 592 | |
583 | -function Nkjp_example_ajax(frame, arg_selections, sentence, source, opinion, comment, semantic) | |
593 | +function Nkjp_example_ajax(frame, arg_selections, sentence, source, opinion, comment, semantic, lexical_unit) | |
584 | 594 | { |
585 | 595 | this.frame = frame; |
586 | 596 | this.arg_selections = arg_selections; |
... | ... | @@ -589,6 +599,7 @@ function Nkjp_example_ajax(frame, arg_selections, sentence, source, opinion, com |
589 | 599 | this.opinion = opinion; |
590 | 600 | this.comment = comment; |
591 | 601 | this.semantic = semantic; |
602 | + this.lexical_unit = lexical_unit; | |
592 | 603 | } |
593 | 604 | |
594 | 605 | function Nkjp_ArgSelection(position, arguments) |
... | ... | @@ -629,7 +640,7 @@ function frameToTableRows(frame) |
629 | 640 | arguments_row.push(frame.positions[i].arguments[arg_number]); |
630 | 641 | else |
631 | 642 | { |
632 | - arguments_row.push(new argument(new_elem_id, '', '')); | |
643 | + arguments_row.push(new argument(new_elem_id, '', '', [])); | |
633 | 644 | new_elem_id--; |
634 | 645 | } |
635 | 646 | } |
... | ... | @@ -866,8 +877,7 @@ function needConfirmation(nkjpInstance) { |
866 | 877 | function unpin_nkjp_example(example_tabId) |
867 | 878 | { |
868 | 879 | if(example_tabId != -1 && |
869 | - !checkIfSemChangedAndAlert() && | |
870 | - !exampleGotAssignedSemantics(example_tabId)) | |
880 | + !checkIfSemChangedAndAlert())// && !exampleGotAssignedSemantics(example_tabId)) | |
871 | 881 | { |
872 | 882 | example_id = example_tabId.replace('nkjp_', ''); |
873 | 883 | for(var i=0; i<window.nkjp_examples.length; i++) |
... | ... | @@ -992,60 +1002,6 @@ function getNkjpExampleInstance(nkjp_examples, example_id) |
992 | 1002 | return ''; |
993 | 1003 | } |
994 | 1004 | |
995 | -//////////////////////// semantics ////////////////////////////// | |
996 | - | |
997 | -function schemaGotAssignedSemantics(element_id) | |
998 | -{ | |
999 | - var semanticsAssigned = true; | |
1000 | - var id_map = parseId(element_id); | |
1001 | - var schema_id = id_map['frame_id']; | |
1002 | - if(schema_id < 0) { | |
1003 | - semanticsAssigned = false; | |
1004 | - } | |
1005 | - else { | |
1006 | - jQuery.ajax({ | |
1007 | - type: 'get', | |
1008 | - url: ajax_schema_got_assigned_semantics, | |
1009 | - data: {lemma_id: window.lemma_id, | |
1010 | - schema_id: schema_id}, | |
1011 | - success: function(result) { | |
1012 | - semanticsAssigned = result['got_assigned_semantics']; | |
1013 | - }, | |
1014 | - async: false | |
1015 | - }); | |
1016 | - } | |
1017 | - if(semanticsAssigned) { | |
1018 | - error_alert('Nie można zmodyfikować. Element jest wykorzystywany w ramkach semantycznych.'); | |
1019 | - } | |
1020 | - return semanticsAssigned; | |
1021 | -} | |
1022 | - | |
1023 | -function exampleGotAssignedSemantics(example_tab_id) | |
1024 | -{ | |
1025 | - var semanticsAssigned = true; | |
1026 | - var example_id = example_tab_id.replace('nkjp_', ''); | |
1027 | - if (example_id < 0) { | |
1028 | - semanticsAssigned = false; | |
1029 | - } | |
1030 | - else { | |
1031 | - jQuery.ajax({ | |
1032 | - type: 'get', | |
1033 | - url: ajax_example_got_assigned_semantics, | |
1034 | - data: {lemma_id: window.lemma_id, | |
1035 | - example_id: example_id}, | |
1036 | - success: function(result) { | |
1037 | - semanticsAssigned = result['got_assigned_semantics']; | |
1038 | - }, | |
1039 | - async: false | |
1040 | - }); | |
1041 | - } | |
1042 | - if(semanticsAssigned) { | |
1043 | - error_alert('Nie można zmodyfikować. Przykład jest wykorzystywany w ramkach semantycznych.'); | |
1044 | - } | |
1045 | - return semanticsAssigned; | |
1046 | -} | |
1047 | -////////////////////////////////////////////////////// | |
1048 | - | |
1049 | 1005 | function getNkjpLemmaExampleInstance(nkjp_examples, example_id) |
1050 | 1006 | { |
1051 | 1007 | var example_id = example_id.replace('nkjpLemma_', ''); |
... | ... | @@ -1058,7 +1014,7 @@ function getNkjpLemmaExampleInstance(nkjp_examples, example_id) |
1058 | 1014 | } |
1059 | 1015 | |
1060 | 1016 | function remove_semantic_example(example_id) { |
1061 | - if(example_id != -1 && !checkIfSemChangedAndAlert() && !exampleGotAssignedSemantics(example_id)) | |
1017 | + if(example_id != -1 && !checkIfSemChangedAndAlert())// && !exampleGotAssignedSemantics(example_id)) | |
1062 | 1018 | { |
1063 | 1019 | example_id = example_id.replace('nkjp_', ''); |
1064 | 1020 | for(var i=0; i<nkjp_examples.length; i++) |
... | ... | @@ -1421,7 +1377,7 @@ function add_pos_form_submit() { |
1421 | 1377 | var arguments = new Array(); |
1422 | 1378 | for(var i=0; i<argsObj.length; i++) |
1423 | 1379 | { |
1424 | - arguments.push(new argument(argsObj[i].pk, argsObj[i].fields.text_rep, argsObj[i].fields.type)); | |
1380 | + arguments.push(new argument(argsObj[i].pk, argsObj[i].fields.text_rep, argsObj[i].fields.type, [])); | |
1425 | 1381 | } |
1426 | 1382 | |
1427 | 1383 | var cats = new Array(); |
... | ... | @@ -1570,7 +1526,11 @@ function can_add_position_category(lemma_id) { |
1570 | 1526 | } |
1571 | 1527 | |
1572 | 1528 | function openEditForm(id) { |
1573 | - if(window.can_modify && !checkIfSemChangedAndAlert() && !schemaGotAssignedSemantics(id)) { | |
1529 | + if(window.can_modify && !checkIfSemChangedAndAlert()) { | |
1530 | + /*if(schemaGotAssignedSemantics(id)) { | |
1531 | + semanticsAssignedAlert(); | |
1532 | + }*/ | |
1533 | + | |
1574 | 1534 | editedFrameInstance = getFrameInstance(id, window.schemas); |
1575 | 1535 | elemInstance = getElementInstance(id, window.schemas); |
1576 | 1536 | addSyntacticFramesPerm = user_has_perm('dictionary.add_syntactic_frames'); |
... | ... | @@ -1699,7 +1659,7 @@ function convertExample(nkjp_example) |
1699 | 1659 | var convertedExample = new Nkjp_example_ajax(frame['element'], argument_selections, |
1700 | 1660 | nkjp_example.sentence, nkjp_example.source, |
1701 | 1661 | nkjp_example.opinion, nkjp_example.comment, |
1702 | - nkjp_example.semantic); | |
1662 | + nkjp_example.semantic, nkjp_example.lexical_unit); | |
1703 | 1663 | |
1704 | 1664 | return convertedExample; |
1705 | 1665 | } |
... | ... | @@ -1790,7 +1750,7 @@ function save_new_frames() { |
1790 | 1750 | data: data, |
1791 | 1751 | id: lemma_id, |
1792 | 1752 | examples: examples_data, |
1793 | - lemma_examples: lemma_examples_data | |
1753 | + lemma_examples: lemma_examples_data, | |
1794 | 1754 | }, |
1795 | 1755 | |
1796 | 1756 | callback: function(result) { |
... | ... | @@ -1954,8 +1914,7 @@ function frame_form_submit() { |
1954 | 1914 | } |
1955 | 1915 | }); |
1956 | 1916 | |
1957 | - if(window.addedFrame) | |
1958 | - { | |
1917 | + if(window.addedFrame) { | |
1959 | 1918 | frame = JSON.stringify(window.addedFrame); |
1960 | 1919 | } |
1961 | 1920 | else if(propose_phraseology) { |
... | ... | @@ -2003,9 +1962,8 @@ function frame_form_submit() { |
2003 | 1962 | |
2004 | 1963 | callback: function(result) { |
2005 | 1964 | edited_frame_id = null; |
2006 | - old_edited_frame_id = ''; | |
2007 | - if(window.addedFrame) | |
2008 | - { | |
1965 | + old_edited_frame_id = ''; | |
1966 | + if(window.addedFrame) { | |
2009 | 1967 | edited_frame = $.evalJSON($.toJSON(window.addedFrame)); |
2010 | 1968 | edited_frame = serializedObjToObj(result['frame']); |
2011 | 1969 | edited_frame.id = window.addedFrame.id; |
... | ... | @@ -2041,10 +1999,11 @@ function frame_form_submit() { |
2041 | 1999 | } |
2042 | 2000 | else { |
2043 | 2001 | edited_frame = getElementInstance(edited_id, schemas); |
2044 | - old_edited_frame_id = edited_frame['element'].id; | |
2045 | - edited_frame['element'].id = new_elem_id; | |
2046 | - edited_frame_id = new_elem_id; | |
2047 | - new_elem_id--; | |
2002 | + var old_edited_frame_id = edited_frame['element'].id; | |
2003 | + //edited_frame['element'].id = new_elem_id; tuta zmienilem | |
2004 | + edited_frame['element'].id = result['id']; | |
2005 | + edited_frame_id = edited_frame['element'].id; | |
2006 | + //new_elem_id--; | |
2048 | 2007 | edited_frame['element'].text_rep = result['text_rep']; |
2049 | 2008 | edited_frame['element'].characteristics = result['characteristics']; |
2050 | 2009 | edited_frame['element'].opinion = result['opinion']; |
... | ... | @@ -2071,7 +2030,12 @@ function frame_form_submit() { |
2071 | 2030 | HideProgressAnimation(); |
2072 | 2031 | error_alert('Wypełnij wszystkie niezbędne pola formularza.'); |
2073 | 2032 | return false; |
2074 | - } | |
2033 | + } | |
2034 | + else if (result == 'data error') { | |
2035 | + HideProgressAnimation(); | |
2036 | + error_alert('Brakuje danych do stworzenia schematu.'); | |
2037 | + return false; | |
2038 | + } | |
2075 | 2039 | else |
2076 | 2040 | { |
2077 | 2041 | HideProgressAnimation(); |
... | ... | @@ -3687,6 +3651,7 @@ function restore_lemma() { |
3687 | 3651 | to_copy_elem['type'] == 'frame') |
3688 | 3652 | { |
3689 | 3653 | var frame = $.evalJSON($.toJSON(to_copy_elem['element'])); |
3654 | + clearSemanticConnections(to_copy_elem['type'], frame); | |
3690 | 3655 | // kopiowanie schematu z podgladu (moze wymagac konwersji) |
3691 | 3656 | if(elem_in_bucket['lemma_id'] && |
3692 | 3657 | need_conversion && can_be_converted && |
... | ... | @@ -3711,6 +3676,7 @@ function restore_lemma() { |
3711 | 3676 | to_copy_elem['type'] == 'argument' && !need_conversion) |
3712 | 3677 | { |
3713 | 3678 | var argument = $.evalJSON($.toJSON(to_copy_elem['element'])); |
3679 | + clearSemanticConnections(to_copy_elem['type'], argument); | |
3714 | 3680 | argument.id = new_elem_id; |
3715 | 3681 | new_elem_id--; |
3716 | 3682 | target_elem['element'].arguments.push(argument); |
... | ... | @@ -3721,6 +3687,7 @@ function restore_lemma() { |
3721 | 3687 | to_copy_elem['type'] == 'position' && !need_conversion) |
3722 | 3688 | { |
3723 | 3689 | var position = $.evalJSON($.toJSON(to_copy_elem['element'])); |
3690 | + clearSemanticConnections(to_copy_elem['type'], position); | |
3724 | 3691 | position.id = new_elem_id; |
3725 | 3692 | new_elem_id--; |
3726 | 3693 | target_elem['element'].positions.push(position); |
... | ... | @@ -3813,8 +3780,12 @@ function restore_lemma() { |
3813 | 3780 | if(window.selected_id != -1) { |
3814 | 3781 | var assignedExamples = []; |
3815 | 3782 | if(canModifyFrame(window.selected_id, window.schemas) && |
3816 | - !checkIfSemChangedAndAlert() && | |
3817 | - !schemaGotAssignedSemantics(window.selected_id)) { | |
3783 | + !checkIfSemChangedAndAlert()) { | |
3784 | + | |
3785 | + /*if(schemaGotAssignedSemantics(window.selected_id)) { | |
3786 | + semanticsAssignedAlert(); | |
3787 | + }*/ | |
3788 | + | |
3818 | 3789 | assignedExamples = gotAssignedExample(nkjp_examples, selected_id, true); |
3819 | 3790 | if(assignedExamples.length == 0) { |
3820 | 3791 | schemas = removeFrameElement(selected_id, schemas); |
... | ... | @@ -3829,8 +3800,10 @@ function restore_lemma() { |
3829 | 3800 | |
3830 | 3801 | function addElement() { |
3831 | 3802 | if(!checkIfSemChangedAndAlert() && |
3832 | - (window.selected_id == -1 || (canModifyFrame(window.selected_id, window.schemas) && | |
3833 | - !schemaGotAssignedSemantics(window.selected_id)))) { | |
3803 | + (window.selected_id == -1 || canModifyFrame(window.selected_id, window.schemas))) { | |
3804 | + /*if(schemaGotAssignedSemantics(window.selected_id)) { | |
3805 | + semanticsAssignedAlert(); | |
3806 | + }*/ | |
3834 | 3807 | window.schemas = addFrameElementDialog(window.selected_id, window.schemas); |
3835 | 3808 | } |
3836 | 3809 | } |
... | ... | @@ -3967,8 +3940,11 @@ function restore_lemma() { |
3967 | 3940 | { |
3968 | 3941 | if(window.elem_in_bucket && !checkIfSemChangedAndAlert() && |
3969 | 3942 | (window.selected_id == -1 || |
3970 | - (canModifyFrame(window.selected_id, window.schemas) && | |
3971 | - !schemaGotAssignedSemantics(window.selected_id)))) { | |
3943 | + canModifyFrame(window.selected_id, window.schemas))) { | |
3944 | + | |
3945 | + /*if(schemaGotAssignedSemantics(window.selected_id)) { | |
3946 | + semanticsAssignedAlert(); | |
3947 | + }*/ | |
3972 | 3948 | pasteFrameElement(selected_id, elem_in_bucket, schemas); |
3973 | 3949 | } |
3974 | 3950 | } |
... | ... | @@ -3999,9 +3975,17 @@ function restore_lemma() { |
3999 | 3975 | canModifyFrame(window.selected_id, window.schemas) && |
4000 | 3976 | !checkIfSemChangedAndAlert()) |
4001 | 3977 | { |
3978 | + /*if(getElementInstance(selected_id, schemas)['type'] != 'frame' && | |
3979 | + schemaGotAssignedSemantics(selected_id)) { | |
3980 | + semanticsAssignedAlert(); | |
3981 | + return; | |
3982 | + }*/ | |
3983 | + | |
4002 | 3984 | elem_in_bucket = getElementInstance(selected_id, schemas); |
3985 | + | |
4003 | 3986 | var parent_elem = getParentInstance(selected_id, schemas); |
4004 | 3987 | var duplicate = $.evalJSON($.toJSON(elem_in_bucket['element'])); |
3988 | + clearSemanticConnections(elem_in_bucket['type'], duplicate); | |
4005 | 3989 | duplicate.id = new_elem_id; |
4006 | 3990 | new_elem_id--; |
4007 | 3991 | |
... | ... | @@ -4040,6 +4024,7 @@ function restore_lemma() { |
4040 | 4024 | && !schema['element'].is_phraseologic |
4041 | 4025 | && user_has_perm('dictionary.add_phraseologic_frames')) { |
4042 | 4026 | var duplicate = $.evalJSON($.toJSON(schema['element'])); |
4027 | + clearSemanticConnections(schema['type'], duplicate); | |
4043 | 4028 | duplicate.id = new_elem_id; |
4044 | 4029 | new_elem_id--; |
4045 | 4030 | duplicate.is_phraseologic = true; |
... | ... | @@ -4108,7 +4093,7 @@ function restore_lemma() { |
4108 | 4093 | |
4109 | 4094 | function delete_nkjp_example(example_id) |
4110 | 4095 | { |
4111 | - if(example_id != -1 && !checkIfSemChangedAndAlert() && !exampleGotAssignedSemantics(example_id)) | |
4096 | + if(example_id != -1 && !checkIfSemChangedAndAlert())// && !exampleGotAssignedSemantics(example_id)) | |
4112 | 4097 | { |
4113 | 4098 | example_id = selected_example_id.replace('nkjp_', ''); |
4114 | 4099 | for(var i=0; i<nkjp_examples.length; i++) |
... | ... | @@ -4143,8 +4128,8 @@ function restore_lemma() { |
4143 | 4128 | function delete_all_nkjp_examples(frame_id) |
4144 | 4129 | { |
4145 | 4130 | if(canModifyFrame(frame_id, window.schemas) && |
4146 | - !checkIfSemChangedAndAlert() && | |
4147 | - !schemaGotAssignedSemantics(frame_id)) { | |
4131 | + !checkIfSemChangedAndAlert())// && !schemaGotAssignedSemantics(frame_id)) | |
4132 | + { | |
4148 | 4133 | var new_example_tab = new Array(); |
4149 | 4134 | for(var i=0; i<nkjp_examples.length; i++) |
4150 | 4135 | { |
... | ... | @@ -4202,7 +4187,7 @@ function restore_lemma() { |
4202 | 4187 | |
4203 | 4188 | function modify_nkjp_example(example_id) |
4204 | 4189 | { |
4205 | - if(example_id != -1 && !checkIfSemChangedAndAlert() && !exampleGotAssignedSemantics(example_id)) | |
4190 | + if(example_id != -1 && !checkIfSemChangedAndAlert())// && !exampleGotAssignedSemantics(example_id)) | |
4206 | 4191 | { |
4207 | 4192 | var example = ''; |
4208 | 4193 | for(var i=0; i<window.nkjp_examples.length; i++) |
... | ... | @@ -5092,21 +5077,6 @@ function gridPreviewContent(isPreview) { |
5092 | 5077 | return false; |
5093 | 5078 | } |
5094 | 5079 | |
5095 | -function semanticsChanged() { | |
5096 | - if(window.frames_operations.length > 0) { | |
5097 | - return true; | |
5098 | - } | |
5099 | - return false; | |
5100 | -} | |
5101 | - | |
5102 | -function checkIfSemChangedAndAlert() { | |
5103 | - if(semanticsChanged()) { | |
5104 | - alert('Przed dokonaniem zmiany zapisz semantykę.'); | |
5105 | - return true; | |
5106 | - } | |
5107 | - return false; | |
5108 | -} | |
5109 | - | |
5110 | 5080 | ///////////////////////////////////// |
5111 | 5081 | |
5112 | 5082 | $(function(){ |
... | ... |
dictionary/static/js/semantics_coupling.js
0 → 100644
1 | +function schemaGotAssignedSemantics(element_id) { | |
2 | + var semanticsAssigned = true; | |
3 | + var id_map = parseId(element_id); | |
4 | + var schema_id = id_map['frame_id']; | |
5 | + if(schema_id < 0) { | |
6 | + semanticsAssigned = false; | |
7 | + } | |
8 | + else { | |
9 | + jQuery.ajax({ | |
10 | + type: 'get', | |
11 | + url: ajax_schema_got_assigned_semantics, | |
12 | + data: {lemma_id: window.lemma_id, | |
13 | + schema_id: schema_id}, | |
14 | + success: function(result) { | |
15 | + semanticsAssigned = result['got_assigned_semantics']; | |
16 | + }, | |
17 | + async: false | |
18 | + }); | |
19 | + } | |
20 | + return semanticsAssigned; | |
21 | +} | |
22 | + | |
23 | +function semanticsAssignedAlert() { | |
24 | + error_alert('Działaj rozważnie, element jest wykorzystywany w ramach semantycznych.'); | |
25 | +} | |
26 | + | |
27 | +function exampleGotAssignedSemantics(example_tab_id) | |
28 | +{ | |
29 | + var semanticsAssigned = true; | |
30 | + var example_id = example_tab_id.replace('nkjp_', ''); | |
31 | + if (example_id < 0) { | |
32 | + semanticsAssigned = false; | |
33 | + } | |
34 | + else { | |
35 | + jQuery.ajax({ | |
36 | + type: 'get', | |
37 | + url: ajax_example_got_assigned_semantics, | |
38 | + data: {lemma_id: window.lemma_id, | |
39 | + example_id: example_id}, | |
40 | + success: function(result) { | |
41 | + semanticsAssigned = result['got_assigned_semantics']; | |
42 | + }, | |
43 | + async: false | |
44 | + }); | |
45 | + } | |
46 | + return semanticsAssigned; | |
47 | +} | |
48 | + | |
49 | +function semanticsAssignedExampleAlert() { | |
50 | + error_alert('Działaj rozważnie, przykład jest wykorzystywany w ramach semantycznych.'); | |
51 | +} | |
52 | + | |
53 | +function semanticsChanged() { | |
54 | + if(window.frames_operations.length > 0) { | |
55 | + return true; | |
56 | + } | |
57 | + return false; | |
58 | +} | |
59 | + | |
60 | +function checkIfSemChangedAndAlert() { | |
61 | + if(semanticsChanged()) { | |
62 | + alert('Przed dokonaniem zmiany zapisz semantykę.'); | |
63 | + return true; | |
64 | + } | |
65 | + return false; | |
66 | +} | |
67 | + | |
68 | +function clearSemanticConnections(type, schemaElement) { | |
69 | + if(type == 'frame') { | |
70 | + clearSchemaConnections(schemaElement); | |
71 | + } | |
72 | + else if(type == 'position') { | |
73 | + clearPositionConnections(schemaElement); | |
74 | + } | |
75 | + else if(type == 'argument') { | |
76 | + clearPhraseTypeConnections(schemaElement); | |
77 | + } | |
78 | +} | |
79 | + | |
80 | +function clearSchemaConnections(schema) { | |
81 | + for(var i=0; i<schema.positions.length; i++) { | |
82 | + clearPositionConnections(schema.positions[i]); | |
83 | + } | |
84 | +} | |
85 | + | |
86 | +function clearPositionConnections(position) { | |
87 | + for(var i=0; i<position.arguments.length; i++) { | |
88 | + clearPhraseTypeConnections(position.arguments[i]); | |
89 | + } | |
90 | +} | |
91 | + | |
92 | +function clearPhraseTypeConnections(phraseType) { | |
93 | + phraseType.connections = []; | |
94 | +} | |
95 | + | |
96 | +function updateSchemataConnections() { | |
97 | + $('#new-frame-tables').empty(); | |
98 | + $("#show_nkjp_table").empty(); | |
99 | + $.ajaxJSON({ | |
100 | + method: 'get', | |
101 | + url: ajax_get_schemata, | |
102 | + data: { | |
103 | + lemma_id: window.lemma_id | |
104 | + }, | |
105 | + | |
106 | + callback: function(result) { | |
107 | + window.schemas = serializedObjToObj(result['schemata']); | |
108 | + resetLemmaVersions(); | |
109 | + var frame_class = 'InactiveFrameTable'; | |
110 | + if(result['can_modify']) { | |
111 | + frame_class = 'ActiveFrameTable'; | |
112 | + } | |
113 | + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', | |
114 | + 'frame_filter', window.nkjp_examples, frame_class, | |
115 | + window.lemma_entry, window.lemma_entry); | |
116 | + }, | |
117 | + error_callback: function(xhr, status, error) { | |
118 | + error_alert(status + ': ' + error); | |
119 | + }, | |
120 | + bad_data_callback: function(result) { | |
121 | + return true; | |
122 | + }, | |
123 | + }); | |
124 | +} | |
125 | + | |
126 | +function updateExamplesConnections() { | |
127 | + $('#new-frame-tables').empty(); | |
128 | + $("#show_nkjp_table").empty(); | |
129 | + $.ajaxJSON({ | |
130 | + method: 'get', | |
131 | + url: ajax_get_examples, | |
132 | + data: { | |
133 | + lemma_id: window.lemma_id | |
134 | + }, | |
135 | + | |
136 | + callback: function(result) { | |
137 | + window.nkjp_examples = serializedNkjpToObj(result['examples']); | |
138 | + resetLemmaVersions(); | |
139 | + var frame_class = 'InactiveFrameTable'; | |
140 | + if(result['can_modify']) { | |
141 | + frame_class = 'ActiveFrameTable'; | |
142 | + } | |
143 | + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', | |
144 | + 'frame_filter', window.nkjp_examples, frame_class, | |
145 | + window.lemma_entry, window.lemma_entry); | |
146 | + }, | |
147 | + error_callback: function(xhr, status, error) { | |
148 | + error_alert(status + ': ' + error); | |
149 | + }, | |
150 | + bad_data_callback: function(result) { | |
151 | + return true; | |
152 | + }, | |
153 | + }); | |
154 | +} | |
... | ... |
dictionary/templates/lemma_status.html
1 | -<div id="lemma-status"> | |
2 | - <table class='StatusTable'> | |
3 | - <tr> | |
4 | - <td class='ColumnHeader'>Hasło:</td> | |
5 | - <td>{{lemma.entry}}</td> | |
6 | - </tr> | |
7 | - <tr> | |
8 | - <td class='ColumnHeader'>Właściciel:</td> | |
9 | - <td> | |
10 | - {% if lemma.owner %} | |
11 | - {{lemma.owner.username}} | |
12 | - {% else %} | |
13 | - brak | |
14 | - {% endif %} | |
15 | - </td> | |
16 | - </tr> | |
17 | - <tr> | |
18 | - <td class='ColumnHeader'>Frazeolog:</td> | |
19 | - <td> | |
20 | - {% if lemma.phraseologist %} | |
21 | - {{lemma.phraseologist.username}} | |
22 | - {% else %} | |
23 | - brak | |
24 | - {% endif %} | |
25 | - </td> | |
26 | - </tr> | |
27 | - <tr> | |
28 | - <td class='ColumnHeader'>Semantyk:</td> | |
29 | - <td> | |
30 | - {% if lemma.semanticist %} | |
31 | - {{lemma.semanticist.username}} | |
32 | - {% else %} | |
33 | - brak | |
34 | - {% endif %} | |
35 | - </td> | |
36 | - </tr> | |
37 | - <tr> | |
38 | - <td class='ColumnHeader'>Słownik:</td> | |
39 | - <td>{{lemma.vocabulary.name}}</td> | |
40 | - </tr> | |
41 | - <tr> | |
42 | - <td class='ColumnHeader'>Status:</td> | |
43 | - <td>{{lemma.status.status}}</td> | |
44 | - </tr> | |
45 | - <tr> | |
46 | - <td class='ColumnHeader'>Część mowy:</td> | |
47 | - <td>{{pos.name}}</td> | |
48 | - </tr> | |
49 | - </table> | |
50 | -</div> | |
51 | -<div id="lemma-status-change"> | |
52 | - {% if abort_status %} | |
53 | - <button type="button" id="{{ abort_status.id }}" style="width:120px">Zmień na "{{ abort_status.status }}"</button> | |
54 | - {% endif %} | |
55 | - {% for next_status in next_statuses %} | |
56 | - <button type="button" id="{{ next_status.id }}" style="width:120px">Zmień na "{{ next_status.status }}"</button> | |
57 | - {% endfor %} | |
1 | +<div style="display:flex;"> | |
2 | + <div> | |
3 | + <div id="lemma-status"> | |
4 | + <table class='StatusTable'> | |
5 | + <tr> | |
6 | + <td class='ColumnHeader'>Hasło:</td> | |
7 | + <td>{{lemma.entry}}</td> | |
8 | + </tr> | |
9 | + <tr> | |
10 | + <td class='ColumnHeader'>Właściciel:</td> | |
11 | + <td> | |
12 | + {% if lemma.owner %} | |
13 | + {{lemma.owner.username}} | |
14 | + {% else %} | |
15 | + brak | |
16 | + {% endif %} | |
17 | + </td> | |
18 | + </tr> | |
19 | + <tr> | |
20 | + <td class='ColumnHeader'>Frazeolog:</td> | |
21 | + <td> | |
22 | + {% if lemma.phraseologist %} | |
23 | + {{lemma.phraseologist.username}} | |
24 | + {% else %} | |
25 | + brak | |
26 | + {% endif %} | |
27 | + </td> | |
28 | + </tr> | |
29 | + <tr> | |
30 | + <td class='ColumnHeader'>Semantyk:</td> | |
31 | + <td> | |
32 | + {% if lemma.semanticist %} | |
33 | + {{lemma.semanticist.username}} | |
34 | + {% else %} | |
35 | + brak | |
36 | + {% endif %} | |
37 | + </td> | |
38 | + </tr> | |
39 | + <tr> | |
40 | + <td class='ColumnHeader'>Słownik:</td> | |
41 | + <td>{{lemma.vocabulary.name}}</td> | |
42 | + </tr> | |
43 | + <tr> | |
44 | + <td class='ColumnHeader'>Status:</td> | |
45 | + <td>{{lemma.status.status}}</td> | |
46 | + </tr> | |
47 | + <tr> | |
48 | + <td class='ColumnHeader'>Część mowy:</td> | |
49 | + <td>{{pos.name}}</td> | |
50 | + </tr> | |
51 | + </table> | |
52 | + </div> | |
53 | + <div id="lemma-status-change"> | |
54 | + {% if abort_status %} | |
55 | + <button type="button" id="{{ abort_status.id }}" style="width:120px">Zmień na "{{ abort_status.status }}"</button> | |
56 | + {% endif %} | |
57 | + {% for next_status in next_statuses %} | |
58 | + <button type="button" id="{{ next_status.id }}" style="width:120px">Zmień na "{{ next_status.status }}"</button> | |
59 | + {% endfor %} | |
60 | + </div> | |
61 | + </div> | |
62 | + {% if perms.dictionary.view_status_changes and status_changes %} | |
63 | + <div class="status-changes"> | |
64 | + <table class='ChangeControlTable' style="margin:15px;"> | |
65 | + <tr> | |
66 | + <td class='ColumnHeader'>Czas zmiany:</td> | |
67 | + <td class='ColumnHeader'>Docelowy status:</td> | |
68 | + <td class='ColumnHeader'>Osoba dokonująca zmiany:</td> | |
69 | + </tr> | |
70 | + {% for change in status_changes %} | |
71 | + <tr class='ChangeControlTableRow' id="change_{{version.id}}"> | |
72 | + <td>{{ change.date }}</td> | |
73 | + <td>{{ change.status.status }}</td> | |
74 | + <td>{{ change.changer.username }}</td> | |
75 | + </tr> | |
76 | + {% endfor %} | |
77 | + </table> | |
78 | + </div> | |
79 | + {% endif %} | |
58 | 80 | </div> |
59 | 81 | <div id="ready-note-dialog"> |
60 | 82 | </div> |
... | ... |
dictionary/templates/lemma_view.html
... | ... | @@ -18,6 +18,7 @@ |
18 | 18 | <script type="text/javascript" src="{{ STATIC_URL }}js/lib/jquery.multiselect.js"></script> |
19 | 19 | <script type="text/javascript" src="{{ STATIC_URL }}js/jqgrid-patch.js"></script> |
20 | 20 | <script type="text/javascript" src="{{ STATIC_URL }}js/lemma_grid.js"></script> |
21 | + <script type="text/javascript" src="{{ STATIC_URL }}js/semantics_coupling.js"></script> | |
21 | 22 | <script type="text/javascript" src="{{ STATIC_URL }}js/lemma-view.js"></script> |
22 | 23 | |
23 | 24 | {% endblock %} |
... | ... |
dictionary/validation.py
... | ... | @@ -418,6 +418,30 @@ def create_miss_binded_frames_msg_content(missing_frames): |
418 | 418 | message_content += '\n' |
419 | 419 | return message_content |
420 | 420 | |
421 | +####################### same positions validation ####################### | |
422 | +def validate_same_positions_schemata(lemma): | |
423 | + msg_content = '' | |
424 | + same_positions_schemata = get_same_positions_schemata(lemma) | |
425 | + if len(same_positions_schemata) > 0: | |
426 | + msg_content = same_positions_message(same_positions_schemata) | |
427 | + return msg_content | |
428 | + | |
429 | +def get_same_positions_schemata(lemma): | |
430 | + same_positions_schemata = [] | |
431 | + for schema in lemma.frames.all(): | |
432 | + for pos in schema.positions.all(): | |
433 | + if schema.positions.filter(text_rep=pos.text_rep).count() > 1: | |
434 | + same_positions_schemata.append(schema) | |
435 | + break | |
436 | + return same_positions_schemata | |
437 | + | |
438 | +def same_positions_message(same_positions_schemata): | |
439 | + message_content = u'W następujących schematach występuje więcej niż jedna identyczna pozycja:\n' | |
440 | + for schema in same_positions_schemata: | |
441 | + message_content += u'\t- [%d] %s\n' % (schema.id, schema.text_rep) | |
442 | + message_content += '\n' | |
443 | + return message_content | |
444 | + | |
421 | 445 | ####################### WALIDACJA ############################ |
422 | 446 | def get_napprv_examples(lemma): |
423 | 447 | nApprovedExamples = lemma.nkjp_examples.filter(source__confirmation_required=True, |
... | ... | @@ -436,7 +460,7 @@ def validate_examples_and_mark_errors(lemma, status_obj, selected_frame_id): |
436 | 460 | error = False |
437 | 461 | serialized_frames = [] |
438 | 462 | for frame_obj in lemma.frames.all(): |
439 | - serialized_frame = frameObjToSerializableDict(lemma, frame_obj) | |
463 | + serialized_frame = frameObjToSerializableDict(lemma, frame_obj, True) | |
440 | 464 | if selected_frame_id and frame_obj.id != selected_frame_id: |
441 | 465 | serialized_frames.append(serialized_frame) |
442 | 466 | continue |
... | ... | @@ -461,7 +485,7 @@ def validate_schemas_and_mark_errors(lemma, status, selected_frame_id): |
461 | 485 | error = False |
462 | 486 | serialized_frames = [] |
463 | 487 | for frame_obj in lemma.frames.all(): |
464 | - serialized_frame = frameObjToSerializableDict(lemma, frame_obj) | |
488 | + serialized_frame = frameObjToSerializableDict(lemma, frame_obj, True) | |
465 | 489 | if selected_frame_id and frame_obj.id != selected_frame_id: |
466 | 490 | serialized_frames.append(serialized_frame) |
467 | 491 | continue |
... | ... |
dictionary/views.py
... | ... | @@ -191,6 +191,8 @@ def lemma_view(request): |
191 | 191 | 'ajax_get_compatible_schema_chars' : reverse('get_compatible_schema_chars'), |
192 | 192 | |
193 | 193 | 'ajax_deselect_preview_tab': reverse('deselect_preview_tab'), |
194 | + 'ajax_get_schemata': reverse('get_schemata'), | |
195 | + 'ajax_get_examples': reverse('get_examples'), | |
194 | 196 | |
195 | 197 | # powiazywanie hasel (nieczasownikowe) |
196 | 198 | 'ajax_relate_entries' : reverse('relate_entries'), |
... | ... |
semantics/admin.py
1 | 1 | from django.contrib import admin |
2 | 2 | |
3 | -from models import FramePosition, SemanticRole, SelectivePreferenceRelations, \ | |
4 | - SemanticRolesDisplay, GeneralSelectivePreference | |
3 | +from models import FramePosition, GeneralSelectivePreference, LexicalUnitExamples, \ | |
4 | + SelectivePreferenceRelations, SemanticFrame, SemanticRole, \ | |
5 | + SemanticRolesDisplay | |
6 | + | |
5 | 7 | |
6 | 8 | |
7 | 9 | class SemanticRoleAdmin(admin.ModelAdmin): |
8 | 10 | search_fields = ('role',) |
9 | 11 | |
10 | -admin.site.register(GeneralSelectivePreference) | |
11 | 12 | admin.site.register(FramePosition) |
13 | +admin.site.register(GeneralSelectivePreference) | |
14 | +admin.site.register(LexicalUnitExamples) | |
15 | +admin.site.register(SemanticFrame) | |
12 | 16 | admin.site.register(SelectivePreferenceRelations) |
13 | 17 | admin.site.register(SemanticRolesDisplay) |
14 | 18 | admin.site.register(SemanticRole, SemanticRoleAdmin) |
... | ... |
semantics/management/commands/find_hanging_connections.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +import datetime | |
4 | + | |
5 | +from django.core.management.base import BaseCommand | |
6 | + | |
7 | +from dictionary.models import Lemma | |
8 | + | |
9 | +class Command(BaseCommand): | |
10 | + args = 'none' | |
11 | + help = "" | |
12 | + | |
13 | + def handle(self, **options): | |
14 | + find_hanging_connections() | |
15 | + | |
16 | +def find_hanging_connections(): | |
17 | + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') | |
18 | + for lemma in lemmas: | |
19 | + frames = lemma.entry_obj.actual_frames() | |
20 | + for frame in frames: | |
21 | + for compl in frame.complements.all(): | |
22 | + for real in compl.realizations.all(): | |
23 | + match = False | |
24 | + matching_schemata = lemma.frames.filter(id=real.frame.id).all() | |
25 | + for schema in matching_schemata: | |
26 | + matching_poss = schema.positions.filter(id=real.position.id, | |
27 | + arguments=real.argument) | |
28 | + if matching_poss.exists(): | |
29 | + match = True | |
30 | + break | |
31 | + if not match: | |
32 | + compl_ref = 'frame_%d_comp_%d_' % (frame.id, compl.id) | |
33 | + print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
34 | + print 'lemma: %s\tcomplement: %s\trealization: %s' % (lemma.entry_obj.name, | |
35 | + compl_ref, | |
36 | + unicode(real)) | |
37 | + | |
0 | 38 | \ No newline at end of file |
... | ... |
semantics/management/commands/find_hanging_examples.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +from django.core.management.base import BaseCommand | |
4 | + | |
5 | +from dictionary.models import Lemma | |
6 | +from semantics.models import LexicalUnitExamples | |
7 | + | |
8 | +class Command(BaseCommand): | |
9 | + args = 'none' | |
10 | + help = "" | |
11 | + | |
12 | + def handle(self, **options): | |
13 | + find_hanging_examples() | |
14 | + | |
15 | +def find_hanging_examples(): | |
16 | + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') | |
17 | + for lemma in lemmas: | |
18 | + print_hanging_examples(lemma) | |
19 | + | |
20 | +def print_hanging_examples(lemma): | |
21 | + lex_units = lemma.entry_obj.lexical_units().all() | |
22 | + for lu in lex_units: | |
23 | + lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu) | |
24 | + for lu_ex in lu_examples: | |
25 | + example = lu_ex.example | |
26 | + if not lemma.nkjp_examples.filter(id=example.id).exists(): | |
27 | + print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
28 | + print 'lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name, | |
29 | + lu_ex.id, | |
30 | + example.sentence, | |
31 | + example.id) | |
32 | + | |
0 | 33 | \ No newline at end of file |
... | ... |
semantics/models.py
... | ... | @@ -49,6 +49,11 @@ class SemanticFrame(models.Model): |
49 | 49 | return True |
50 | 50 | return False |
51 | 51 | |
52 | + def opinion_selected(self): | |
53 | + if not self.opinion: | |
54 | + return False | |
55 | + return True | |
56 | + | |
52 | 57 | def __unicode__(self): |
53 | 58 | complements_str_tab = [unicode(compl) for compl in self.complements.all()] |
54 | 59 | return u'%d --> %s' % (self.id, u'+'.join(complements_str_tab)) |
... | ... | @@ -62,6 +67,10 @@ class FramePosition(models.Model): |
62 | 67 | argument = models.ForeignKey(Argument) |
63 | 68 | # numer alternacji |
64 | 69 | alternation = models.IntegerField(default=1) |
70 | + | |
71 | + def __unicode__(self): | |
72 | + return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (self.frame.id, self.position.id, | |
73 | + self.argument.id, self.alternation) | |
65 | 74 | |
66 | 75 | class LexicalUnitExamples(models.Model): |
67 | 76 | example = models.ForeignKey(NKJP_Example) |
... | ... | @@ -110,6 +119,12 @@ class Complement(models.Model): # pola z ramki |
110 | 119 | # realizacje tego argumentu w schematach składniowych |
111 | 120 | realizations = models.ManyToManyField(FramePosition) |
112 | 121 | |
122 | + def has_only_phraseologic_realizations(self): | |
123 | + for real in self.realizations.all(): | |
124 | + if not real.argument.is_phraseologic(): | |
125 | + return False | |
126 | + return True | |
127 | + | |
113 | 128 | def __unicode__(self): |
114 | 129 | return u'%d:%s' % (self.id, self.roles.all()) |
115 | 130 | |
... | ... |
semantics/saving.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | +from django.db.models import Min | |
4 | + | |
5 | +from dictionary.models import Argument, Frame, NKJP_Example, Position | |
6 | +from semantics.change_log import store_old_versions | |
7 | +from semantics.models import Complement, GeneralSelectivePreference, FramePosition,\ | |
8 | + LexicalUnitExamples, RelationalSelectivePreference, \ | |
9 | + SelectivePreference, SelectivePreferenceRelations, \ | |
10 | + SemanticFrame, SemanticRole, FrameOpinion | |
11 | +from wordnet.models import Hypernymy, LexicalUnit, Synonymy, Synset | |
12 | + | |
13 | +def modify_frames(lemma_id, operations, user): | |
14 | + store_old_versions(lemma_id, operations, user) | |
15 | + make_operations(operations) | |
16 | + | |
17 | +def make_operations(operations): | |
18 | + translation = {'frame_id': {}, 'complement_id': {}, 'preference_id': {}} | |
19 | + for operation in operations: | |
20 | + if operation['operation'] == "create_frame": | |
21 | + luids = [int(m['id']) for m in operation['meanings']] | |
22 | + translation['frame_id'][int(operation['id'])] = create_frame(luids) | |
23 | + elif operation['operation'] == "remove_frame": | |
24 | + if int(operation['id']) in translation['frame_id']: | |
25 | + frame_id = translation['frame_id'][int(operation['id'])] | |
26 | + else: | |
27 | + frame_id = int(operation['id']) | |
28 | + remove_frame(frame_id) | |
29 | + elif operation['operation'] == "add_argument": | |
30 | + if int(operation['frame_id']) in translation['frame_id']: | |
31 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
32 | + else: | |
33 | + frame_id = int(operation['frame_id']) | |
34 | + roles = [int(r) for r in operation['role']] | |
35 | + translation['complement_id'][int(operation['id'])] = add_argument(frame_id, roles) | |
36 | + elif operation['operation'] == "remove_argument": | |
37 | + if int(operation['frame_id']) in translation['frame_id']: | |
38 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
39 | + else: | |
40 | + frame_id = int(operation['frame_id']) | |
41 | + if int(operation['complement_id']) in translation['complement_id']: | |
42 | + complement_id = translation['complement_id'][int(operation['complement_id'])] | |
43 | + else: | |
44 | + complement_id = int(operation['complement_id']) | |
45 | + remove_argument(frame_id, complement_id) | |
46 | + elif operation['operation'] == "connect": | |
47 | + frame_data = operation['arg'].split('_') | |
48 | + if int(frame_data[1]) in translation['frame_id']: | |
49 | + frame_id = translation['frame_id'][int(frame_data[1])] | |
50 | + else: | |
51 | + frame_id = int(frame_data[1]) | |
52 | + if int(frame_data[3]) in translation['complement_id']: | |
53 | + complement_id = translation['complement_id'][int(frame_data[3])] | |
54 | + else: | |
55 | + complement_id = int(frame_data[3]) | |
56 | + schema_data = operation['connect'].split('_') | |
57 | + schema_id = int(schema_data[1]) | |
58 | + position_id = int(schema_data[3]) | |
59 | + argument_id = int(schema_data[5]) | |
60 | + alternation = int(schema_data[7]) | |
61 | + connect(frame_id, complement_id, schema_id, position_id, argument_id, alternation) | |
62 | + elif operation['operation'] == "disconnect": | |
63 | + frame_data = operation['arg'].split('_') | |
64 | + if int(frame_data[1]) in translation['frame_id']: | |
65 | + frame_id = translation['frame_id'][int(frame_data[1])] | |
66 | + else: | |
67 | + frame_id = int(frame_data[1]) | |
68 | + if int(frame_data[3]) in translation['complement_id']: | |
69 | + complement_id = translation['complement_id'][int(frame_data[3])] | |
70 | + else: | |
71 | + complement_id = int(frame_data[3]) | |
72 | + schema_data = operation['connect'].split('_') | |
73 | + schema_id = int(schema_data[1]) | |
74 | + position_id = int(schema_data[3]) | |
75 | + argument_id = int(schema_data[5]) | |
76 | + alternation = int(schema_data[7]) | |
77 | + disconnect(frame_id, complement_id, schema_id, position_id, argument_id, alternation) | |
78 | + elif operation['operation'] == "assign_role": | |
79 | + if int(operation['frame_id']) in translation['frame_id']: | |
80 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
81 | + else: | |
82 | + frame_id = int(operation['frame_id']) | |
83 | + if int(operation['complement_id']) in translation['complement_id']: | |
84 | + complement_id = translation['complement_id'][int(operation['complement_id'])] | |
85 | + else: | |
86 | + complement_id = int(operation['complement_id']) | |
87 | + roles = [int(r) for r in operation['role']] | |
88 | + assign_role(frame_id, complement_id, roles) | |
89 | + elif operation['operation'] == "change_units": | |
90 | + if int(operation['frame_id']) in translation['frame_id']: | |
91 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
92 | + else: | |
93 | + frame_id = int(operation['frame_id']) | |
94 | + luids = [int(m) for m in operation['units']] | |
95 | + change_units(frame_id, luids) | |
96 | + elif operation['operation'] == "set_opinion": | |
97 | + if int(operation['frame_id']) in translation['frame_id']: | |
98 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
99 | + else: | |
100 | + frame_id = int(operation['frame_id']) | |
101 | + opinion = operation['opinion'] | |
102 | + set_opinion(frame_id, opinion) | |
103 | + elif operation['operation'] == "add_preference": | |
104 | + # {operation: 'add_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id, preference: preference} | |
105 | + if int(operation['frame_id']) in translation['frame_id']: | |
106 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
107 | + else: | |
108 | + frame_id = int(operation['frame_id']) | |
109 | + if int(operation['complement_id']) in translation['complement_id']: | |
110 | + complement_id = translation['complement_id'][int(operation['complement_id'])] | |
111 | + else: | |
112 | + complement_id = int(operation['complement_id']) | |
113 | + preference_id = add_preference(frame_id, complement_id, operation['preference']['type'], operation['preference']['content']) | |
114 | + translation['preference_id'][operation['preference_id']] = preference_id | |
115 | + elif operation['operation'] == "remove_preference": | |
116 | + # {operation: 'remove_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id} | |
117 | + if int(operation['frame_id']) in translation['frame_id']: | |
118 | + frame_id = translation['frame_id'][int(operation['frame_id'])] | |
119 | + else: | |
120 | + frame_id = int(operation['frame_id']) | |
121 | + if int(operation['complement_id']) in translation['complement_id']: | |
122 | + complement_id = translation['complement_id'][int(operation['complement_id'])] | |
123 | + else: | |
124 | + complement_id = int(operation['complement_id']) | |
125 | + if operation['preference_id'] in translation['preference_id']: | |
126 | + preference_id = translation['preference_id'][operation['preference_id']] | |
127 | + else: | |
128 | + preference_id = (operation['preference_id'][0], int(operation['preference_id'][1:])) | |
129 | + | |
130 | + remove_preference(frame_id, complement_id, preference_id) | |
131 | + else: | |
132 | + pass | |
133 | + | |
134 | +def create_frame(luids): | |
135 | + frame = SemanticFrame() | |
136 | + frame.save() | |
137 | + for id in luids: | |
138 | + lu = LexicalUnit.objects.get(id=id) | |
139 | + frame.lexical_units.add(lu) | |
140 | + return frame.id | |
141 | + | |
142 | +def add_argument(frame_id, roles): | |
143 | + if validate_roles(roles): | |
144 | + frame = SemanticFrame.objects.get(id=frame_id) | |
145 | + complement = Complement(frame=frame) | |
146 | + complement.save() | |
147 | + frame.complements.add(complement) | |
148 | + role_objects = [] | |
149 | + for r in roles: | |
150 | + role_objects.append(SemanticRole.objects.get(id=r)) | |
151 | + complement.roles = role_objects | |
152 | + return complement.id | |
153 | + | |
154 | +def remove_frame(frame_id): | |
155 | + frame = SemanticFrame.objects.get(id=frame_id) | |
156 | + frame.removed = True | |
157 | + frame.save() | |
158 | + | |
159 | +def remove_argument(frame_id, complement_id): | |
160 | + Complement.objects.get(id=complement_id).delete() | |
161 | + | |
162 | +def connect(frame_id, complement_id, schema_id, position_id, argument_id, alternation): | |
163 | + schema = Frame.objects.get(id=schema_id) | |
164 | + position = Position.objects.get(id=position_id) | |
165 | + argument = Argument.objects.get(id=argument_id) | |
166 | + fpas = FramePosition.objects.filter(frame=schema, position=position, argument=argument, alternation=alternation) | |
167 | + if len(fpas) > 0: | |
168 | + fpa = fpas[0] | |
169 | + else: | |
170 | + fpa = FramePosition(frame=schema, position=position, argument=argument, alternation=alternation) | |
171 | + fpa.save() | |
172 | + complement = Complement.objects.get(id=complement_id) | |
173 | + complement.realizations.add(fpa) | |
174 | + | |
175 | +def disconnect(frame_id, complement_id, schema_id, position_id, argument_id, alternation): | |
176 | + schema = Frame.objects.get(id=schema_id) | |
177 | + position = Position.objects.get(id=position_id) | |
178 | + argument = Argument.objects.get(id=argument_id) | |
179 | + fpas = FramePosition.objects.filter(frame=schema, position=position, argument=argument, alternation=alternation) | |
180 | + if len(fpas) > 0: | |
181 | + fpa = fpas[0] | |
182 | + else: | |
183 | + return | |
184 | + complement = Complement.objects.get(id=complement_id) | |
185 | + complement.realizations.remove(fpa) | |
186 | + | |
187 | +def assign_role(frame_id, complement_id, roles): | |
188 | + if validate_roles(roles): | |
189 | + role_objects = [] | |
190 | + for r in roles: | |
191 | + role_objects.append(SemanticRole.objects.get(id=r)) | |
192 | + complement = Complement.objects.get(id=complement_id) | |
193 | + complement.roles = role_objects | |
194 | + | |
195 | +def validate_roles(roles): | |
196 | + role_objects = [] | |
197 | + for r in roles: | |
198 | + role_objects.append(SemanticRole.objects.get(id=r)) | |
199 | + if len(role_objects) > 2: | |
200 | + return False | |
201 | + ok = False | |
202 | + for r in role_objects: | |
203 | + if not r.color == None: | |
204 | + ok = not ok | |
205 | + return ok | |
206 | + | |
207 | +def change_units(frame_id, luids): | |
208 | + frame = SemanticFrame.objects.get(id=frame_id) | |
209 | + frame.lexical_units = [] | |
210 | + for id in luids: | |
211 | + lu = LexicalUnit.objects.get(id=id) | |
212 | + frame.lexical_units.add(lu) | |
213 | + | |
214 | +def set_opinion(frame_id, opinion): | |
215 | + frame = SemanticFrame.objects.get(id=frame_id) | |
216 | + frame_opinion = FrameOpinion.objects.get(short=opinion) | |
217 | + frame.opinion = frame_opinion | |
218 | + frame.save() | |
219 | + | |
220 | +# preference_id = add_preference(frame_id, complement_id, operation['preference']['type'], operation['preference']['content']) | |
221 | +def add_preference(frame_id, complement_id, preference_type, preference_content): | |
222 | + | |
223 | + complement = Complement.objects.get(id=complement_id) | |
224 | + if complement.selective_preference is None: | |
225 | + sp = SelectivePreference() | |
226 | + sp.save() | |
227 | + complement.selective_preference = sp | |
228 | + complement.save() | |
229 | + | |
230 | + if preference_type == 'g': | |
231 | + general = GeneralSelectivePreference.objects.get(id=int(preference_content)) | |
232 | + complement.selective_preference.generals.add(general) | |
233 | + return ('g', general.id) | |
234 | + elif preference_type == 's': | |
235 | + synset = Synset.objects.get(id=int(preference_content)) | |
236 | + complement.selective_preference.synsets.add(synset) | |
237 | + return ('s', synset.id) | |
238 | + elif preference_type == 'r': | |
239 | + relation = SelectivePreferenceRelations.objects.get(id=int(preference_content['relation'])) | |
240 | + argument = [int(a) for a in preference_content['to'].split(',')] | |
241 | + frame = SemanticFrame.objects.get(id=frame_id) | |
242 | + candidates = Complement.objects.filter(frame=frame) | |
243 | + found = None | |
244 | + for c in candidates: | |
245 | + if len(c.roles.all()) == len(argument): | |
246 | + roles = [r.id for r in c.roles.all()] | |
247 | + ok = True | |
248 | + for a in argument: | |
249 | + if a not in roles: | |
250 | + ok = False | |
251 | + if ok: | |
252 | + found = c | |
253 | + break | |
254 | + if found is not None: | |
255 | + rsp = RelationalSelectivePreference(relation=relation, to=found) | |
256 | + rsp.save() | |
257 | + complement.selective_preference.relations.add(rsp) | |
258 | + return ('r', rsp.id) | |
259 | + else: | |
260 | + return -1 | |
261 | + else: | |
262 | + return -1 | |
263 | + | |
264 | +# remove_preference(frame_id, complement_id, preference) | |
265 | +def remove_preference(frame_id, complement_id, preference): | |
266 | + preference_type, preference_id = preference | |
267 | + if preference_type == 'g': | |
268 | + complement = Complement.objects.get(id=complement_id) | |
269 | + g = complement.selective_preference.generals.get(id = int(preference_id)) | |
270 | + complement.selective_preference.generals.remove(g) | |
271 | + elif preference_type == 's': | |
272 | + complement = Complement.objects.get(id=complement_id) | |
273 | + s = complement.selective_preference.synsets.get(id = int(preference_id)) | |
274 | + complement.selective_preference.synsets.remove(s) | |
275 | + elif preference_type == 'r': | |
276 | + complement = Complement.objects.get(id=complement_id) | |
277 | + r = complement.selective_preference.relations.get(id = int(preference_id)) | |
278 | + complement.selective_preference.relations.remove(r) | |
279 | + | |
280 | + | |
281 | +def update_meanings(operations): | |
282 | + translation = {} | |
283 | + for operation in operations: | |
284 | + if operation['operation'] == "set_glossa": | |
285 | + if int(operation['unit']) in translation: | |
286 | + unit = translation[int(operation['unit'])] | |
287 | + else: | |
288 | + unit = int(operation['unit']) | |
289 | + set_glossa(unit, operation['value']) | |
290 | + elif operation['operation'] == "add_example": | |
291 | + if int(operation['unit']) in translation: | |
292 | + unit = translation[int(operation['unit'])] | |
293 | + else: | |
294 | + unit = int(operation['unit']) | |
295 | + add_example(unit, operation['example']) | |
296 | + elif operation['operation'] == "remove_example": | |
297 | + if int(operation['unit']) in translation: | |
298 | + unit = translation[int(operation['unit'])] | |
299 | + else: | |
300 | + unit = int(operation['unit']) | |
301 | + remove_example(unit, operation['example']) | |
302 | + elif operation['operation'] == "add_unit": | |
303 | + translation[operation['unit']['id']] = add_unit(operation['unit']) | |
304 | + elif operation['operation'] == "remove_unit": | |
305 | + luid = int(operation['luid']) | |
306 | + if luid in translation: | |
307 | + remove_unit(translation[luid]) | |
308 | + else: | |
309 | + remove_unit(luid) | |
310 | + else: | |
311 | + pass | |
312 | + | |
313 | +def set_glossa(unit_id, new_glossa): | |
314 | + unit = LexicalUnit.objects.get(id=unit_id) | |
315 | + unit.glossa = new_glossa | |
316 | + unit.save() | |
317 | + | |
318 | +def add_example(unit_id, example_id): | |
319 | + unit = LexicalUnit.objects.get(id=unit_id) | |
320 | + nkjp_example = NKJP_Example.objects.get(id=example_id) | |
321 | + lue = LexicalUnitExamples(example=nkjp_example, lexical_unit=unit) | |
322 | + lue.save() | |
323 | + | |
324 | +def remove_example(unit_id, example_id): | |
325 | + unit = LexicalUnit.objects.get(id=unit_id) | |
326 | + nkjp_example = NKJP_Example.objects.get(id=example_id) | |
327 | + lue = LexicalUnitExamples.objects.get(example=nkjp_example, lexical_unit=unit) | |
328 | + lue.delete() | |
329 | + | |
330 | +def add_unit(unit): # returns new id | |
331 | + | |
332 | + s1 = Synset(id=(min(Synset.objects.all().aggregate(Min('id'))['id__min'], 0) - 1)) | |
333 | + s1.save() | |
334 | + lu = LexicalUnit(base=unit['base'], sense=unit['sense'], pos=unit['pos'], glossa=unit['glossa'], luid=-1, synset=s1) | |
335 | + lu.save() | |
336 | + | |
337 | + | |
338 | + if int(unit['relation']) == 1: | |
339 | + s2 = Synset.objects.get(id=int(unit['to'])) | |
340 | + r = Synonymy(parent=s1, child=s2) | |
341 | + r.save() | |
342 | + r = Synonymy(parent=s2, child=s1) | |
343 | + r.save() | |
344 | + elif int(unit['relation']) == 0: | |
345 | + s2 = Synset.objects.get(id=int(unit['to'])) | |
346 | + r = Hypernymy(parent=s1, child=s2) | |
347 | + r.save() | |
348 | + else: | |
349 | + pass | |
350 | + | |
351 | + return lu.id | |
352 | + | |
353 | +def remove_unit(luid): | |
354 | + lu = LexicalUnit.objects.get(id=luid) | |
355 | + if lu.luid is not None and lu.luid >= 0: | |
356 | + return | |
357 | + else: | |
358 | + lu.delete() | |
... | ... |
semantics/static/js/semantics_connections.js
1 | -var connected = {}; // dictionaries of connections and disconnections between frames and schemas | |
2 | -var connected_reverse = {}; | |
1 | + var connected = {}; // dictionaries of connections and disconnections between frames and schemas | |
2 | + var connected_reverse = {}; | |
3 | 3 | |
4 | 4 | function memorizeConnections(arguments_connected, frames_connection){ |
5 | 5 | connected = arguments_connected; |
... | ... |
semantics/static/js/semantics_frames.js
... | ... | @@ -463,8 +463,8 @@ function saveFrames() { |
463 | 463 | memorizeConnections(data.connections.connected, data.connections.connected_reverse); |
464 | 464 | $("#semantic-frames-count").empty(); |
465 | 465 | $("#semantic-frames-count").append(data.frames_count); |
466 | + updateSchemataConnections(); | |
466 | 467 | }); |
467 | 468 | frames_operations = []; |
468 | 469 | } |
469 | 470 | } |
470 | - | |
... | ... |
semantics/static/js/semantics_lexical_units.js
semantics/templates/opinions.json
0 → 100644
semantics/validation.py
... | ... | @@ -2,12 +2,12 @@ |
2 | 2 | |
3 | 3 | from django.db.models import Max |
4 | 4 | |
5 | -from dictionary.models import Lemma, reflex_phrase_types | |
5 | +from dictionary.models import Lemma, reflex_phrase_types, Argument_Model | |
6 | 6 | from semantics.models import LexicalUnitExamples |
7 | 7 | from semantics.utils import get_matching_frame |
8 | 8 | |
9 | 9 | def validate_frames(lemma_id): |
10 | - lemma = Lemma.objects.get(id=lemma_id, old=False) | |
10 | + lemma = Lemma.objects.get(id=lemma_id) | |
11 | 11 | actual_frames = lemma.entry_obj.actual_frames() |
12 | 12 | error_msg = u'' |
13 | 13 | for frame in actual_frames.all(): |
... | ... | @@ -21,6 +21,8 @@ def frame_valid(lemma, frame, actual_frames): |
21 | 21 | complements = frame.complements.all() |
22 | 22 | if not arguments_exists(complements): |
23 | 23 | error_msg = u'Semantyka: Rama semantyczna %d jest pusta.' % frame.id |
24 | + elif not frame.opinion_selected(): | |
25 | + error_msg = u'Semantyka: Rama semantyczna %d nie ma wybranej opinii.' % frame.id | |
24 | 26 | elif not roles_unique(complements): |
25 | 27 | error_msg = u'Semantyka: Rama semantyczna %d nie zawiera unikalnych ról.' % frame.id |
26 | 28 | elif not arguments_pinned(complements): |
... | ... | @@ -62,7 +64,9 @@ def arguments_pinned(complements): |
62 | 64 | |
63 | 65 | def preferences_selected(complements): |
64 | 66 | for complement in complements: |
65 | - if not preference_valid(complement): | |
67 | + if complement.realizations.exists() and complement.has_only_phraseologic_realizations(): | |
68 | + pass | |
69 | + elif not preference_valid(complement): | |
66 | 70 | return False |
67 | 71 | return True |
68 | 72 | |
... | ... |
semantics/views.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | -import locale | |
4 | 3 | from semantics.models import SemanticRole, SemanticFrame, Complement, \ |
5 | 4 | LexicalUnit, FrameRankings, SemanticRolesDisplay, \ |
6 | - LexicalUnitExamples, FramePosition, SelectivePreference, \ | |
7 | - RelationalSelectivePreference, SelectivePreferenceRelations, \ | |
5 | + LexicalUnitExamples, SelectivePreferenceRelations, \ | |
8 | 6 | GeneralSelectivePreference, FrameOpinion |
7 | + | |
9 | 8 | from dictionary.models import Frame_Char_Model, Lemma, Lemma_Status, \ |
10 | - sort_arguments, sort_positions, NKJP_Example, \ | |
11 | - Frame, Position, Argument | |
12 | -from wordnet.models import Hypernymy, Synonymy, Synset | |
9 | + sort_arguments, sort_positions | |
13 | 10 | from dictionary.ajax_lemma_view import user_can_modify |
14 | 11 | from django.core.exceptions import SuspiciousOperation |
15 | 12 | from django.core.urlresolvers import reverse |
16 | 13 | from django.db.models import Q |
17 | -from datetime import datetime | |
18 | -from django.db.models import Min | |
19 | 14 | |
20 | -from common.decorators import render, ajax, AjaxError | |
21 | -from semantics.change_log import store_old_versions | |
15 | +from common.decorators import render, ajax | |
16 | +from semantics.saving import modify_frames, update_meanings | |
22 | 17 | from semantics.validation import validate_schemas, validate_frames, validate_lexical_units |
23 | 18 | |
24 | 19 | |
... | ... | @@ -469,357 +464,15 @@ def ajax_create_complement(request, lemma_id, frame, roles): |
469 | 464 | |
470 | 465 | @ajax(method='get', encode_result=False) |
471 | 466 | def ajax_update_meanings(request, operations, lemma_id): |
472 | - translation = {} | |
473 | - for operation in operations: | |
474 | - if operation['operation'] == "set_glossa": | |
475 | - if int(operation['unit']) in translation: | |
476 | - unit = translation[int(operation['unit'])] | |
477 | - else: | |
478 | - unit = int(operation['unit']) | |
479 | - set_glossa(unit, operation['value']) | |
480 | - elif operation['operation'] == "add_example": | |
481 | - if int(operation['unit']) in translation: | |
482 | - unit = translation[int(operation['unit'])] | |
483 | - else: | |
484 | - unit = int(operation['unit']) | |
485 | - add_example(unit, operation['example']) | |
486 | - elif operation['operation'] == "remove_example": | |
487 | - if int(operation['unit']) in translation: | |
488 | - unit = translation[int(operation['unit'])] | |
489 | - else: | |
490 | - unit = int(operation['unit']) | |
491 | - remove_example(unit, operation['example']) | |
492 | - elif operation['operation'] == "add_unit": | |
493 | - translation[operation['unit']['id']] = add_unit(operation['unit']) | |
494 | - elif operation['operation'] == "remove_unit": | |
495 | - luid = int(operation['luid']) | |
496 | - if luid in translation: | |
497 | - remove_unit(translation[luid]) | |
498 | - else: | |
499 | - remove_unit(luid) | |
500 | - else: | |
501 | - pass | |
502 | - | |
467 | + update_meanings(operations) | |
503 | 468 | return ajax_units(request) |
504 | - | |
505 | -def set_glossa(unit_id, new_glossa): | |
506 | - unit = LexicalUnit.objects.get(id=unit_id) | |
507 | - unit.glossa = new_glossa | |
508 | - unit.save() | |
509 | - | |
510 | -def add_example(unit_id, example_id): | |
511 | - unit = LexicalUnit.objects.get(id=unit_id) | |
512 | - nkjp_example = NKJP_Example.objects.get(id=example_id) | |
513 | - lue = LexicalUnitExamples(example=nkjp_example, lexical_unit=unit) | |
514 | - lue.save() | |
515 | - | |
516 | -def remove_example(unit_id, example_id): | |
517 | - unit = LexicalUnit.objects.get(id=unit_id) | |
518 | - nkjp_example = NKJP_Example.objects.get(id=example_id) | |
519 | - lue = LexicalUnitExamples.objects.get(example=nkjp_example, lexical_unit=unit) | |
520 | - lue.delete() | |
521 | - | |
522 | -def add_unit(unit): # returns new id | |
523 | - | |
524 | - s1 = Synset(id=(min(Synset.objects.all().aggregate(Min('id'))['id__min'], 0) - 1)) | |
525 | - s1.save() | |
526 | - lu = LexicalUnit(base=unit['base'], sense=unit['sense'], pos=unit['pos'], glossa=unit['glossa'], luid=-1, synset=s1) | |
527 | - lu.save() | |
528 | - | |
529 | - | |
530 | - if int(unit['relation']) == 1: | |
531 | - s2 = Synset.objects.get(id=int(unit['to'])) | |
532 | - r = Synonymy(parent=s1, child=s2) | |
533 | - r.save() | |
534 | - r = Synonymy(parent=s2, child=s1) | |
535 | - r.save() | |
536 | - elif int(unit['relation']) == 0: | |
537 | - s2 = Synset.objects.get(id=int(unit['to'])) | |
538 | - r = Hypernymy(parent=s1, child=s2) | |
539 | - r.save() | |
540 | - else: | |
541 | - pass | |
542 | - | |
543 | - return lu.id | |
544 | - | |
545 | -def remove_unit(luid): | |
546 | - lu = LexicalUnit.objects.get(id=luid) | |
547 | - if lu.luid is not None and lu.luid >= 0: | |
548 | - return | |
549 | - else: | |
550 | - lu.delete() | |
551 | 469 | |
552 | 470 | @ajax(method='get', encode_result=False) |
553 | 471 | def ajax_modify_frames(request, operations, lemma_id): |
554 | - | |
555 | 472 | if not request.user.is_authenticated(): |
556 | 473 | return 'user logged out' |
557 | - | |
558 | - store_old_versions(lemma_id, operations, request.user) | |
559 | - | |
560 | - translation = {'frame_id': {}, 'complement_id': {}, 'preference_id': {}} | |
561 | - for operation in operations: | |
562 | - if operation['operation'] == "create_frame": | |
563 | - luids = [int(m['id']) for m in operation['meanings']] | |
564 | - translation['frame_id'][int(operation['id'])] = create_frame(luids) | |
565 | - elif operation['operation'] == "remove_frame": | |
566 | - if int(operation['id']) in translation['frame_id']: | |
567 | - frame_id = translation['frame_id'][int(operation['id'])] | |
568 | - else: | |
569 | - frame_id = int(operation['id']) | |
570 | - remove_frame(frame_id) | |
571 | - elif operation['operation'] == "add_argument": | |
572 | - if int(operation['frame_id']) in translation['frame_id']: | |
573 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
574 | - else: | |
575 | - frame_id = int(operation['frame_id']) | |
576 | - roles = [int(r) for r in operation['role']] | |
577 | - translation['complement_id'][int(operation['id'])] = add_argument(frame_id, roles) | |
578 | - elif operation['operation'] == "remove_argument": | |
579 | - if int(operation['frame_id']) in translation['frame_id']: | |
580 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
581 | - else: | |
582 | - frame_id = int(operation['frame_id']) | |
583 | - if int(operation['complement_id']) in translation['complement_id']: | |
584 | - complement_id = translation['complement_id'][int(operation['complement_id'])] | |
585 | - else: | |
586 | - complement_id = int(operation['complement_id']) | |
587 | - remove_argument(frame_id, complement_id) | |
588 | - elif operation['operation'] == "connect": | |
589 | - frame_data = operation['arg'].split('_') | |
590 | - if int(frame_data[1]) in translation['frame_id']: | |
591 | - frame_id = translation['frame_id'][int(frame_data[1])] | |
592 | - else: | |
593 | - frame_id = int(frame_data[1]) | |
594 | - if int(frame_data[3]) in translation['complement_id']: | |
595 | - complement_id = translation['complement_id'][int(frame_data[3])] | |
596 | - else: | |
597 | - complement_id = int(frame_data[3]) | |
598 | - schema_data = operation['connect'].split('_') | |
599 | - schema_id = int(schema_data[1]) | |
600 | - position_id = int(schema_data[3]) | |
601 | - argument_id = int(schema_data[5]) | |
602 | - alternation = int(schema_data[7]) | |
603 | - connect(frame_id, complement_id, schema_id, position_id, argument_id, alternation) | |
604 | - elif operation['operation'] == "disconnect": | |
605 | - frame_data = operation['arg'].split('_') | |
606 | - if int(frame_data[1]) in translation['frame_id']: | |
607 | - frame_id = translation['frame_id'][int(frame_data[1])] | |
608 | - else: | |
609 | - frame_id = int(frame_data[1]) | |
610 | - if int(frame_data[3]) in translation['complement_id']: | |
611 | - complement_id = translation['complement_id'][int(frame_data[3])] | |
612 | - else: | |
613 | - complement_id = int(frame_data[3]) | |
614 | - schema_data = operation['connect'].split('_') | |
615 | - schema_id = int(schema_data[1]) | |
616 | - position_id = int(schema_data[3]) | |
617 | - argument_id = int(schema_data[5]) | |
618 | - alternation = int(schema_data[7]) | |
619 | - disconnect(frame_id, complement_id, schema_id, position_id, argument_id, alternation) | |
620 | - elif operation['operation'] == "assign_role": | |
621 | - if int(operation['frame_id']) in translation['frame_id']: | |
622 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
623 | - else: | |
624 | - frame_id = int(operation['frame_id']) | |
625 | - if int(operation['complement_id']) in translation['complement_id']: | |
626 | - complement_id = translation['complement_id'][int(operation['complement_id'])] | |
627 | - else: | |
628 | - complement_id = int(operation['complement_id']) | |
629 | - roles = [int(r) for r in operation['role']] | |
630 | - assign_role(frame_id, complement_id, roles) | |
631 | - elif operation['operation'] == "change_units": | |
632 | - if int(operation['frame_id']) in translation['frame_id']: | |
633 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
634 | - else: | |
635 | - frame_id = int(operation['frame_id']) | |
636 | - luids = [int(m) for m in operation['units']] | |
637 | - change_units(frame_id, luids) | |
638 | - elif operation['operation'] == "set_opinion": | |
639 | - if int(operation['frame_id']) in translation['frame_id']: | |
640 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
641 | - else: | |
642 | - frame_id = int(operation['frame_id']) | |
643 | - opinion = operation['opinion'] | |
644 | - set_opinion(frame_id, opinion) | |
645 | - elif operation['operation'] == "add_preference": | |
646 | - # {operation: 'add_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id, preference: preference} | |
647 | - if int(operation['frame_id']) in translation['frame_id']: | |
648 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
649 | - else: | |
650 | - frame_id = int(operation['frame_id']) | |
651 | - if int(operation['complement_id']) in translation['complement_id']: | |
652 | - complement_id = translation['complement_id'][int(operation['complement_id'])] | |
653 | - else: | |
654 | - complement_id = int(operation['complement_id']) | |
655 | - preference_id = add_preference(frame_id, complement_id, operation['preference']['type'], operation['preference']['content']) | |
656 | - translation['preference_id'][operation['preference_id']] = preference_id | |
657 | - elif operation['operation'] == "remove_preference": | |
658 | - # {operation: 'remove_preference', frame_id: frame_id, complement_id: complement_id, preference_id: preference_id} | |
659 | - if int(operation['frame_id']) in translation['frame_id']: | |
660 | - frame_id = translation['frame_id'][int(operation['frame_id'])] | |
661 | - else: | |
662 | - frame_id = int(operation['frame_id']) | |
663 | - if int(operation['complement_id']) in translation['complement_id']: | |
664 | - complement_id = translation['complement_id'][int(operation['complement_id'])] | |
665 | - else: | |
666 | - complement_id = int(operation['complement_id']) | |
667 | - if operation['preference_id'] in translation['preference_id']: | |
668 | - preference_id = translation['preference_id'][operation['preference_id']] | |
669 | - else: | |
670 | - preference_id = (operation['preference_id'][0], int(operation['preference_id'][1:])) | |
671 | - | |
672 | - remove_preference(frame_id, complement_id, preference_id) | |
673 | - else: | |
674 | - pass | |
675 | - | |
474 | + modify_frames(lemma_id, operations, request.user) | |
676 | 475 | return ajax_frames(request) |
677 | - | |
678 | -def create_frame(luids): | |
679 | - frame = SemanticFrame() | |
680 | - frame.save() | |
681 | - for id in luids: | |
682 | - lu = LexicalUnit.objects.get(id=id) | |
683 | - frame.lexical_units.add(lu) | |
684 | - return frame.id | |
685 | - | |
686 | -def change_units(frame_id, luids): | |
687 | - frame = SemanticFrame.objects.get(id=frame_id) | |
688 | - frame.lexical_units = [] | |
689 | - for id in luids: | |
690 | - lu = LexicalUnit.objects.get(id=id) | |
691 | - frame.lexical_units.add(lu) | |
692 | - | |
693 | -def set_opinion(frame_id, opinion): | |
694 | - frame = SemanticFrame.objects.get(id=frame_id) | |
695 | - frame_opinion = FrameOpinion.objects.get(short=opinion) | |
696 | - frame.opinion = frame_opinion | |
697 | - frame.save() | |
698 | - | |
699 | -def remove_frame(frame_id): | |
700 | - frame = SemanticFrame.objects.get(id=frame_id) | |
701 | - frame.removed = True | |
702 | - frame.save() | |
703 | - | |
704 | -def add_argument(frame_id, roles): | |
705 | - if validate_roles(roles): | |
706 | - frame = SemanticFrame.objects.get(id=frame_id) | |
707 | - complement = Complement(frame=frame) | |
708 | - complement.save() | |
709 | - frame.complements.add(complement) | |
710 | - role_objects = [] | |
711 | - for r in roles: | |
712 | - role_objects.append(SemanticRole.objects.get(id=r)) | |
713 | - complement.roles = role_objects | |
714 | - return complement.id | |
715 | - | |
716 | -def remove_argument(frame_id, complement_id): | |
717 | - Complement.objects.get(id=complement_id).delete() | |
718 | - | |
719 | -def connect(frame_id, complement_id, schema_id, position_id, argument_id, alternation): | |
720 | - schema = Frame.objects.get(id=schema_id) | |
721 | - position = Position.objects.get(id=position_id) | |
722 | - argument = Argument.objects.get(id=argument_id) | |
723 | - fpas = FramePosition.objects.filter(frame=schema, position=position, argument=argument, alternation=alternation) | |
724 | - if len(fpas) > 0: | |
725 | - fpa = fpas[0] | |
726 | - else: | |
727 | - fpa = FramePosition(frame=schema, position=position, argument=argument, alternation=alternation) | |
728 | - fpa.save() | |
729 | - complement = Complement.objects.get(id=complement_id) | |
730 | - complement.realizations.add(fpa) | |
731 | - | |
732 | -def disconnect(frame_id, complement_id, schema_id, position_id, argument_id, alternation): | |
733 | - schema = Frame.objects.get(id=schema_id) | |
734 | - position = Position.objects.get(id=position_id) | |
735 | - argument = Argument.objects.get(id=argument_id) | |
736 | - fpas = FramePosition.objects.filter(frame=schema, position=position, argument=argument, alternation=alternation) | |
737 | - if len(fpas) > 0: | |
738 | - fpa = fpas[0] | |
739 | - else: | |
740 | - return | |
741 | - complement = Complement.objects.get(id=complement_id) | |
742 | - complement.realizations.remove(fpa) | |
743 | - | |
744 | -def assign_role(frame_id, complement_id, roles): | |
745 | - if validate_roles(roles): | |
746 | - role_objects = [] | |
747 | - for r in roles: | |
748 | - role_objects.append(SemanticRole.objects.get(id=r)) | |
749 | - complement = Complement.objects.get(id=complement_id) | |
750 | - complement.roles = role_objects | |
751 | - | |
752 | -def validate_roles(roles): | |
753 | - role_objects = [] | |
754 | - for r in roles: | |
755 | - role_objects.append(SemanticRole.objects.get(id=r)) | |
756 | - if len(role_objects) > 2: | |
757 | - return False | |
758 | - ok = False | |
759 | - for r in role_objects: | |
760 | - if not r.color == None: | |
761 | - ok = not ok | |
762 | - return ok | |
763 | - | |
764 | -# preference_id = add_preference(frame_id, complement_id, operation['preference']['type'], operation['preference']['content']) | |
765 | -def add_preference(frame_id, complement_id, preference_type, preference_content): | |
766 | - | |
767 | - complement = Complement.objects.get(id=complement_id) | |
768 | - if complement.selective_preference is None: | |
769 | - sp = SelectivePreference() | |
770 | - sp.save() | |
771 | - complement.selective_preference = sp | |
772 | - complement.save() | |
773 | - | |
774 | - if preference_type == 'g': | |
775 | - general = GeneralSelectivePreference.objects.get(id=int(preference_content)) | |
776 | - complement.selective_preference.generals.add(general) | |
777 | - return ('g', general.id) | |
778 | - elif preference_type == 's': | |
779 | - synset = Synset.objects.get(id=int(preference_content)) | |
780 | - complement.selective_preference.synsets.add(synset) | |
781 | - return ('s', synset.id) | |
782 | - elif preference_type == 'r': | |
783 | - relation = SelectivePreferenceRelations.objects.get(id=int(preference_content['relation'])) | |
784 | - argument = [int(a) for a in preference_content['to'].split(',')] | |
785 | - frame = SemanticFrame.objects.get(id=frame_id) | |
786 | - candidates = Complement.objects.filter(frame=frame) | |
787 | - found = None | |
788 | - for c in candidates: | |
789 | - if len(c.roles.all()) == len(argument): | |
790 | - roles = [r.id for r in c.roles.all()] | |
791 | - ok = True | |
792 | - for a in argument: | |
793 | - if a not in roles: | |
794 | - ok = False | |
795 | - if ok: | |
796 | - found = c | |
797 | - break | |
798 | - if found is not None: | |
799 | - rsp = RelationalSelectivePreference(relation=relation, to=found) | |
800 | - rsp.save() | |
801 | - complement.selective_preference.relations.add(rsp) | |
802 | - return ('r', rsp.id) | |
803 | - else: | |
804 | - return -1 | |
805 | - else: | |
806 | - return -1 | |
807 | - | |
808 | -# remove_preference(frame_id, complement_id, preference) | |
809 | -def remove_preference(frame_id, complement_id, preference): | |
810 | - preference_type, preference_id = preference | |
811 | - if preference_type == 'g': | |
812 | - complement = Complement.objects.get(id=complement_id) | |
813 | - g = complement.selective_preference.generals.get(id = int(preference_id)) | |
814 | - complement.selective_preference.generals.remove(g) | |
815 | - elif preference_type == 's': | |
816 | - complement = Complement.objects.get(id=complement_id) | |
817 | - s = complement.selective_preference.synsets.get(id = int(preference_id)) | |
818 | - complement.selective_preference.synsets.remove(s) | |
819 | - elif preference_type == 'r': | |
820 | - complement = Complement.objects.get(id=complement_id) | |
821 | - r = complement.selective_preference.relations.get(id = int(preference_id)) | |
822 | - complement.selective_preference.relations.remove(r) | |
823 | 476 | |
824 | 477 | @ajax(method='get', encode_result=True) |
825 | 478 | def ajax_plWN_context_lookup(request, term): |
... | ... | @@ -843,14 +496,17 @@ def get_ordered_lexical_units_bases(lexical_units_query): |
843 | 496 | @ajax(method='get') |
844 | 497 | def validate_semantics(request, lemma_id, new_status_id): |
845 | 498 | error_msg = '' |
846 | - try: | |
847 | - status = Lemma_Status.objects.get(id=new_status_id) | |
848 | - except Lemma_Status.DoesNotExist: | |
849 | - status = None | |
850 | - if status and status.check_semantics: | |
851 | - error_msg = validate_frames(lemma_id) | |
852 | - if not error_msg: | |
853 | - error_msg = validate_lexical_units(lemma_id) | |
854 | - if not error_msg: | |
855 | - error_msg = validate_schemas(lemma_id) | |
499 | + if Lemma.objects.get(id=lemma_id).old: | |
500 | + error_msg = u'Odśwież hasło, widoczna wersja nie jest aktualna.' | |
501 | + else: | |
502 | + try: | |
503 | + status = Lemma_Status.objects.get(id=new_status_id) | |
504 | + except Lemma_Status.DoesNotExist: | |
505 | + status = None | |
506 | + if status and status.check_semantics: | |
507 | + error_msg = validate_frames(lemma_id) | |
508 | + if not error_msg: | |
509 | + error_msg = validate_lexical_units(lemma_id) | |
510 | + if not error_msg: | |
511 | + error_msg = validate_schemas(lemma_id) | |
856 | 512 | return {'error_message': error_msg} |
... | ... |
urls.py
... | ... | @@ -121,6 +121,8 @@ urlpatterns += patterns('dictionary.ajax_lemma_view', |
121 | 121 | url(r'^ajax/user_is_authenticated/$', 'user_is_authenticated'), |
122 | 122 | |
123 | 123 | url(r'^ajax/deselect_preview_tab/$', 'deselect_preview_tab'), |
124 | + url(r'^ajax/get_schemata/$', 'get_schemata'), | |
125 | + url(r'^ajax/get_examples/$', 'get_examples'), | |
124 | 126 | |
125 | 127 | # powiazywanie hasel (nieczasownikowe) |
126 | 128 | url(r'^ajax/relate_entries/$', 'relate_entries'), |
... | ... |