Commit ba4f24621e81e5cb72d0df010e60381cd346ee80
1 parent
a131fa35
Added lemmata filters using semantic frames constrains.
Showing
24 changed files
with
714 additions
and
332 deletions
dictionary/ajax_lemma_view.py
@@ -12,6 +12,7 @@ from django.contrib.auth.models import User, Group | @@ -12,6 +12,7 @@ from django.contrib.auth.models import User, Group | ||
12 | from django.core import serializers | 12 | from django.core import serializers |
13 | 13 | ||
14 | from common.js_to_obj import frameObjToSerializableDict, jsArgToObj, jsFrameToObj, jsPosToObj | 14 | from common.js_to_obj import frameObjToSerializableDict, jsArgToObj, jsFrameToObj, jsPosToObj |
15 | +from dictionary.common_func import escape_regex | ||
15 | from dictionary.convert_frames import frame_conversion | 16 | from dictionary.convert_frames import frame_conversion |
16 | from dictionary.filtering import default_filter_rules, prepare_filter_form, \ | 17 | from dictionary.filtering import default_filter_rules, prepare_filter_form, \ |
17 | save_lemma_filters_and_get_schemata_filter_setup, \ | 18 | save_lemma_filters_and_get_schemata_filter_setup, \ |
@@ -29,7 +30,7 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ | @@ -29,7 +30,7 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ | ||
29 | sortFrameChars, sortArguments, sortPositions, \ | 30 | sortFrameChars, sortArguments, sortPositions, \ |
30 | get_or_create_position, get_schemata_by_type, pos_compatible | 31 | get_or_create_position, get_schemata_by_type, pos_compatible |
31 | from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ | 32 | from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ |
32 | - AddNkjpExampleForm, MessageForm, SortForm, FilterForm, \ | 33 | + AddNkjpExampleForm, MessageForm, SortForm, \ |
33 | SimilarLemmasNewForm, ChangeUserFunctionForm, \ | 34 | SimilarLemmasNewForm, ChangeUserFunctionForm, \ |
34 | ExampleOpinionForm, \ | 35 | ExampleOpinionForm, \ |
35 | FrameConversionForm, CreatePositionForm, AssignPhraseologicFrameForm | 36 | FrameConversionForm, CreatePositionForm, AssignPhraseologicFrameForm |
@@ -39,6 +40,7 @@ from dictionary.saving import connect_example_operation, disconnect_all_examples | @@ -39,6 +40,7 @@ from dictionary.saving import connect_example_operation, disconnect_all_examples | ||
39 | 40 | ||
40 | from common.decorators import render, ajax, AjaxError | 41 | from common.decorators import render, ajax, AjaxError |
41 | from common.util import triple_arg_poss | 42 | from common.util import triple_arg_poss |
43 | +from dictionary.filtering import filter_lemmas | ||
42 | from dictionary.validation import find_similar_frames, get_all_test_missing_frames, get_aspect_rel_lemmas, \ | 44 | from dictionary.validation import find_similar_frames, get_all_test_missing_frames, get_aspect_rel_lemmas, \ |
43 | get_wrong_aspect_frames, validate_B_frames, get_deriv_miss_frames_message, \ | 45 | get_wrong_aspect_frames, validate_B_frames, get_deriv_miss_frames_message, \ |
44 | validate_phraseology_binded_frames, validate_rule_5, \ | 46 | validate_phraseology_binded_frames, validate_rule_5, \ |
@@ -46,7 +48,7 @@ from dictionary.validation import find_similar_frames, get_all_test_missing_fram | @@ -46,7 +48,7 @@ from dictionary.validation import find_similar_frames, get_all_test_missing_fram | ||
46 | validate_schemata_for_semantics_and_mark_errors, \ | 48 | validate_schemata_for_semantics_and_mark_errors, \ |
47 | get_missing_aspects_msg, validate_same_positions_schemata | 49 | get_missing_aspects_msg, validate_same_positions_schemata |
48 | 50 | ||
49 | -from semantics.models import LexicalUnitExamples | 51 | +from semantics.models import LexicalUnitExamples, SemanticFrame |
50 | 52 | ||
51 | from wordnet.models import LexicalUnit | 53 | from wordnet.models import LexicalUnit |
52 | 54 | ||
@@ -147,7 +149,7 @@ def prepareFrameTable(frame): | @@ -147,7 +149,7 @@ def prepareFrameTable(frame): | ||
147 | 149 | ||
148 | def nkjpExamplesObjToJs(nkjp_examples, user, lemma): | 150 | def nkjpExamplesObjToJs(nkjp_examples, user, lemma): |
149 | example_dict_list = [] | 151 | example_dict_list = [] |
150 | - lexical_units = lemma.entry_obj.lexical_units() | 152 | + lexical_units = lemma.entry_obj.meanings.all() |
151 | for example in nkjp_examples: | 153 | for example in nkjp_examples: |
152 | frame = example.frame; | 154 | frame = example.frame; |
153 | frame_table_id = 'frame_'+str(frame.id)+'_' | 155 | frame_table_id = 'frame_'+str(frame.id)+'_' |
@@ -168,11 +170,6 @@ def nkjpExamplesObjToJs(nkjp_examples, user, lemma): | @@ -168,11 +170,6 @@ def nkjpExamplesObjToJs(nkjp_examples, user, lemma): | ||
168 | 170 | ||
169 | sentence = example.sentence | 171 | sentence = example.sentence |
170 | comment = example.comment | 172 | comment = example.comment |
171 | -# sentence = example.sentence.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | ||
172 | -# comment = example.comment.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | ||
173 | -# h = HTMLParser.HTMLParser() | ||
174 | -# sentence = h.unescape(sentence) | ||
175 | -# comment = h.unescape(comment) | ||
176 | 173 | ||
177 | example_dict = { 'example_id' : example.id, | 174 | example_dict = { 'example_id' : example.id, |
178 | 'frame_id' : frame_table_id, | 175 | 'frame_id' : frame_table_id, |
@@ -423,11 +420,7 @@ def examples_pinned(frame, schema_examples): | @@ -423,11 +420,7 @@ def examples_pinned(frame, schema_examples): | ||
423 | @ajax(method='get') | 420 | @ajax(method='get') |
424 | def example_got_assigned_semantics(request, lemma_id, example_id): | 421 | def example_got_assigned_semantics(request, lemma_id, example_id): |
425 | lemma = Lemma.objects.get(id=lemma_id) | 422 | lemma = Lemma.objects.get(id=lemma_id) |
426 | -# sprawdz czy najnowsza wersja | ||
427 | -# if lemma.old: | ||
428 | -# raise AjaxError('old lemma') | ||
429 | - # TODO niech lexical units beda wybierane z uzyciem Entry jak juz Tomasz to zrobi | ||
430 | - lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')) | 423 | + lexical_units = lemma.entry_obj.meanings.all() |
431 | for lu in lexical_units: | 424 | for lu in lexical_units: |
432 | if LexicalUnitExamples.objects.filter(example__id=example_id, | 425 | if LexicalUnitExamples.objects.filter(example__id=example_id, |
433 | lexical_unit=lu).exists(): | 426 | lexical_unit=lu).exists(): |
@@ -789,8 +782,7 @@ def get_sort_order(request): | @@ -789,8 +782,7 @@ def get_sort_order(request): | ||
789 | @render('filter_form.html') | 782 | @render('filter_form.html') |
790 | @ajax(method='get', encode_result=False) | 783 | @ajax(method='get', encode_result=False) |
791 | def filter_form(request): | 784 | def filter_form(request): |
792 | - form = prepare_filter_form(request) | ||
793 | - return {'form': form} | 785 | + return prepare_filter_form(request) |
794 | 786 | ||
795 | @ajax(method='post') | 787 | @ajax(method='post') |
796 | def filter_form_submit(request, form_data): | 788 | def filter_form_submit(request, form_data): |
@@ -1355,10 +1347,7 @@ def get_default_char_value(possibilities): | @@ -1355,10 +1347,7 @@ def get_default_char_value(possibilities): | ||
1355 | value = possibilities.get(default=True) | 1347 | value = possibilities.get(default=True) |
1356 | except Frame_Char_Value.DoesNotExist: | 1348 | except Frame_Char_Value.DoesNotExist: |
1357 | value = possibilities.all()[0] | 1349 | value = possibilities.all()[0] |
1358 | - return value | ||
1359 | - | ||
1360 | -def escape_regex(string): | ||
1361 | - return string.replace('(', '\(').replace(')', '\)').replace('{', '\{').replace('}', '\}').replace('[', '\[').replace(']', '\]') | 1350 | + return value |
1362 | 1351 | ||
1363 | def regex_query(string): | 1352 | def regex_query(string): |
1364 | q_query = [] | 1353 | q_query = [] |
@@ -2336,7 +2325,7 @@ def save_new_frames(request, data, id, examples, lemma_examples): | @@ -2336,7 +2325,7 @@ def save_new_frames(request, data, id, examples, lemma_examples): | ||
2336 | reconnect_examples_operations.remove(disconnect_example_operation(example, nkjp_example_obj)) | 2325 | reconnect_examples_operations.remove(disconnect_example_operation(example, nkjp_example_obj)) |
2337 | except ValueError: | 2326 | except ValueError: |
2338 | reconnect_examples_operations.append(connect_example_operation(example, nkjp_example_obj)) | 2327 | reconnect_examples_operations.append(connect_example_operation(example, nkjp_example_obj)) |
2339 | - reconnect_examples(reconnect_examples_operations) | 2328 | + reconnect_examples(new_lemma_ver, reconnect_examples_operations) |
2340 | 2329 | ||
2341 | # dodawanie przykladow nkjp do czasownika | 2330 | # dodawanie przykladow nkjp do czasownika |
2342 | for example in decoded_lemma_examples: | 2331 | for example in decoded_lemma_examples: |
@@ -2607,90 +2596,6 @@ def prepare_sort_rules(sort_rules): | @@ -2607,90 +2596,6 @@ def prepare_sort_rules(sort_rules): | ||
2607 | prepared_sort_rules.append(rule['name']) | 2596 | prepared_sort_rules.append(rule['name']) |
2608 | return prepared_sort_rules | 2597 | return prepared_sort_rules |
2609 | 2598 | ||
2610 | -def pos_regex_frames(frames, string): | ||
2611 | - try: | ||
2612 | - alternative_queries = [] | ||
2613 | - for alternative in string.split('|'): | ||
2614 | - possible_frames = frames | ||
2615 | - for conj in alternative.split('&'): | ||
2616 | - model_results = [] | ||
2617 | - negation = False | ||
2618 | - conj = conj.strip() | ||
2619 | - if conj.startswith('!'): | ||
2620 | - conj = conj.lstrip('!') | ||
2621 | - negation = True | ||
2622 | - regex = ur'^%s$' % escape_regex(conj) | ||
2623 | - model_results = Position.objects.filter(frames__lemmas__old=False, | ||
2624 | - text_rep__regex=regex).distinct() | ||
2625 | - if model_results.exists(): | ||
2626 | - if negation: | ||
2627 | - possible_frames = possible_frames.exclude(positions__in=model_results) | ||
2628 | - else: | ||
2629 | - possible_frames = possible_frames.filter(positions__in=model_results) | ||
2630 | - elif not model_results.exists() and not negation: | ||
2631 | - possible_frames = Frame.objects.none() | ||
2632 | - alternative_queries.append(Q(id__in=possible_frames)) | ||
2633 | - frames = frames.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
2634 | - except: | ||
2635 | - frames = Frame.objects.none() | ||
2636 | - return frames | ||
2637 | - | ||
2638 | -def arg_regex_frames(frames, string): | ||
2639 | - try: | ||
2640 | - alternative_queries = [] | ||
2641 | - for alternative in string.split('|'): | ||
2642 | - possible_frames = frames | ||
2643 | - for conj in alternative.split('&'): | ||
2644 | - model_results = [] | ||
2645 | - negation = False | ||
2646 | - conj = conj.strip() | ||
2647 | - if conj.startswith('!'): | ||
2648 | - conj = conj.lstrip('!') | ||
2649 | - negation = True | ||
2650 | - regex = ur'^%s$' % escape_regex(conj) | ||
2651 | - model_results = Argument.objects.filter(positions__frames__lemmas__old=False, | ||
2652 | - text_rep__regex=regex).distinct() | ||
2653 | - if model_results.exists(): | ||
2654 | - if negation: | ||
2655 | - possible_frames = possible_frames.exclude(positions__arguments__in=model_results) | ||
2656 | - else: | ||
2657 | - possible_frames = possible_frames.filter(positions__arguments__in=model_results) | ||
2658 | - elif not model_results.exists() and not negation: | ||
2659 | - possible_frames = Frame.objects.none() | ||
2660 | - alternative_queries.append(Q(id__in=possible_frames)) | ||
2661 | - frames = frames.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
2662 | - except: | ||
2663 | - frames = Frame.objects.none() | ||
2664 | - return frames | ||
2665 | - | ||
2666 | -def lemma_regex_filter(lemmas, string): | ||
2667 | - try: | ||
2668 | - alternative_queries = [] | ||
2669 | - for alternative in string.split('|'): | ||
2670 | - possible_lemmas = lemmas | ||
2671 | - for conj in alternative.split('&'): | ||
2672 | - model_results = [] | ||
2673 | - negation = False | ||
2674 | - conj = conj.strip() | ||
2675 | - if conj.startswith('!'): | ||
2676 | - conj = conj.lstrip('!') | ||
2677 | - negation = True | ||
2678 | - regex = ur'^%s$' % escape_regex(conj) | ||
2679 | - model_results = Lemma.objects.filter(old=False, | ||
2680 | - entry_obj__name__regex=regex).distinct() | ||
2681 | - if model_results.exists(): | ||
2682 | - if negation: | ||
2683 | - possible_lemmas = possible_lemmas.exclude(pk__in=model_results) | ||
2684 | - else: | ||
2685 | - possible_lemmas = possible_lemmas.filter(pk__in=model_results) | ||
2686 | - elif not model_results.exists() and not negation: | ||
2687 | - possible_lemmas = Lemma.objects.none() | ||
2688 | - alternative_queries.append(Q(id__in=possible_lemmas)) | ||
2689 | - lemmas = lemmas.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
2690 | - except: | ||
2691 | - lemmas = Lemma.objects.none() | ||
2692 | - return lemmas | ||
2693 | - | ||
2694 | def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): | 2599 | def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): |
2695 | lemmas = Lemma.objects.none() | 2600 | lemmas = Lemma.objects.none() |
2696 | if user.is_authenticated(): | 2601 | if user.is_authenticated(): |
@@ -2711,72 +2616,8 @@ def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): | @@ -2711,72 +2616,8 @@ def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): | ||
2711 | lemmas = lemmas.filter(reduce(operator.or_, q_vocab_list)) | 2616 | lemmas = lemmas.filter(reduce(operator.or_, q_vocab_list)) |
2712 | lemmas = lemmas.filter(reduce(operator.or_, q_status_list)) | 2617 | lemmas = lemmas.filter(reduce(operator.or_, q_status_list)) |
2713 | 2618 | ||
2714 | - ## filtrowanie | ||
2715 | - if filter_rules['owner']: | ||
2716 | - lemmas = lemmas.filter(owner=filter_rules['owner']) | ||
2717 | - if filter_rules['phraseologist']: | ||
2718 | - lemmas = lemmas.filter(phraseologist=filter_rules['phraseologist']) | ||
2719 | - if filter_rules['semanticist']: | ||
2720 | - lemmas = lemmas.filter(semanticist=filter_rules['semanticist']) | ||
2721 | - if filter_rules['vocabulary']: | ||
2722 | - lemmas = lemmas.filter(vocabulary=filter_rules['vocabulary']) | ||
2723 | - if filter_rules['status']: | ||
2724 | - lemmas = lemmas.filter(status=filter_rules['status']) | ||
2725 | - if filter_rules['frame_opinion']: | ||
2726 | - lemmas = lemmas.filter(frame_opinions__value=filter_rules['frame_opinion']) | ||
2727 | - if filter_rules['lemma'] and filter_rules['lemma'] != '.*': | ||
2728 | - lemmas = lemma_regex_filter(lemmas, filter_rules['lemma']) | ||
2729 | - if filter_rules['sender']: | ||
2730 | - lemmas = lemmas.filter(messages__sender=filter_rules['sender']) | ||
2731 | - if filter_rules['pos']: | ||
2732 | - lemmas = lemmas.filter(entry_obj__pos=filter_rules['pos']) | ||
2733 | - if filter_rules['contains_phraseology']: | ||
2734 | - phraseologic_lemmas = lemmas.filter(frames__phraseologic=True) | ||
2735 | - if filter_rules['contains_phraseology'] == 'yes': | ||
2736 | - lemmas = phraseologic_lemmas | ||
2737 | - else: | ||
2738 | - lemmas = lemmas.exclude(pk__in=phraseologic_lemmas) | ||
2739 | - if filter_rules['example_source']: | ||
2740 | - lemmas = lemmas.filter(Q(nkjp_examples__source=filter_rules['example_source']) & | ||
2741 | - Q(nkjp_examples__approved=False)).distinct() | ||
2742 | - napproved_examples = NKJP_Example.objects.filter(Q(source=filter_rules['example_source']) & | ||
2743 | - Q(approved=False) & | ||
2744 | - Q(lemmas__old=False) & | ||
2745 | - ~Q(approvers=user)).distinct() | ||
2746 | - | ||
2747 | - if filter_rules['approver']: | ||
2748 | - napproved_examples = napproved_examples.filter(approvers=filter_rules['approver']) | ||
2749 | - lemmas = lemmas.filter(nkjp_examples__in=napproved_examples) | ||
2750 | - lemmas = lemmas.distinct() | ||
2751 | - | ||
2752 | - frames = Frame.objects | ||
2753 | - if filter_rules['reflex']: | ||
2754 | - frames = frames.filter(characteristics=filter_rules['reflex']) | ||
2755 | - if filter_rules['negativity']: | ||
2756 | - frames = frames.filter(characteristics=filter_rules['negativity']) | ||
2757 | - if filter_rules['predicativity']: | ||
2758 | - frames = frames.filter(characteristics=filter_rules['predicativity']) | ||
2759 | - if filter_rules['aspect']: | ||
2760 | - frames = frames.filter(characteristics=filter_rules['aspect']) | ||
2761 | - if filter_rules['position'] and filter_rules['position'] != '.*': | ||
2762 | - frames = pos_regex_frames(frames, filter_rules['position']) | ||
2763 | - if filter_rules['argument'] and filter_rules['argument'] != '.*': | ||
2764 | - frames = arg_regex_frames(frames, filter_rules['argument']) | ||
2765 | - if filter_rules['schema_type']: | ||
2766 | - frames = get_schemata_by_type(filter_rules['schema_type'], frames) | ||
2767 | - | ||
2768 | - if (filter_rules['reflex'] or filter_rules['negativity'] or | ||
2769 | - filter_rules['aspect'] or filter_rules['predicativity'] or | ||
2770 | - filter_rules['schema_type'] or filter_rules['frame_opinion'] or | ||
2771 | - (filter_rules['argument'] and filter_rules['argument'] != '.*') or | ||
2772 | - (filter_rules['position'] and filter_rules['position'] != '.*')): | ||
2773 | - if filter_rules['frame_opinion']: | ||
2774 | - lemmas = lemmas.filter(frame_opinions__frame__in=frames.all(), | ||
2775 | - frame_opinions__value=filter_rules['frame_opinion']).distinct() | ||
2776 | - else: | ||
2777 | - lemmas = lemmas.filter(frames__in=frames.all()).distinct() | ||
2778 | - | ||
2779 | - lemmas = lemmas.distinct() | 2619 | + ## filtrowanie |
2620 | + lemmas = filter_lemmas(lemmas, filter_rules, user) | ||
2780 | 2621 | ||
2781 | ## sortowanie | 2622 | ## sortowanie |
2782 | entrySortDefined = False | 2623 | entrySortDefined = False |
dictionary/common_func.py
1 | #-*- coding:utf-8 -*- | 1 | #-*- coding:utf-8 -*- |
2 | 2 | ||
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | ||
4 | -#All rights reserved. | ||
5 | - | ||
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
7 | -#that the following conditions are met: | ||
8 | - | ||
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | ||
10 | -# the following disclaimer. | ||
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
13 | - | ||
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
21 | -# POSSIBILITY OF SUCH DAMAGE. | ||
22 | - | ||
23 | ''' | 3 | ''' |
24 | Common functions used in Slowal application. | 4 | Common functions used in Slowal application. |
25 | ''' | 5 | ''' |
@@ -131,4 +111,6 @@ def have_same_positions_structure(pos1, pos2): | @@ -131,4 +111,6 @@ def have_same_positions_structure(pos1, pos2): | ||
131 | if(pos1_args == pos2_args and pos1_cats==pos2_cats): | 111 | if(pos1_args == pos2_args and pos1_cats==pos2_cats): |
132 | same_structure = True | 112 | same_structure = True |
133 | return same_structure | 113 | return same_structure |
134 | - | 114 | + |
115 | +def escape_regex(string): | ||
116 | + return string.replace('(', '\(').replace(')', '\)').replace('{', '\{').replace('}', '\}').replace('[', '\[').replace(']', '\]') |
dictionary/filtering.py
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2 | 2 | ||
3 | +import operator | ||
4 | + | ||
3 | from django.contrib.auth.models import User | 5 | from django.contrib.auth.models import User |
6 | +from django.db.models import Q | ||
4 | 7 | ||
5 | from accounts.models import get_anon_profile | 8 | from accounts.models import get_anon_profile |
9 | +from dictionary.common_func import escape_regex | ||
6 | from dictionary.forms import FilterForm | 10 | from dictionary.forms import FilterForm |
7 | -from dictionary.models import Frame_Char_Model, Frame_Opinion_Value, Lemma_Status, \ | ||
8 | - NKJP_Source, POS, Vocabulary, \ | ||
9 | - get_frame_char_and_its_value | 11 | +from dictionary.models import Argument, Frame, Frame_Char_Model, Frame_Opinion_Value, \ |
12 | + Lemma, Lemma_Status, NKJP_Example, NKJP_Source, POS, \ | ||
13 | + Position, Vocabulary, \ | ||
14 | + get_frame_char_and_its_value, get_schemata_by_type | ||
15 | +from semantics.forms import GeneralSelPrefForm, RelationalSelPrefForm, RoleForm, \ | ||
16 | + SynsetSelPrefForm | ||
17 | +from semantics.models import Complement, FrameOpinion, RelationalSelectivePreference, \ | ||
18 | + SemanticFrame | ||
19 | +from wordnet.models import LexicalUnit | ||
10 | 20 | ||
11 | def schemata_filter_options(): | 21 | def schemata_filter_options(): |
12 | # pobieranie wartosci aspektu | 22 | # pobieranie wartosci aspektu |
@@ -70,9 +80,11 @@ def default_filter_rules(): | @@ -70,9 +80,11 @@ def default_filter_rules(): | ||
70 | 'aspect': None, | 80 | 'aspect': None, |
71 | 'argument': '.*', | 81 | 'argument': '.*', |
72 | 'position': '.*', | 82 | 'position': '.*', |
73 | - 'frame_opinion' : None, | 83 | + 'schema_opinion' : None, |
74 | 'sender': None, | 84 | 'sender': None, |
75 | - 'schema_type': None} | 85 | + 'schema_type': None, |
86 | + 'frame_opinion': None, | ||
87 | + 'sem_arguments': []} | ||
76 | 88 | ||
77 | def prepare_filter_form(request): | 89 | def prepare_filter_form(request): |
78 | if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | 90 | if request.session.has_key('lemma_preview') and request.session['lemma_preview']: |
@@ -121,13 +133,60 @@ def prepare_filter_form(request): | @@ -121,13 +133,60 @@ def prepare_filter_form(request): | ||
121 | sel_aspect=filter_rules['aspect'], | 133 | sel_aspect=filter_rules['aspect'], |
122 | sel_has_argument=filter_rules['argument'], | 134 | sel_has_argument=filter_rules['argument'], |
123 | sel_has_position=filter_rules['position'], | 135 | sel_has_position=filter_rules['position'], |
124 | - sel_frame_opinion=filter_rules['frame_opinion'], | 136 | + sel_schema_opinion=filter_rules['schema_opinion'], |
125 | can_confirm_example = can_confirm_example, | 137 | can_confirm_example = can_confirm_example, |
126 | sel_example_source=filter_rules['example_source'], | 138 | sel_example_source=filter_rules['example_source'], |
127 | sel_approver=filter_rules['approver'], | 139 | sel_approver=filter_rules['approver'], |
128 | sel_sender=filter_rules['sender'], | 140 | sel_sender=filter_rules['sender'], |
129 | - sel_schema_type=filter_rules['schema_type']) | ||
130 | - return form | 141 | + sel_schema_type=filter_rules['schema_type'], |
142 | + sel_frame_opinion=filter_rules['frame_opinion']) | ||
143 | + return {'form': form, | ||
144 | + 'sem_args_forms': sem_args_to_forms(filter_rules['sem_arguments'])} | ||
145 | + | ||
146 | +def sem_args_to_forms(sem_arguments): | ||
147 | + args_forms = [] | ||
148 | + first_alternative = True | ||
149 | + for alternative in sem_arguments: | ||
150 | + if first_alternative: | ||
151 | + first_alternative = False | ||
152 | + else: | ||
153 | + args_forms.append('or') | ||
154 | + for arg in alternative: | ||
155 | + args_forms.append(RoleForm(negation=arg['negation'], | ||
156 | + sel_role=arg['role'], | ||
157 | + sel_attribute=arg['attribute'], | ||
158 | + sel_preferences=get_sel_prefs_as_forms(arg))) | ||
159 | + return args_forms | ||
160 | + | ||
161 | +def get_sel_prefs_as_forms(arg): | ||
162 | + forms = [] | ||
163 | + if arg['general_prefs']: | ||
164 | + forms.extend(general_prefs_to_forms(arg['general_prefs'])) | ||
165 | + if arg['synset_prefs']: | ||
166 | + forms.extend(synset_prefs_to_forms(arg['synset_prefs'])) | ||
167 | + if arg['relational_prefs']: | ||
168 | + forms.extend(relational_prefs_to_forms(arg['relational_prefs'])) | ||
169 | + return forms | ||
170 | + | ||
171 | +def general_prefs_to_forms(prefs): | ||
172 | + forms = [] | ||
173 | + for pref in prefs: | ||
174 | + forms.append(GeneralSelPrefForm(sel_preference=pref)) | ||
175 | + return forms | ||
176 | + | ||
177 | +def synset_prefs_to_forms(prefs): | ||
178 | + forms = [] | ||
179 | + for pref in prefs: | ||
180 | + forms.append(SynsetSelPrefForm(sel_preference=pref)) | ||
181 | + return forms | ||
182 | + | ||
183 | +def relational_prefs_to_forms(prefs): | ||
184 | + forms = [] | ||
185 | + for pref in prefs: | ||
186 | + forms.append(RelationalSelPrefForm(sel_relation=pref['relation'], | ||
187 | + sel_role=pref['role'], | ||
188 | + sel_attribute=pref['attribute'])) | ||
189 | + return forms | ||
131 | 190 | ||
132 | def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | 191 | def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): |
133 | if filter_dict['pos']: | 192 | if filter_dict['pos']: |
@@ -183,17 +242,28 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | @@ -183,17 +242,28 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | ||
183 | aspect_obj, aspect_val = get_frame_char_and_its_value(filter_dict['aspect'], '*') | 242 | aspect_obj, aspect_val = get_frame_char_and_its_value(filter_dict['aspect'], '*') |
184 | pred_obj, pred_val = get_frame_char_and_its_value(filter_dict['predicativity'], '*') | 243 | pred_obj, pred_val = get_frame_char_and_its_value(filter_dict['predicativity'], '*') |
185 | 244 | ||
186 | - if filter_dict['frame_opinion']: | ||
187 | - frame_opinion_obj = Frame_Opinion_Value.objects.get(id=filter_dict['frame_opinion']) | ||
188 | - opinion_val = frame_opinion_obj.value | 245 | + if filter_dict['schema_opinion']: |
246 | + schema_opinion_obj = Frame_Opinion_Value.objects.get(id=filter_dict['schema_opinion']) | ||
247 | + opinion_val = schema_opinion_obj.value | ||
189 | else: | 248 | else: |
190 | - frame_opinion_obj = None | 249 | + schema_opinion_obj = None |
191 | opinion_val = '*' | 250 | opinion_val = '*' |
192 | 251 | ||
193 | if 'schema_type' in filter_dict: | 252 | if 'schema_type' in filter_dict: |
194 | schema_type = filter_dict['schema_type'] | 253 | schema_type = filter_dict['schema_type'] |
195 | else: | 254 | else: |
196 | schema_type = None | 255 | schema_type = None |
256 | + | ||
257 | + if filter_dict['frame_opinion']: | ||
258 | + frame_opinion = FrameOpinion.objects.get(id=filter_dict['frame_opinion']) | ||
259 | + else: | ||
260 | + frame_opinion = None | ||
261 | + | ||
262 | + if filter_dict['sem_arguments']: | ||
263 | + sem_arguments = filter_dict['sem_arguments'] | ||
264 | + else: | ||
265 | + sem_arguments = [] | ||
266 | + | ||
197 | if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | 267 | if request.session.has_key('lemma_preview') and request.session['lemma_preview']: |
198 | request.session['filter_rules_lemma_preview'] = {'pos' : pos_obj, | 268 | request.session['filter_rules_lemma_preview'] = {'pos' : pos_obj, |
199 | 'contains_phraseology': filter_dict['contains_phraseology'], | 269 | 'contains_phraseology': filter_dict['contains_phraseology'], |
@@ -211,9 +281,11 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | @@ -211,9 +281,11 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | ||
211 | 'argument' : filter_dict['has_argument'], | 281 | 'argument' : filter_dict['has_argument'], |
212 | 'position' : filter_dict['has_position'], | 282 | 'position' : filter_dict['has_position'], |
213 | 'lemma' : filter_dict['lemma'], | 283 | 'lemma' : filter_dict['lemma'], |
214 | - 'frame_opinion' : frame_opinion_obj, | 284 | + 'schema_opinion' : schema_opinion_obj, |
215 | 'sender' : sender_obj, | 285 | 'sender' : sender_obj, |
216 | - 'schema_type' : schema_type} | 286 | + 'schema_type' : schema_type, |
287 | + 'frame_opinion' : frame_opinion, | ||
288 | + 'sem_arguments' : sem_arguments} | ||
217 | else: | 289 | else: |
218 | request.session['filter_rules'] = {'pos' : pos_obj, | 290 | request.session['filter_rules'] = {'pos' : pos_obj, |
219 | 'contains_phraseology': filter_dict['contains_phraseology'], | 291 | 'contains_phraseology': filter_dict['contains_phraseology'], |
@@ -231,9 +303,11 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | @@ -231,9 +303,11 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | ||
231 | 'argument' : filter_dict['has_argument'], | 303 | 'argument' : filter_dict['has_argument'], |
232 | 'position' : filter_dict['has_position'], | 304 | 'position' : filter_dict['has_position'], |
233 | 'lemma' : filter_dict['lemma'], | 305 | 'lemma' : filter_dict['lemma'], |
234 | - 'frame_opinion' : frame_opinion_obj, | 306 | + 'schema_opinion' : schema_opinion_obj, |
235 | 'sender' : sender_obj, | 307 | 'sender' : sender_obj, |
236 | - 'schema_type' : schema_type} | 308 | + 'schema_type' : schema_type, |
309 | + 'frame_opinion' : frame_opinion, | ||
310 | + 'sem_arguments' : sem_arguments} | ||
237 | 311 | ||
238 | return {'filter_frames': filter_dict['filter_frames'], | 312 | return {'filter_frames': filter_dict['filter_frames'], |
239 | 'schema_type' : schema_type, | 313 | 'schema_type' : schema_type, |
@@ -244,3 +318,242 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | @@ -244,3 +318,242 @@ def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | ||
244 | 'aspect' : aspect_val, | 318 | 'aspect' : aspect_val, |
245 | 'position' : filter_dict['has_position'], | 319 | 'position' : filter_dict['has_position'], |
246 | 'argument' : filter_dict['has_argument']} | 320 | 'argument' : filter_dict['has_argument']} |
321 | + | ||
322 | +def filter_lemmas(lemmas, filter_rules, user): | ||
323 | + lemmas = filter_by_lemma_properties(lemmas, filter_rules, user) | ||
324 | + lemmas = filter_by_schemata(lemmas, filter_rules) | ||
325 | + lemmas = filter_by_frames(lemmas, filter_rules) | ||
326 | + return lemmas | ||
327 | + | ||
328 | +def filter_by_lemma_properties(lemmas, filter_rules, user): | ||
329 | + if filter_rules['owner']: | ||
330 | + lemmas = lemmas.filter(owner=filter_rules['owner']) | ||
331 | + if filter_rules['phraseologist']: | ||
332 | + lemmas = lemmas.filter(phraseologist=filter_rules['phraseologist']) | ||
333 | + if filter_rules['semanticist']: | ||
334 | + lemmas = lemmas.filter(semanticist=filter_rules['semanticist']) | ||
335 | + if filter_rules['vocabulary']: | ||
336 | + lemmas = lemmas.filter(vocabulary=filter_rules['vocabulary']) | ||
337 | + if filter_rules['status']: | ||
338 | + lemmas = lemmas.filter(status=filter_rules['status']) | ||
339 | + if filter_rules['schema_opinion']: | ||
340 | + lemmas = lemmas.filter(frame_opinions__value=filter_rules['schema_opinion']) | ||
341 | + if filter_rules['lemma'] and filter_rules['lemma'] != '.*': | ||
342 | + lemmas = lemma_regex_filter(lemmas, filter_rules['lemma']) | ||
343 | + if filter_rules['sender']: | ||
344 | + lemmas = lemmas.filter(messages__sender=filter_rules['sender']) | ||
345 | + if filter_rules['pos']: | ||
346 | + lemmas = lemmas.filter(entry_obj__pos=filter_rules['pos']) | ||
347 | + if filter_rules['contains_phraseology']: | ||
348 | + phraseologic_lemmas = lemmas.filter(frames__phraseologic=True) | ||
349 | + if filter_rules['contains_phraseology'] == 'yes': | ||
350 | + lemmas = phraseologic_lemmas | ||
351 | + else: | ||
352 | + lemmas = lemmas.exclude(pk__in=phraseologic_lemmas) | ||
353 | + if filter_rules['example_source']: | ||
354 | + lemmas = lemmas.filter(Q(nkjp_examples__source=filter_rules['example_source']) & | ||
355 | + Q(nkjp_examples__approved=False)).distinct() | ||
356 | + napproved_examples = NKJP_Example.objects.filter(Q(source=filter_rules['example_source']) & | ||
357 | + Q(approved=False) & | ||
358 | + Q(lemmas__old=False) & | ||
359 | + ~Q(approvers=user)).distinct() | ||
360 | + | ||
361 | + if filter_rules['approver']: | ||
362 | + napproved_examples = napproved_examples.filter(approvers=filter_rules['approver']) | ||
363 | + lemmas = lemmas.filter(nkjp_examples__in=napproved_examples) | ||
364 | + lemmas = lemmas.distinct() | ||
365 | + return lemmas | ||
366 | + | ||
367 | +def lemma_regex_filter(lemmas, string): | ||
368 | + try: | ||
369 | + alternative_queries = [] | ||
370 | + for alternative in string.split('|'): | ||
371 | + possible_lemmas = lemmas | ||
372 | + for conj in alternative.split('&'): | ||
373 | + model_results = [] | ||
374 | + negation = False | ||
375 | + conj = conj.strip() | ||
376 | + if conj.startswith('!'): | ||
377 | + conj = conj.lstrip('!') | ||
378 | + negation = True | ||
379 | + regex = ur'^%s$' % escape_regex(conj) | ||
380 | + model_results = Lemma.objects.filter(old=False, | ||
381 | + entry_obj__name__regex=regex).distinct() | ||
382 | + if model_results.exists(): | ||
383 | + if negation: | ||
384 | + possible_lemmas = possible_lemmas.exclude(pk__in=model_results) | ||
385 | + else: | ||
386 | + possible_lemmas = possible_lemmas.filter(pk__in=model_results) | ||
387 | + elif not model_results.exists() and not negation: | ||
388 | + possible_lemmas = Lemma.objects.none() | ||
389 | + alternative_queries.append(Q(id__in=possible_lemmas)) | ||
390 | + lemmas = lemmas.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
391 | + except: | ||
392 | + lemmas = Lemma.objects.none() | ||
393 | + return lemmas | ||
394 | + | ||
395 | +def filter_by_schemata(lemmas, filter_rules): | ||
396 | + schemata = Frame.objects | ||
397 | + if filter_rules['reflex']: | ||
398 | + schemata = schemata.filter(characteristics=filter_rules['reflex']) | ||
399 | + if filter_rules['negativity']: | ||
400 | + schemata = schemata.filter(characteristics=filter_rules['negativity']) | ||
401 | + if filter_rules['predicativity']: | ||
402 | + schemata = schemata.filter(characteristics=filter_rules['predicativity']) | ||
403 | + if filter_rules['aspect']: | ||
404 | + schemata = schemata.filter(characteristics=filter_rules['aspect']) | ||
405 | + if filter_rules['position'] and filter_rules['position'] != '.*': | ||
406 | + schemata = pos_regex_frames(schemata, filter_rules['position']) | ||
407 | + if filter_rules['argument'] and filter_rules['argument'] != '.*': | ||
408 | + schemata = arg_regex_frames(schemata, filter_rules['argument']) | ||
409 | + if filter_rules['schema_type']: | ||
410 | + schemata = get_schemata_by_type(filter_rules['schema_type'], schemata) | ||
411 | + | ||
412 | + if (filter_rules['reflex'] or filter_rules['negativity'] or | ||
413 | + filter_rules['aspect'] or filter_rules['predicativity'] or | ||
414 | + filter_rules['schema_type'] or filter_rules['schema_opinion'] or | ||
415 | + (filter_rules['argument'] and filter_rules['argument'] != '.*') or | ||
416 | + (filter_rules['position'] and filter_rules['position'] != '.*')): | ||
417 | + if filter_rules['schema_opinion']: | ||
418 | + lemmas = lemmas.filter(frame_opinions__frame__in=schemata.all(), | ||
419 | + frame_opinions__value=filter_rules['schema_opinion']) | ||
420 | + else: | ||
421 | + lemmas = lemmas.filter(frames__in=schemata.all()) | ||
422 | + lemmas = lemmas.distinct() | ||
423 | + return lemmas | ||
424 | + | ||
425 | +def pos_regex_frames(frames, string): | ||
426 | + try: | ||
427 | + alternative_queries = [] | ||
428 | + for alternative in string.split('|'): | ||
429 | + possible_frames = frames | ||
430 | + for conj in alternative.split('&'): | ||
431 | + model_results = [] | ||
432 | + negation = False | ||
433 | + conj = conj.strip() | ||
434 | + if conj.startswith('!'): | ||
435 | + conj = conj.lstrip('!') | ||
436 | + negation = True | ||
437 | + regex = ur'^%s$' % escape_regex(conj) | ||
438 | + model_results = Position.objects.filter(frames__lemmas__old=False, | ||
439 | + text_rep__regex=regex).distinct() | ||
440 | + if model_results.exists(): | ||
441 | + if negation: | ||
442 | + possible_frames = possible_frames.exclude(positions__in=model_results) | ||
443 | + else: | ||
444 | + possible_frames = possible_frames.filter(positions__in=model_results) | ||
445 | + elif not model_results.exists() and not negation: | ||
446 | + possible_frames = Frame.objects.none() | ||
447 | + alternative_queries.append(Q(id__in=possible_frames)) | ||
448 | + frames = frames.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
449 | + except: | ||
450 | + frames = Frame.objects.none() | ||
451 | + return frames | ||
452 | + | ||
453 | +def arg_regex_frames(frames, string): | ||
454 | + try: | ||
455 | + alternative_queries = [] | ||
456 | + for alternative in string.split('|'): | ||
457 | + possible_frames = frames | ||
458 | + for conj in alternative.split('&'): | ||
459 | + model_results = [] | ||
460 | + negation = False | ||
461 | + conj = conj.strip() | ||
462 | + if conj.startswith('!'): | ||
463 | + conj = conj.lstrip('!') | ||
464 | + negation = True | ||
465 | + regex = ur'^%s$' % escape_regex(conj) | ||
466 | + model_results = Argument.objects.filter(positions__frames__lemmas__old=False, | ||
467 | + text_rep__regex=regex).distinct() | ||
468 | + if model_results.exists(): | ||
469 | + if negation: | ||
470 | + possible_frames = possible_frames.exclude(positions__arguments__in=model_results) | ||
471 | + else: | ||
472 | + possible_frames = possible_frames.filter(positions__arguments__in=model_results) | ||
473 | + elif not model_results.exists() and not negation: | ||
474 | + possible_frames = Frame.objects.none() | ||
475 | + alternative_queries.append(Q(id__in=possible_frames)) | ||
476 | + frames = frames.filter(reduce(operator.or_, alternative_queries)).distinct() | ||
477 | + except: | ||
478 | + frames = Frame.objects.none() | ||
479 | + return frames | ||
480 | + | ||
481 | +def filter_by_frames(lemmas, filter_rules): | ||
482 | + frames = SemanticFrame.objects.filter(next__isnull=True, removed=False) | ||
483 | + if filter_rules['frame_opinion']: | ||
484 | + frames = frames.filter(opinion=filter_rules['frame_opinion']) | ||
485 | + if filter_rules['sem_arguments']: | ||
486 | + frames = get_frames_by_args_rule(frames, filter_rules['sem_arguments']) | ||
487 | + if filter_rules['frame_opinion'] or filter_rules['sem_arguments']: | ||
488 | + lemmas = lemmas.filter(entry_obj__meanings__frames__in=frames).distinct() | ||
489 | + return lemmas | ||
490 | + | ||
491 | +def get_frames_by_args_rule(frames, args_filter_rule): | ||
492 | + matching_frames = [] | ||
493 | + for alternative in args_filter_rule: | ||
494 | + alt_matching_frames = get_matching_frames(frames, alternative) | ||
495 | + matching_frames.extend(alt_matching_frames.values_list('id', flat=True)) | ||
496 | + return frames.filter(id__in=list(set(matching_frames))) | ||
497 | + | ||
498 | +def get_matching_frames(frames, arguments_rules): | ||
499 | + for rules in arguments_rules: | ||
500 | + if not rules['negation']: | ||
501 | + frames = frames.filter(complements__in=matching_complements(rules)) | ||
502 | + else: | ||
503 | + frames = frames.exclude(complements__in=matching_complements(rules)) | ||
504 | + return frames | ||
505 | + | ||
506 | +def matching_complements(filter_rules): | ||
507 | + complements = Complement.objects | ||
508 | + if filter_rules['role']: | ||
509 | + complements = complements.filter(roles=filter_rules['role']) | ||
510 | + if filter_rules['attribute']: | ||
511 | + complements = complements.filter(roles=filter_rules['attribute']) | ||
512 | + if filter_rules['general_prefs'] or filter_rules['synset_prefs'] or filter_rules['relational_prefs']: | ||
513 | + complements = complements.filter(selective_preference__isnull=False) | ||
514 | + if filter_rules['general_prefs']: | ||
515 | + complements = filter_by_general_prefs(complements, filter_rules['general_prefs']) | ||
516 | + if filter_rules['synset_prefs']: | ||
517 | + complements = filter_by_synset_prefs(complements, filter_rules['synset_prefs']) | ||
518 | + if filter_rules['relational_prefs']: | ||
519 | + complements = filter_by_relational_prefs(complements, filter_rules['relational_prefs']) | ||
520 | + return complements.all() | ||
521 | + | ||
522 | +def filter_by_general_prefs(complements, prefs): | ||
523 | + complements = complements.exclude(selective_preference__generals=None) | ||
524 | + for pref in list(set(prefs)): | ||
525 | + if pref: | ||
526 | + complements = complements.filter(selective_preference__generals=pref) | ||
527 | + return complements | ||
528 | + | ||
529 | +def filter_by_synset_prefs(complements, prefs): | ||
530 | + complements = complements.exclude(selective_preference__synsets=None) | ||
531 | + for pref in list(set(prefs)): | ||
532 | + if pref: | ||
533 | + try: | ||
534 | + pref_parts = pref.split('-') | ||
535 | + base = pref_parts[0] | ||
536 | + sense = pref_parts[1] | ||
537 | + synset = LexicalUnit.objects.get(base=base, sense=sense).synset | ||
538 | + complements = complements.filter(selective_preference__synsets=synset) | ||
539 | + except: | ||
540 | + complements = Complement.objects.none() | ||
541 | + return complements | ||
542 | + | ||
543 | +def filter_by_relational_prefs(complements, prefs): | ||
544 | + complements = complements.exclude(selective_preference__relations=None) | ||
545 | + for pref in prefs: | ||
546 | + if pref['relation'] or pref['role'] or pref['attribute']: | ||
547 | + relational_prefs = RelationalSelectivePreference.objects | ||
548 | + if pref['relation']: | ||
549 | + relational_prefs = relational_prefs.filter(relation=pref['relation']) | ||
550 | + if pref['role'] or pref['attribute']: | ||
551 | + to_complements = Complement.objects | ||
552 | + if pref['role']: | ||
553 | + to_complements = to_complements.filter(roles=pref['role']) | ||
554 | + if pref['attribute']: | ||
555 | + to_complements = to_complements.filter(roles=pref['attribute']) | ||
556 | + relational_prefs = relational_prefs.filter(to__in=to_complements.all()).distinct() | ||
557 | + complements = complements.filter(selective_preference__relations__in=relational_prefs).distinct() | ||
558 | + return complements | ||
559 | + | ||
247 | \ No newline at end of file | 560 | \ No newline at end of file |
dictionary/forms.py
1 | #-*- coding:utf-8 -*- | 1 | #-*- coding:utf-8 -*- |
2 | 2 | ||
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | ||
4 | -#All rights reserved. | ||
5 | - | ||
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
7 | -#that the following conditions are met: | ||
8 | - | ||
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | ||
10 | -# the following disclaimer. | ||
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
13 | - | ||
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
21 | -# POSSIBILITY OF SUCH DAMAGE. | ||
22 | - | ||
23 | import datetime | 3 | import datetime |
24 | 4 | ||
25 | from django.contrib.auth.forms import UserCreationForm | 5 | from django.contrib.auth.forms import UserCreationForm |
@@ -28,6 +8,7 @@ from django.db.models import Q | @@ -28,6 +8,7 @@ from django.db.models import Q | ||
28 | from django.forms import * | 8 | from django.forms import * |
29 | 9 | ||
30 | from dictionary.models import * | 10 | from dictionary.models import * |
11 | +from semantics.models import FrameOpinion | ||
31 | #Frame, Argument_Model, AttrValueSelectionMode, \ | 12 | #Frame, Argument_Model, AttrValueSelectionMode, \ |
32 | # AttrValuesSeparator, Atribute_Value, PositionCategory, \ | 13 | # AttrValuesSeparator, Atribute_Value, PositionCategory, \ |
33 | # Argument, Atribute_Model, ArgRealOpinion, Frame_Characteristic, \ | 14 | # Argument, Atribute_Model, ArgRealOpinion, Frame_Characteristic, \ |
@@ -530,11 +511,6 @@ class MessageForm(ModelForm): | @@ -530,11 +511,6 @@ class MessageForm(ModelForm): | ||
530 | 511 | ||
531 | 512 | ||
532 | ############################ sorting, filtering | 513 | ############################ sorting, filtering |
533 | - | ||
534 | -#trzeba dodac jeszcze opcje, ze zawiera tylko normalne hasla | ||
535 | -#no i filtrowanie po lematach z wykorzystaniem wyrazen regularnych | ||
536 | -# rozbić to wszystko na 3 zakładki Hasło, Schematy, Ramy | ||
537 | -# no i oczywiście dodać te pola do filtrowania schematów | ||
538 | 514 | ||
539 | class FilterForm(Form): | 515 | class FilterForm(Form): |
540 | # Lemma filters | 516 | # Lemma filters |
@@ -571,14 +547,13 @@ class FilterForm(Form): | @@ -571,14 +547,13 @@ class FilterForm(Form): | ||
571 | required=False) | 547 | required=False) |
572 | has_argument = forms.CharField(label=u'Zawiera typ frazy', required=False) | 548 | has_argument = forms.CharField(label=u'Zawiera typ frazy', required=False) |
573 | has_position = forms.CharField(label=u'Zawiera pozycję', required=False) | 549 | has_position = forms.CharField(label=u'Zawiera pozycję', required=False) |
574 | - frame_opinion = ModelChoiceField(label=u'Opinia o schemacie', queryset=Frame_Opinion_Value.objects.all(), | ||
575 | - required=False) | 550 | + schema_opinion = ModelChoiceField(label=u'Opinia o schemacie', queryset=Frame_Opinion_Value.objects.all(), |
551 | + required=False) | ||
576 | filter_frames = forms.BooleanField(label=u'Odfiltruj niepasujące schematy', initial=False, | 552 | filter_frames = forms.BooleanField(label=u'Odfiltruj niepasujące schematy', initial=False, |
577 | required=False) | 553 | required=False) |
578 | # Frame filters | 554 | # Frame filters |
579 | -# role = | ||
580 | -# selective_preferences = | ||
581 | -# opinion = | 555 | + frame_opinion = ModelChoiceField(label=u'Opinia o ramie', queryset=FrameOpinion.objects.order_by('priority'), |
556 | + required=False) | ||
582 | 557 | ||
583 | def __init__(self, users, phraseologists, semanticists, vocabularies, statuses, senders, | 558 | def __init__(self, users, phraseologists, semanticists, vocabularies, statuses, senders, |
584 | lemma='.*', sel_pos=None, contains_phraseology=None, | 559 | lemma='.*', sel_pos=None, contains_phraseology=None, |
@@ -586,8 +561,9 @@ class FilterForm(Form): | @@ -586,8 +561,9 @@ class FilterForm(Form): | ||
586 | sel_vocabulary=None, sel_status=None, sel_schema_type=None, | 561 | sel_vocabulary=None, sel_status=None, sel_schema_type=None, |
587 | sel_reflex=None, sel_negativity=None, sel_predicativity=None, | 562 | sel_reflex=None, sel_negativity=None, sel_predicativity=None, |
588 | sel_aspect=None, sel_has_argument='.*', sel_has_position='.*', | 563 | sel_aspect=None, sel_has_argument='.*', sel_has_position='.*', |
589 | - sel_frame_opinion=None, can_confirm_example=False, sel_example_source=None, | ||
590 | - sel_approver=None, sel_sender=None, *args, **kwargs): | 564 | + sel_schema_opinion=None, can_confirm_example=False, sel_example_source=None, |
565 | + sel_approver=None, sel_sender=None, | ||
566 | + sel_frame_opinion=None, *args, **kwargs): | ||
591 | super(FilterForm, self).__init__(*args, **kwargs) | 567 | super(FilterForm, self).__init__(*args, **kwargs) |
592 | 568 | ||
593 | self.fields['pos'].queryset = POS.objects.exclude(tag='unk') | 569 | self.fields['pos'].queryset = POS.objects.exclude(tag='unk') |
@@ -612,23 +588,20 @@ class FilterForm(Form): | @@ -612,23 +588,20 @@ class FilterForm(Form): | ||
612 | self.fields['example_source'].initial = None | 588 | self.fields['example_source'].initial = None |
613 | self.fields['approver'].widget = self.fields['approver'].hidden_widget() | 589 | self.fields['approver'].widget = self.fields['approver'].hidden_widget() |
614 | self.fields['approver'].initial = None | 590 | self.fields['approver'].initial = None |
615 | -# self.fields['has_old_frames_property'].initial = sel_old_property | ||
616 | self.fields['reflex'].initial = sel_reflex | 591 | self.fields['reflex'].initial = sel_reflex |
617 | self.fields['negativity'].initial = sel_negativity | 592 | self.fields['negativity'].initial = sel_negativity |
618 | self.fields['predicativity'].initial = sel_predicativity | 593 | self.fields['predicativity'].initial = sel_predicativity |
619 | self.fields['aspect'].initial = sel_aspect | 594 | self.fields['aspect'].initial = sel_aspect |
620 | self.fields['has_argument'].initial = sel_has_argument | 595 | self.fields['has_argument'].initial = sel_has_argument |
621 | self.fields['has_position'].initial = sel_has_position | 596 | self.fields['has_position'].initial = sel_has_position |
622 | - #self.fields['has_frame'].initial = sel_has_frame | ||
623 | - self.fields['frame_opinion'].initial = sel_frame_opinion | 597 | + self.fields['schema_opinion'].initial = sel_schema_opinion |
624 | self.fields['has_message_from'].initial = sel_sender | 598 | self.fields['has_message_from'].initial = sel_sender |
625 | self.fields['has_message_from'].queryset = senders | 599 | self.fields['has_message_from'].queryset = senders |
626 | 600 | ||
627 | self.fields['schema_type'].initial = sel_schema_type | 601 | self.fields['schema_type'].initial = sel_schema_type |
602 | + self.fields['frame_opinion'].initial = sel_frame_opinion | ||
628 | 603 | ||
629 | self.hide_unused_fields() | 604 | self.hide_unused_fields() |
630 | - | ||
631 | - #self.fields['has_frame'].widget = self.fields['has_frame'].hidden_widget() | ||
632 | 605 | ||
633 | def hide_unused_fields(self): | 606 | def hide_unused_fields(self): |
634 | for field_name in self.fields: | 607 | for field_name in self.fields: |
dictionary/models.py
1 | #-*- coding:utf-8 -*- | 1 | #-*- coding:utf-8 -*- |
2 | 2 | ||
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | ||
4 | -#All rights reserved. | ||
5 | - | ||
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
7 | -#that the following conditions are met: | ||
8 | - | ||
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | ||
10 | -# the following disclaimer. | ||
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
13 | - | ||
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
21 | -# POSSIBILITY OF SUCH DAMAGE. | ||
22 | - | ||
23 | from django.contrib.auth.models import User | 3 | from django.contrib.auth.models import User |
24 | from django.db.models import * | 4 | from django.db.models import * |
25 | 5 | ||
26 | -from wordnet.models import LexicalUnit | ||
27 | - | ||
28 | class Configuration(Model): | 6 | class Configuration(Model): |
29 | name = CharField(max_length=16, primary_key=True, unique=True, db_column='nazwa_konfiguracji') | 7 | name = CharField(max_length=16, primary_key=True, unique=True, db_column='nazwa_konfiguracji') |
30 | selected_conf = BooleanField(db_column='wybrana_konfiguracja', default=False) | 8 | selected_conf = BooleanField(db_column='wybrana_konfiguracja', default=False) |
@@ -766,13 +744,6 @@ class Argument(Model): | @@ -766,13 +744,6 @@ class Argument(Model): | ||
766 | break | 744 | break |
767 | return is_fully_lexicalized | 745 | return is_fully_lexicalized |
768 | 746 | ||
769 | - class Meta: | ||
770 | - permissions = ( | ||
771 | - ('view_realization', u'Może oglądać realizacje argumentów.'), | ||
772 | - ('create_realization', u'Może kreować realizacje argumentów.'), | ||
773 | - ('view_arg_stats', u'Może oglądać statystyki argumentów.'), | ||
774 | - ) | ||
775 | - | ||
776 | def __unicode__(self): | 747 | def __unicode__(self): |
777 | return '%s' % (self.text_rep) | 748 | return '%s' % (self.text_rep) |
778 | 749 | ||
@@ -785,7 +756,21 @@ class Argument(Model): | @@ -785,7 +756,21 @@ class Argument(Model): | ||
785 | for value in attr.values.filter(type__sym_name=u'parameter'): | 756 | for value in attr.values.filter(type__sym_name=u'parameter'): |
786 | if value.parameter.type.realization_only: | 757 | if value.parameter.type.realization_only: |
787 | return True | 758 | return True |
788 | - return False | 759 | + return False |
760 | + | ||
761 | + def main_phrase_type(self): | ||
762 | + category_attrs = self.atributes.filter(type=u'KATEGORIA') | ||
763 | + if not category_attrs.exists() or category_attrs.all()[0].values.count() == 0: # xp bez podtypow | ||
764 | + return self | ||
765 | + else: | ||
766 | + return Argument.objects.get(text_rep=u'%s(%s)' % (self.type, category_attrs.all()[0].selection_mode.name)) | ||
767 | + | ||
768 | + class Meta: | ||
769 | + permissions = ( | ||
770 | + ('view_realization', u'Może oglądać realizacje argumentów.'), | ||
771 | + ('create_realization', u'Może kreować realizacje argumentów.'), | ||
772 | + ('view_arg_stats', u'Może oglądać statystyki argumentów.'), | ||
773 | + ) | ||
789 | 774 | ||
790 | def sort_arguments(arguments): | 775 | def sort_arguments(arguments): |
791 | return sortArguments(arguments) | 776 | return sortArguments(arguments) |
@@ -1403,12 +1388,9 @@ class Entry(Model): | @@ -1403,12 +1388,9 @@ class Entry(Model): | ||
1403 | ('view_semantics', u'Może oglądać semantykę.'), | 1388 | ('view_semantics', u'Może oglądać semantykę.'), |
1404 | ) | 1389 | ) |
1405 | 1390 | ||
1406 | - def lexical_units(self): | ||
1407 | - return LexicalUnit.objects.filter(Q(base = self.name)|Q(base = self.name + u' się')) | ||
1408 | - | ||
1409 | def actual_frames(self): | 1391 | def actual_frames(self): |
1410 | frame_ids = [] | 1392 | frame_ids = [] |
1411 | - lexical_units = self.lexical_units().order_by('sense') | 1393 | + lexical_units = self.meanings.order_by('sense') |
1412 | for lexical_unit in lexical_units: | 1394 | for lexical_unit in lexical_units: |
1413 | frame_ids.extend([f.id for f in lexical_unit.actual_frames()]) | 1395 | frame_ids.extend([f.id for f in lexical_unit.actual_frames()]) |
1414 | return get_model('semantics', 'SemanticFrame').objects.filter(id__in=list(set(frame_ids))) | 1396 | return get_model('semantics', 'SemanticFrame').objects.filter(id__in=list(set(frame_ids))) |
dictionary/saving.py
@@ -94,7 +94,7 @@ def update_connections(lemma_id, reconnect_operations, user): | @@ -94,7 +94,7 @@ def update_connections(lemma_id, reconnect_operations, user): | ||
94 | 94 | ||
95 | def disconnect_all_examples_operations(lemma): | 95 | def disconnect_all_examples_operations(lemma): |
96 | operations = [] | 96 | operations = [] |
97 | - lex_units = lemma.entry_obj.lexical_units().all() | 97 | + lex_units = lemma.entry_obj.meanings.all() |
98 | for lu in lex_units: | 98 | for lu in lex_units: |
99 | lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu) | 99 | lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu) |
100 | for lu_ex in lu_examples: | 100 | for lu_ex in lu_examples: |
@@ -112,6 +112,6 @@ def disconnect_example_operation(example_dict, example_obj): | @@ -112,6 +112,6 @@ def disconnect_example_operation(example_dict, example_obj): | ||
112 | lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) | 112 | lu = LexicalUnit.objects.get(id=example_dict['lexical_unit']) |
113 | return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id} | 113 | return {'operation': 'remove_example', 'unit': lu.id, 'example': example_obj.id} |
114 | 114 | ||
115 | -def reconnect_examples(operations): | ||
116 | - update_meanings(operations) | 115 | +def reconnect_examples(lemma, operations): |
116 | + update_meanings(lemma.id, operations) | ||
117 | 117 | ||
118 | \ No newline at end of file | 118 | \ No newline at end of file |
dictionary/static/css/lemmas_filtering.css
0 → 100644
dictionary/static/js/lemmas_filtering.js
@@ -3,15 +3,74 @@ function filter_form_submit() { | @@ -3,15 +3,74 @@ function filter_form_submit() { | ||
3 | form_data = this_form.serializeArray(); | 3 | form_data = this_form.serializeArray(); |
4 | 4 | ||
5 | var filter_frames = false; | 5 | var filter_frames = false; |
6 | + var actSemArgument = {}; | ||
7 | + var relationalSemPref = {'relation': '', | ||
8 | + 'role': '', | ||
9 | + 'attribute': ''}; | ||
10 | + var semArgumentsAlternatives = []; | ||
11 | + var semArguments = []; | ||
6 | 12 | ||
7 | form_data = $.map(form_data, function(elem) | 13 | form_data = $.map(form_data, function(elem) |
8 | { | 14 | { |
9 | - if (elem.name != 'filter_frames') return elem; | 15 | + if (elem.name != 'filter_frames' && !isPartOfSemArgFilter(elem)) { |
16 | + return elem; | ||
17 | + } | ||
10 | else { | 18 | else { |
11 | - if (elem.name == 'filter_frames') filter_frames = elem.value; | 19 | + if(elem.name == 'filter_frames') { |
20 | + filter_frames = elem.value; | ||
21 | + } | ||
22 | + else if(elem.name == 'negation') { | ||
23 | + if(!jQuery.isEmptyObject(actSemArgument)) { | ||
24 | + semArguments.push(actSemArgument); | ||
25 | + } | ||
26 | + actSemArgument = {'negation': elem.value, | ||
27 | + 'role': '', | ||
28 | + 'attribute': '', | ||
29 | + 'general_prefs': [], | ||
30 | + 'synset_prefs': [], | ||
31 | + 'relational_prefs': []} | ||
32 | + } | ||
33 | + else if(elem.name == 'or') { | ||
34 | + if(!jQuery.isEmptyObject(actSemArgument)) { | ||
35 | + semArguments.push(actSemArgument); | ||
36 | + actSemArgument = {}; | ||
37 | + } | ||
38 | + semArgumentsAlternatives.push(semArguments); | ||
39 | + semArguments = []; | ||
40 | + } | ||
41 | + else if(elem.name == 'role' || elem.name == 'attribute') { | ||
42 | + actSemArgument[elem.name] = elem.value; | ||
43 | + } | ||
44 | + else if(elem.name == 'general_pref' || elem.name == 'synset_pref') { | ||
45 | + actSemArgument[elem.name+'s'].push(elem.value); | ||
46 | + } | ||
47 | + else if(elem.name.startsWith('relational_pref')) { | ||
48 | + if(elem.name.endsWith('relation')) { | ||
49 | + relationalSemPref = {'relation': elem.value, | ||
50 | + 'role': '', | ||
51 | + 'attribute': ''}; | ||
52 | + } | ||
53 | + else if(elem.name.endsWith('role')) { | ||
54 | + relationalSemPref['role'] = elem.value; | ||
55 | + } | ||
56 | + else if(elem.name.endsWith('attribute')) { | ||
57 | + relationalSemPref['attribute'] = elem.value; | ||
58 | + actSemArgument['relational_prefs'].push(relationalSemPref); | ||
59 | + relationalSemPref = {}; | ||
60 | + } | ||
61 | + } | ||
12 | } | 62 | } |
13 | }); | 63 | }); |
64 | + if(!jQuery.isEmptyObject(actSemArgument)) { | ||
65 | + semArguments.push(actSemArgument); | ||
66 | + } | ||
67 | + if(semArguments.length > 0) { | ||
68 | + semArgumentsAlternatives.push(semArguments); | ||
69 | + } | ||
70 | + | ||
71 | + | ||
14 | form_data.push({name: 'filter_frames', value: filter_frames}); | 72 | form_data.push({name: 'filter_frames', value: filter_frames}); |
73 | + form_data.push({name: 'sem_arguments', value: semArgumentsAlternatives}); | ||
15 | 74 | ||
16 | act_lemma_id = window.prev_lemma_id; | 75 | act_lemma_id = window.prev_lemma_id; |
17 | if(window.activeLemmaPanel != 'preview_lemma') | 76 | if(window.activeLemmaPanel != 'preview_lemma') |
@@ -82,3 +141,51 @@ function filter_form_submit() { | @@ -82,3 +141,51 @@ function filter_form_submit() { | ||
82 | }); | 141 | }); |
83 | return false; | 142 | return false; |
84 | } | 143 | } |
144 | + | ||
145 | +function isPartOfSemArgFilter(field) { | ||
146 | + if(field.name == 'or' || field.name == 'negation' || | ||
147 | + field.name == 'role' || field.name == 'attribute' || | ||
148 | + field.name == 'general_pref' || field.name == 'synset_pref' || | ||
149 | + field.name.startsWith('relational_pref')) { | ||
150 | + return true; | ||
151 | + } | ||
152 | + return false; | ||
153 | +} | ||
154 | + | ||
155 | +function addSemArgFilter(buttonElem) { | ||
156 | + var semArgsElem = $(buttonElem).parent().parent(); | ||
157 | + semArgsElem.append('<p id="sem-argument"></p>'); | ||
158 | + semArgsElem.children().last().load(ajax_sem_arg_form); | ||
159 | +} | ||
160 | + | ||
161 | +function addArgAlternative(buttonElem) { | ||
162 | + var semArgsElem = $(buttonElem).parent().parent(); | ||
163 | + semArgsElem.append('<div><hr class="alterSeparator"><input type="hidden" name="or" value="or"><strong>lub</strong> <button type="button" onclick="removeAlternative(this)">Usuń</button></div>'); | ||
164 | +} | ||
165 | + | ||
166 | +function removeAlternative(buttonElem) { | ||
167 | + $(buttonElem).parent().remove(); | ||
168 | +} | ||
169 | + | ||
170 | +function removeSemArgFilter(buttonElem) { | ||
171 | + $(buttonElem).parent().parent().remove(); | ||
172 | +} | ||
173 | + | ||
174 | +function addSelectivePreferenceFilter(buttonElem) { | ||
175 | + var selPrefsElem = $(buttonElem).parent().parent(); | ||
176 | + var selPrefType = selPrefsElem.find('#id_preference_type').first().val(); | ||
177 | + selPrefsElem.append('<p id="sel-preference"></p>'); | ||
178 | + if(selPrefType === 'general') { | ||
179 | + selPrefsElem.children().last().load(ajax_general_preference_form); | ||
180 | + } | ||
181 | + else if(selPrefType === 'synset') { | ||
182 | + selPrefsElem.children().last().load(ajax_synset_preference_form); | ||
183 | + } | ||
184 | + else if(selPrefType === 'relation') { | ||
185 | + selPrefsElem.children().last().load(ajax_relational_preference_form); | ||
186 | + } | ||
187 | +} | ||
188 | + | ||
189 | +function removeSelPreferenceFilter(buttonElem) { | ||
190 | + $(buttonElem).parent().remove(); | ||
191 | +} |
dictionary/teixml.py
@@ -437,7 +437,7 @@ def write_example(parent_elem, lemma, example): | @@ -437,7 +437,7 @@ def write_example(parent_elem, lemma, example): | ||
437 | 437 | ||
438 | def get_and_write_meaning_link(parent_elem, entry, example): | 438 | def get_and_write_meaning_link(parent_elem, entry, example): |
439 | try: | 439 | try: |
440 | - entry_lex_units = entry.lexical_units() | 440 | + entry_lex_units = entry.meanings.all() |
441 | lex_unit_example = LexicalUnitExamples.objects.get(example=example, | 441 | lex_unit_example = LexicalUnitExamples.objects.get(example=example, |
442 | lexical_unit__in=entry_lex_units) | 442 | lexical_unit__in=entry_lex_units) |
443 | meaning = lex_unit_example.lexical_unit | 443 | meaning = lex_unit_example.lexical_unit |
@@ -674,8 +674,7 @@ def write_meanings_layer(parent_elem, lemma): | @@ -674,8 +674,7 @@ def write_meanings_layer(parent_elem, lemma): | ||
674 | 674 | ||
675 | def write_meanings(parent_elem, lemma): | 675 | def write_meanings(parent_elem, lemma): |
676 | entry = lemma.entry_obj | 676 | entry = lemma.entry_obj |
677 | - lex_units = entry.lexical_units() | ||
678 | - for lex_unit in lex_units.all(): | 677 | + for lex_unit in entry.meanings.all(): |
679 | write_meaning(parent_elem, entry, lex_unit) | 678 | write_meaning(parent_elem, entry, lex_unit) |
680 | 679 | ||
681 | def write_meaning(parent_elem, entry, lex_unit): | 680 | def write_meaning(parent_elem, entry, lex_unit): |
dictionary/templates/filter_form.html
@@ -47,6 +47,7 @@ $(function(){ | @@ -47,6 +47,7 @@ $(function(){ | ||
47 | <ul> | 47 | <ul> |
48 | <li><a href="#lemma-filters">Hasło</a></li> | 48 | <li><a href="#lemma-filters">Hasło</a></li> |
49 | <li><a href="#schema-filters">Schematy</a></li> | 49 | <li><a href="#schema-filters">Schematy</a></li> |
50 | + <li><a href="#frame-filters">Ramy</a></li> | ||
50 | </ul> | 51 | </ul> |
51 | <div id="lemma-filters"> | 52 | <div id="lemma-filters"> |
52 | {% if not form.lemma.is_hidden %} | 53 | {% if not form.lemma.is_hidden %} |
@@ -68,7 +69,7 @@ $(function(){ | @@ -68,7 +69,7 @@ $(function(){ | ||
68 | </p> | 69 | </p> |
69 | {% endif %} | 70 | {% endif %} |
70 | {% if not form.owner.is_hidden or not form.phraseologist.is_hidden or not form.semanticist.is_hidden %} | 71 | {% if not form.owner.is_hidden or not form.phraseologist.is_hidden or not form.semanticist.is_hidden %} |
71 | - <hr> | 72 | + <hr class="filtersSeparator"> |
72 | {% endif %} | 73 | {% endif %} |
73 | {% if not form.owner.is_hidden %} | 74 | {% if not form.owner.is_hidden %} |
74 | <p class="fieldWrapper"> | 75 | <p class="fieldWrapper"> |
@@ -89,7 +90,7 @@ $(function(){ | @@ -89,7 +90,7 @@ $(function(){ | ||
89 | </p> | 90 | </p> |
90 | {% endif %} | 91 | {% endif %} |
91 | {% if not form.vocabulary.is_hidden or not form.status.is_hidden or not form.has_message_from.is_hidden %} | 92 | {% if not form.vocabulary.is_hidden or not form.status.is_hidden or not form.has_message_from.is_hidden %} |
92 | - <hr> | 93 | + <hr class="filtersSeparator"> |
93 | {% endif %} | 94 | {% endif %} |
94 | {% if not form.vocabulary.is_hidden %} | 95 | {% if not form.vocabulary.is_hidden %} |
95 | <p class="fieldWrapper"> | 96 | <p class="fieldWrapper"> |
@@ -110,7 +111,7 @@ $(function(){ | @@ -110,7 +111,7 @@ $(function(){ | ||
110 | </p> | 111 | </p> |
111 | {% endif %} | 112 | {% endif %} |
112 | {% if not form.example_source.is_hidden or not form.approver.is_hidden %} | 113 | {% if not form.example_source.is_hidden or not form.approver.is_hidden %} |
113 | - <hr> | 114 | + <hr class="filtersSeparator"> |
114 | {% endif %} | 115 | {% endif %} |
115 | {% if not form.example_source.is_hidden %} | 116 | {% if not form.example_source.is_hidden %} |
116 | <p class="fieldWrapper"> | 117 | <p class="fieldWrapper"> |
@@ -126,10 +127,10 @@ $(function(){ | @@ -126,10 +127,10 @@ $(function(){ | ||
126 | {% endif %} | 127 | {% endif %} |
127 | </div> | 128 | </div> |
128 | <div id="schema-filters"> | 129 | <div id="schema-filters"> |
129 | - {% if not form.frame_opinion.is_hidden %} | 130 | + {% if not form.schema_opinion.is_hidden %} |
130 | <p class="fieldWrapper"> | 131 | <p class="fieldWrapper"> |
131 | - {{ form.frame_opinion.errors }} | ||
132 | - {{ form.frame_opinion.label_tag }}: {{ form.frame_opinion }} | 132 | + {{ form.schema_opinion.errors }} |
133 | + {{ form.schema_opinion.label_tag }}: {{ form.schema_opinion }} | ||
133 | </p> | 134 | </p> |
134 | {% endif %} | 135 | {% endif %} |
135 | {% if not form.schema_type.is_hidden %} | 136 | {% if not form.schema_type.is_hidden %} |
@@ -181,6 +182,26 @@ $(function(){ | @@ -181,6 +182,26 @@ $(function(){ | ||
181 | </p> | 182 | </p> |
182 | {% endif %} | 183 | {% endif %} |
183 | </div> | 184 | </div> |
185 | + <div id="frame-filters"> | ||
186 | + {% if not form.frame_opinion.is_hidden %} | ||
187 | + <p class="fieldWrapper"> | ||
188 | + {{ form.frame_opinion.errors }} | ||
189 | + {{ form.frame_opinion.label_tag }}: {{ form.frame_opinion }} | ||
190 | + </p> | ||
191 | + {% endif %} | ||
192 | + <hr class="filtersSeparator"> | ||
193 | + <div id="sem-arguments"> | ||
194 | + <p>Argumenty semantyczne: | ||
195 | + <button type="button" onclick="addSemArgFilter(this)">Dodaj</button> | ||
196 | + <button type="button" onclick="addArgAlternative(this)">Lub</button> | ||
197 | + </p> | ||
198 | + {% for arg_form in sem_args_forms %} | ||
199 | + <div id="sem-argument"> | ||
200 | + {% include 'sem_arg_form.html' with form=arg_form only %} | ||
201 | + </div> | ||
202 | + {% endfor %} | ||
203 | + </div> | ||
204 | + </div> | ||
184 | </div> | 205 | </div> |
185 | {% for hidden in form.hidden_fields %} | 206 | {% for hidden in form.hidden_fields %} |
186 | {{ hidden }} | 207 | {{ hidden }} |
dictionary/templates/lemma_view.html
@@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
9 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/examples_table.css"/> | 9 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/examples_table.css"/> |
10 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/aspect_relations_table.css"/> | 10 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/aspect_relations_table.css"/> |
11 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/filter_frames_menu.css"/> | 11 | <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/filter_frames_menu.css"/> |
12 | + <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/lemmas_filtering.css"/> | ||
12 | <script type="text/javascript" src="{{ STATIC_URL }}js/lib/grid.locale-pl.js"></script> | 13 | <script type="text/javascript" src="{{ STATIC_URL }}js/lib/grid.locale-pl.js"></script> |
13 | <script type="text/javascript"> | 14 | <script type="text/javascript"> |
14 | jQuery.jgrid.no_legacy_api = true; | 15 | jQuery.jgrid.no_legacy_api = true; |
@@ -62,9 +63,7 @@ | @@ -62,9 +63,7 @@ | ||
62 | <ul> | 63 | <ul> |
63 | <li id="refresh_frames"><a href="#new_frames">{% trans "Schematy" %} [<span id="new-frames-count"></span>]</a></li> | 64 | <li id="refresh_frames"><a href="#new_frames">{% trans "Schematy" %} [<span id="new-frames-count"></span>]</a></li> |
64 | 65 | ||
65 | - {% if perms.dictionary.view_semantics %} | ||
66 | - <li><a href="#semantics">{% trans "Semantyka" %} [<span id="semantic-frames-count"></span>]</a></li> | ||
67 | - {% endif %} | 66 | + <li><a href="#semantics">{% trans "Semantyka" %} [<span id="semantic-frames-count"></span>]</a></li> |
68 | <!-- li><a href="#old_frames">{% trans "Stare schematy" %}</a></li --> | 67 | <!-- li><a href="#old_frames">{% trans "Stare schematy" %}</a></li --> |
69 | {% if perms.dictionary.add_notes %} | 68 | {% if perms.dictionary.add_notes %} |
70 | <li><a href="#notes">{% trans "Notatki" %} [<span id="lemma-notes-count"></span>]</a></li> | 69 | <li><a href="#notes">{% trans "Notatki" %} [<span id="lemma-notes-count"></span>]</a></li> |
@@ -81,10 +80,8 @@ | @@ -81,10 +80,8 @@ | ||
81 | </ul> | 80 | </ul> |
82 | <div id="new_frames"> | 81 | <div id="new_frames"> |
83 | </div> | 82 | </div> |
84 | - {% if perms.dictionary.view_semantics %} | ||
85 | - <div id="semantics"> | ||
86 | - </div> | ||
87 | - {% endif %} | 83 | + <div id="semantics"> |
84 | + </div> | ||
88 | {% if perms.dictionary.add_notes %} | 85 | {% if perms.dictionary.add_notes %} |
89 | <div id="notes"> | 86 | <div id="notes"> |
90 | </div> | 87 | </div> |
dictionary/views.py
1 | #-*- coding:utf-8 -*- | 1 | #-*- coding:utf-8 -*- |
2 | 2 | ||
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | ||
4 | -#All rights reserved. | ||
5 | - | ||
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | ||
7 | -#that the following conditions are met: | ||
8 | - | ||
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | ||
10 | -# the following disclaimer. | ||
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | ||
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
13 | - | ||
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
21 | -# POSSIBILITY OF SUCH DAMAGE. | ||
22 | - | ||
23 | import datetime | 3 | import datetime |
24 | import os | 4 | import os |
25 | 5 | ||
@@ -212,6 +192,11 @@ def lemma_view(request): | @@ -212,6 +192,11 @@ def lemma_view(request): | ||
212 | 'ajax_save_columns': reverse('save_columns'), | 192 | 'ajax_save_columns': reverse('save_columns'), |
213 | 'ajax_save_columns': reverse('save_columns'), | 193 | 'ajax_save_columns': reverse('save_columns'), |
214 | 'ajax_get_sort_order': reverse('get_sort_order'), | 194 | 'ajax_get_sort_order': reverse('get_sort_order'), |
195 | + 'ajax_sem_arg_form': reverse('sem_arg_form'), | ||
196 | + 'ajax_general_preference_form': reverse('general_preference_form'), | ||
197 | + 'ajax_synset_preference_form': reverse('synset_preference_form'), | ||
198 | + 'ajax_relational_preference_form': reverse('relational_preference_form'), | ||
199 | + 'ajax_synset_context_lookup': reverse('synset_context_lookup'), | ||
215 | 200 | ||
216 | # czasowniki podobne | 201 | # czasowniki podobne |
217 | 'ajax_similar_lemmas_old_form_submit': reverse('similar_lemmas_old_form_submit'), | 202 | 'ajax_similar_lemmas_old_form_submit': reverse('similar_lemmas_old_form_submit'), |
semantics/change_log.py
@@ -179,7 +179,7 @@ def backup_lemma_and_get_frames(lemma): | @@ -179,7 +179,7 @@ def backup_lemma_and_get_frames(lemma): | ||
179 | 179 | ||
180 | def backup_lemma(lemma_id): | 180 | def backup_lemma(lemma_id): |
181 | lemma = Lemma.objects.get(id=lemma_id, old=False) | 181 | lemma = Lemma.objects.get(id=lemma_id, old=False) |
182 | - lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')).order_by('sense') | 182 | + lexical_units = lemma.entry_obj.meanings.order_by('sense') |
183 | 183 | ||
184 | frame_ids = [] | 184 | frame_ids = [] |
185 | for lexical_unit in lexical_units: | 185 | for lexical_unit in lexical_units: |
semantics/forms.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | ||
2 | + | ||
3 | +from django.forms import CharField, ChoiceField, Form, ModelChoiceField | ||
4 | + | ||
5 | +from semantics.models import GeneralSelectivePreference, SelectivePreferenceRelations, SemanticRole | ||
6 | + | ||
7 | +class RoleForm(Form): | ||
8 | + negation = ChoiceField(choices=[('', u'---'), ('!', u'!')], required=False, | ||
9 | + label=u'') | ||
10 | + role = ModelChoiceField(label=u'Rola', required=False, | ||
11 | + queryset=SemanticRole.objects.filter(gradient__isnull=True)) | ||
12 | + attribute = ModelChoiceField(label=u'Atrybut', required=False, | ||
13 | + queryset=SemanticRole.objects.filter(gradient__isnull=False)) | ||
14 | + preference_type = ChoiceField(choices=[('general', u'Predefiniowana'), ('synset', u'Słowosieć'), ('relation', u'Relacja')], | ||
15 | + label=u'Preferencje selekcyjne', required=False) | ||
16 | + preferences = [] | ||
17 | + | ||
18 | + def __init__(self, negation=None, sel_role=None, sel_attribute=None, | ||
19 | + sel_preferences=[], | ||
20 | + *args, **kwargs): | ||
21 | + super(RoleForm, self).__init__(*args, **kwargs) | ||
22 | + self.fields['negation'].initial = negation | ||
23 | + self.fields['role'].initial = sel_role | ||
24 | + self.fields['attribute'].initial = sel_attribute | ||
25 | + self.preferences = sel_preferences | ||
26 | + | ||
27 | +class GeneralSelPrefForm(Form): | ||
28 | + general_pref = ModelChoiceField(label=u'Predefiniowana', | ||
29 | + queryset=GeneralSelectivePreference.objects.order_by('name'), required=False) | ||
30 | + | ||
31 | + def pref_type(self): | ||
32 | + return 'general' | ||
33 | + | ||
34 | + def __init__(self, sel_preference=None, *args, **kwargs): | ||
35 | + super(GeneralSelPrefForm, self).__init__(*args, **kwargs) | ||
36 | + self.fields['general_pref'].initial = sel_preference | ||
37 | + | ||
38 | +class SynsetSelPrefForm(Form): | ||
39 | + synset_pref = CharField(label=u'Słowosieć', required=False) | ||
40 | + | ||
41 | + def pref_type(self): | ||
42 | + return 'synset' | ||
43 | + | ||
44 | + def __init__(self, sel_preference=None, *args, **kwargs): | ||
45 | + super(SynsetSelPrefForm, self).__init__(*args, **kwargs) | ||
46 | + self.fields['synset_pref'].initial = sel_preference | ||
47 | + | ||
48 | +class RelationalSelPrefForm(Form): | ||
49 | + relational_pref_relation = ModelChoiceField(label=u'Relacja', | ||
50 | + queryset=SelectivePreferenceRelations.objects.all(), required=False) | ||
51 | + relational_pref_role = ModelChoiceField(label=u'Rola', required=False, | ||
52 | + queryset=SemanticRole.objects.filter(gradient__isnull=True)) | ||
53 | + relational_pref_attribute = ModelChoiceField(label=u'Atrybut', required=False, | ||
54 | + queryset=SemanticRole.objects.filter(gradient__isnull=False)) | ||
55 | + | ||
56 | + def pref_type(self): | ||
57 | + return 'relational' | ||
58 | + | ||
59 | + def __init__(self, sel_relation=None, sel_role=None, sel_attribute=None, *args, **kwargs): | ||
60 | + super(RelationalSelPrefForm, self).__init__(*args, **kwargs) | ||
61 | + self.fields['relational_pref_relation'].initial = sel_relation | ||
62 | + self.fields['relational_pref_role'].initial = sel_role | ||
63 | + self.fields['relational_pref_attribute'].initial = sel_attribute | ||
64 | + | ||
0 | \ No newline at end of file | 65 | \ No newline at end of file |
semantics/saving.py
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | from django.db.models import Min | 3 | from django.db.models import Min |
4 | 4 | ||
5 | -from dictionary.models import Argument, Frame, NKJP_Example, Position | 5 | +from dictionary.models import Argument, Frame, Lemma, NKJP_Example, Position |
6 | from semantics.change_log import store_old_versions | 6 | from semantics.change_log import store_old_versions |
7 | from semantics.models import Complement, GeneralSelectivePreference, FramePosition,\ | 7 | from semantics.models import Complement, GeneralSelectivePreference, FramePosition,\ |
8 | LexicalUnitExamples, RelationalSelectivePreference, \ | 8 | LexicalUnitExamples, RelationalSelectivePreference, \ |
@@ -278,8 +278,9 @@ def remove_preference(frame_id, complement_id, preference): | @@ -278,8 +278,9 @@ def remove_preference(frame_id, complement_id, preference): | ||
278 | complement.selective_preference.relations.remove(r) | 278 | complement.selective_preference.relations.remove(r) |
279 | 279 | ||
280 | 280 | ||
281 | -def update_meanings(operations): | 281 | +def update_meanings(lemma_id, operations): |
282 | translation = {} | 282 | translation = {} |
283 | + entry = Lemma.objects.get(id=lemma_id).entry_obj | ||
283 | for operation in operations: | 284 | for operation in operations: |
284 | if operation['operation'] == "set_glossa": | 285 | if operation['operation'] == "set_glossa": |
285 | if int(operation['unit']) in translation: | 286 | if int(operation['unit']) in translation: |
@@ -300,7 +301,7 @@ def update_meanings(operations): | @@ -300,7 +301,7 @@ def update_meanings(operations): | ||
300 | unit = int(operation['unit']) | 301 | unit = int(operation['unit']) |
301 | remove_example(unit, operation['example']) | 302 | remove_example(unit, operation['example']) |
302 | elif operation['operation'] == "add_unit": | 303 | elif operation['operation'] == "add_unit": |
303 | - translation[operation['unit']['id']] = add_unit(operation['unit']) | 304 | + translation[operation['unit']['id']] = add_unit(entry, operation['unit']) |
304 | elif operation['operation'] == "remove_unit": | 305 | elif operation['operation'] == "remove_unit": |
305 | luid = int(operation['luid']) | 306 | luid = int(operation['luid']) |
306 | if luid in translation: | 307 | if luid in translation: |
@@ -327,11 +328,11 @@ def remove_example(unit_id, example_id): | @@ -327,11 +328,11 @@ def remove_example(unit_id, example_id): | ||
327 | lue = LexicalUnitExamples.objects.get(example=nkjp_example, lexical_unit=unit) | 328 | lue = LexicalUnitExamples.objects.get(example=nkjp_example, lexical_unit=unit) |
328 | lue.delete() | 329 | lue.delete() |
329 | 330 | ||
330 | -def add_unit(unit): # returns new id | 331 | +def add_unit(entry, unit): # returns new id |
331 | 332 | ||
332 | s1 = Synset(id=(min(Synset.objects.all().aggregate(Min('id'))['id__min'], 0) - 1)) | 333 | s1 = Synset(id=(min(Synset.objects.all().aggregate(Min('id'))['id__min'], 0) - 1)) |
333 | s1.save() | 334 | s1.save() |
334 | - lu = LexicalUnit(base=unit['base'], sense=unit['sense'], pos=unit['pos'], glossa=unit['glossa'], luid=-1, synset=s1) | 335 | + lu = LexicalUnit(entry=entry, base=unit['base'], sense=unit['sense'], pos=unit['pos'], glossa=unit['glossa'], luid=-1, synset=s1) |
335 | lu.save() | 336 | lu.save() |
336 | 337 | ||
337 | 338 |
semantics/sem_urls.py
@@ -19,5 +19,10 @@ SEMANTIC_PATTERNS = patterns('semantics.views', | @@ -19,5 +19,10 @@ SEMANTIC_PATTERNS = patterns('semantics.views', | ||
19 | url(r'^ajax/update_meanings/$', 'ajax_update_meanings'), | 19 | url(r'^ajax/update_meanings/$', 'ajax_update_meanings'), |
20 | url(r'^ajax/modify_frames/$', 'ajax_modify_frames'), | 20 | url(r'^ajax/modify_frames/$', 'ajax_modify_frames'), |
21 | url(r'^ajax/plWN_context_lookup/$', 'ajax_plWN_context_lookup'), | 21 | url(r'^ajax/plWN_context_lookup/$', 'ajax_plWN_context_lookup'), |
22 | + url(r'^ajax/synset_context_lookup/$', 'synset_context_lookup'), | ||
22 | url(r'^ajax/validate_semantics/$', 'validate_semantics'), | 23 | url(r'^ajax/validate_semantics/$', 'validate_semantics'), |
24 | + url(r'^ajax/sem_arg_form/$', 'sem_arg_form'), | ||
25 | + url(r'^ajax/general_preference_form/$', 'general_preference_form'), | ||
26 | + url(r'^ajax/synset_preference_form/$', 'synset_preference_form'), | ||
27 | + url(r'^ajax/relational_preference_form/$', 'relational_preference_form'), | ||
23 | ) | 28 | ) |
semantics/templates/general_preference_form.html
0 → 100644
semantics/templates/relational_preference_form.html
0 → 100644
1 | +<p class="fieldWrapper"> | ||
2 | + {{ form.relational_pref_relation.errors }} + {{ form.relational_pref_relation.label_tag }}: {{ form.relational_pref_relation }} | ||
3 | + {{ form.relational_pref_role.errors }} Do: {{ form.relational_pref_role }} | ||
4 | + {{ form.relational_pref_attribute.errors }} {{ form.relational_pref_attribute }} | ||
5 | + <button type="button" onclick="removeSelPreferenceFilter(this)">Usuń</button> | ||
6 | +</p> | ||
0 | \ No newline at end of file | 7 | \ No newline at end of file |
semantics/templates/sem_arg_form.html
0 → 100644
1 | +{% if form == 'or' %} | ||
2 | + <div> | ||
3 | + <hr class="alterSeparator"> | ||
4 | + <input type="hidden" name="or" value="or"><strong>lub</strong> | ||
5 | + <button type="button" onclick="removeAlternative(this)">Usuń</button> | ||
6 | + </div> | ||
7 | +{% else %} | ||
8 | + <hr class="argSeparator"> | ||
9 | + <p class="fieldWrapper"> | ||
10 | + {{ form.negation.errors }} {{ form.negation }} | ||
11 | + {{ form.role.errors }} {{ form.role.label_tag }}: {{ form.role }} | ||
12 | + {{ form.attribute.errors }} {{ form.attribute.label_tag }}: {{ form.attribute }} | ||
13 | + <button type="button" onclick="removeSemArgFilter(this)">Usuń</button> | ||
14 | + </p> | ||
15 | + <div id="selectional-preferences"> | ||
16 | + <p>{{ form.preference_type.errors }} {{ form.preference_type.label_tag }}: {{ form.preference_type }} <button type="button" onclick="addSelectivePreferenceFilter(this)">Dodaj</button></p> | ||
17 | + {% for pref_form in form.preferences %} | ||
18 | + <p id="sel-preference"> | ||
19 | + {% if pref_form.pref_type == 'general' %} | ||
20 | + {% include 'general_preference_form.html' with form=pref_form only %} | ||
21 | + {% elif pref_form.pref_type == 'relational' %} | ||
22 | + {% include 'relational_preference_form.html' with form=pref_form only %} | ||
23 | + {% elif pref_form.pref_type == 'synset' %} | ||
24 | + {% include 'synset_preference_form.html' with form=pref_form only %} | ||
25 | + {% endif %} | ||
26 | + </p> | ||
27 | + {% endfor %} | ||
28 | + </div> | ||
29 | +{% endif %} | ||
0 | \ No newline at end of file | 30 | \ No newline at end of file |
semantics/templates/synset_preference_form.html
0 → 100644
1 | +<p class="fieldWrapper"> | ||
2 | + {{ form.synset_pref.errors }} + {{ form.synset_pref.label_tag }}: {{ form.synset_pref }} | ||
3 | + <button type="button" onclick="removeSelPreferenceFilter(this)">Usuń</button> | ||
4 | + <script type="text/javascript"> | ||
5 | + $(function(){ | ||
6 | + $('input#id_synset_pref').autocomplete({ | ||
7 | + select: function(event, ui){ | ||
8 | + }, | ||
9 | + source: function(req, add){ | ||
10 | + $.getJSON(ajax_synset_context_lookup, req, function(data) { | ||
11 | + var suggestions = []; | ||
12 | + $.each(data['result'], function(i, val){ | ||
13 | + suggestions.push(val); | ||
14 | + }); | ||
15 | + add(suggestions); | ||
16 | + }); | ||
17 | + }, | ||
18 | + }); | ||
19 | + }); | ||
20 | + </script> | ||
21 | +</p> | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
semantics/validation.py
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | from django.db.models import Max | 3 | from django.db.models import Max |
4 | 4 | ||
5 | -from dictionary.models import Lemma, reflex_phrase_types, Argument_Model | 5 | +from dictionary.models import Lemma, reflex_phrase_types |
6 | from semantics.models import LexicalUnitExamples | 6 | from semantics.models import LexicalUnitExamples |
7 | from semantics.utils import get_structural_matching_frame | 7 | from semantics.utils import get_structural_matching_frame |
8 | 8 | ||
@@ -182,7 +182,7 @@ def schema_used(schema, frames): | @@ -182,7 +182,7 @@ def schema_used(schema, frames): | ||
182 | def validate_lexical_units(lemma_id): | 182 | def validate_lexical_units(lemma_id): |
183 | error_msg = '' | 183 | error_msg = '' |
184 | lemma = Lemma.objects.get(id=lemma_id, old=False) | 184 | lemma = Lemma.objects.get(id=lemma_id, old=False) |
185 | - lexical_units = lemma.entry_obj.lexical_units() | 185 | + lexical_units = lemma.entry_obj.meanings |
186 | for lex_unit in lexical_units.all(): | 186 | for lex_unit in lexical_units.all(): |
187 | if not examples_reflex_agreed(lex_unit): | 187 | if not examples_reflex_agreed(lex_unit): |
188 | error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady o niezgodnej zwrotności.' % unicode(lex_unit) | 188 | error_msg = u'Semantyka: Znaczenie %s ma podpięte przykłady o niezgodnej zwrotności.' % unicode(lex_unit) |
semantics/views.py
@@ -15,6 +15,7 @@ from django.core.urlresolvers import reverse | @@ -15,6 +15,7 @@ from django.core.urlresolvers import reverse | ||
15 | from django.db.models import Q | 15 | from django.db.models import Q |
16 | 16 | ||
17 | from common.decorators import render, ajax | 17 | from common.decorators import render, ajax |
18 | +from semantics.forms import GeneralSelPrefForm, RelationalSelPrefForm, RoleForm, SynsetSelPrefForm | ||
18 | from semantics.saving import modify_frames, update_meanings | 19 | from semantics.saving import modify_frames, update_meanings |
19 | from semantics.validation import validate_schemas, validate_frames, validate_lexical_units | 20 | from semantics.validation import validate_schemas, validate_frames, validate_lexical_units |
20 | 21 | ||
@@ -79,7 +80,7 @@ def create_frames_context(lemma_id): | @@ -79,7 +80,7 @@ def create_frames_context(lemma_id): | ||
79 | lemma = Lemma.objects.get(id=lemma_id) | 80 | lemma = Lemma.objects.get(id=lemma_id) |
80 | 81 | ||
81 | #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense') | 82 | #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense') |
82 | - lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')).order_by('sense') | 83 | + lexical_units = lemma.entry_obj.meanings.order_by('sense') |
83 | 84 | ||
84 | alternations = {} | 85 | alternations = {} |
85 | frames_dict = {} | 86 | frames_dict = {} |
@@ -216,7 +217,7 @@ def ajax_units(request, lemma_id): | @@ -216,7 +217,7 @@ def ajax_units(request, lemma_id): | ||
216 | 217 | ||
217 | def create_units_context(lemma_id): | 218 | def create_units_context(lemma_id): |
218 | lemma = Lemma.objects.get(id=lemma_id) | 219 | lemma = Lemma.objects.get(id=lemma_id) |
219 | - lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry, pos="czasownik")|Q(base = lemma.entry + u' się', pos="czasownik")).order_by('base', 'sense') | 220 | + lexical_units = lemma.entry_obj.meanings.order_by('base', 'sense') |
220 | # lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense') | 221 | # lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense') |
221 | 222 | ||
222 | context = { | 223 | context = { |
@@ -354,7 +355,7 @@ def ajax_schemas(request, lemma_id): | @@ -354,7 +355,7 @@ def ajax_schemas(request, lemma_id): | ||
354 | schemas_by_characteristic[characteristic_id] = [] | 355 | schemas_by_characteristic[characteristic_id] = [] |
355 | schemas_by_characteristic[characteristic_id].append(schema) | 356 | schemas_by_characteristic[characteristic_id].append(schema) |
356 | 357 | ||
357 | - lexical_units = LexicalUnit.objects.filter(Q(base=lemma.entry) | Q(base=lemma.entry+u' się')) | 358 | + lexical_units = lemma.entry_obj.meanings.all() |
358 | 359 | ||
359 | schemas_display = [] | 360 | schemas_display = [] |
360 | schema_unit_rank = {} | 361 | schema_unit_rank = {} |
@@ -414,7 +415,7 @@ def ajax_examples(request, lemma_id): | @@ -414,7 +415,7 @@ def ajax_examples(request, lemma_id): | ||
414 | 415 | ||
415 | lemma = Lemma.objects.get(id=lemma_id).entry_obj.actual_lemma() | 416 | lemma = Lemma.objects.get(id=lemma_id).entry_obj.actual_lemma() |
416 | nkjp_examples = lemma.nkjp_examples.all() | 417 | nkjp_examples = lemma.nkjp_examples.all() |
417 | - lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')) | 418 | + lexical_units = lemma.entry_obj.meanings.all() |
418 | 419 | ||
419 | lexical_units_ids = [lu.id for lu in lexical_units] | 420 | lexical_units_ids = [lu.id for lu in lexical_units] |
420 | 421 | ||
@@ -488,7 +489,7 @@ def ajax_create_complement(request, lemma_id, frame, roles): | @@ -488,7 +489,7 @@ def ajax_create_complement(request, lemma_id, frame, roles): | ||
488 | 489 | ||
489 | @ajax(method='post', encode_result=True) | 490 | @ajax(method='post', encode_result=True) |
490 | def ajax_update_meanings(request, operations, lemma_id): | 491 | def ajax_update_meanings(request, operations, lemma_id): |
491 | - update_meanings(operations) | 492 | + update_meanings(lemma_id, operations) |
492 | units_context = create_units_context(lemma_id) | 493 | units_context = create_units_context(lemma_id) |
493 | return units_context | 494 | return units_context |
494 | 495 | ||
@@ -519,6 +520,19 @@ def get_ordered_lexical_units_bases(lexical_units_query): | @@ -519,6 +520,19 @@ def get_ordered_lexical_units_bases(lexical_units_query): | ||
519 | last_unit_base = lexical_unit.base | 520 | last_unit_base = lexical_unit.base |
520 | return lexical_unit_bases | 521 | return lexical_unit_bases |
521 | 522 | ||
523 | +@ajax(method='get', encode_result=True) | ||
524 | +def synset_context_lookup(request, term): | ||
525 | + results = [] | ||
526 | + term = unicode(term) | ||
527 | + if len(term) > 0: | ||
528 | + obj_results = LexicalUnit.objects.filter(base__startswith=term) | ||
529 | + results = get_ordered_lexical_units(obj_results) | ||
530 | + return {'result': results} | ||
531 | + | ||
532 | +def get_ordered_lexical_units(lexical_units_query): | ||
533 | + ordered_lexical_units = lexical_units_query.order_by('base', 'sense') | ||
534 | + return [unicode(lu) for lu in ordered_lexical_units] | ||
535 | + | ||
522 | @ajax(method='get') | 536 | @ajax(method='get') |
523 | def validate_semantics(request, lemma_id, new_status_id): | 537 | def validate_semantics(request, lemma_id, new_status_id): |
524 | error_msg = '' | 538 | error_msg = '' |
@@ -536,3 +550,27 @@ def validate_semantics(request, lemma_id, new_status_id): | @@ -536,3 +550,27 @@ def validate_semantics(request, lemma_id, new_status_id): | ||
536 | if not error_msg: | 550 | if not error_msg: |
537 | error_msg = validate_schemas(lemma_id) | 551 | error_msg = validate_schemas(lemma_id) |
538 | return {'error_message': error_msg} | 552 | return {'error_message': error_msg} |
553 | + | ||
554 | +@render('sem_arg_form.html') | ||
555 | +@ajax(method='get', encode_result=False) | ||
556 | +def sem_arg_form(request): | ||
557 | + form = RoleForm() | ||
558 | + return {'form': form} | ||
559 | + | ||
560 | +@render('general_preference_form.html') | ||
561 | +@ajax(method='get', encode_result=False) | ||
562 | +def general_preference_form(request): | ||
563 | + form = GeneralSelPrefForm() | ||
564 | + return {'form': form} | ||
565 | + | ||
566 | +@render('synset_preference_form.html') | ||
567 | +@ajax(method='get', encode_result=False) | ||
568 | +def synset_preference_form(request): | ||
569 | + form = SynsetSelPrefForm() | ||
570 | + return {'form': form} | ||
571 | + | ||
572 | +@render('relational_preference_form.html') | ||
573 | +@ajax(method='get', encode_result=False) | ||
574 | +def relational_preference_form(request): | ||
575 | + form = RelationalSelPrefForm() | ||
576 | + return {'form': form} |
static/js/script.js
@@ -202,6 +202,7 @@ function resetForm($form) { | @@ -202,6 +202,7 @@ function resetForm($form) { | ||
202 | $form.find('input:text, input:password, input:file, select, textarea').val(''); | 202 | $form.find('input:text, input:password, input:file, select, textarea').val(''); |
203 | $form.find('input:radio, input:checkbox') | 203 | $form.find('input:radio, input:checkbox') |
204 | .removeAttr('checked').removeAttr('selected'); | 204 | .removeAttr('checked').removeAttr('selected'); |
205 | + $form.find('#sem-arguments').remove(); | ||
205 | } | 206 | } |
206 | 207 | ||
207 | // funkcja konwertujaca kody html znakow do znakow | 208 | // funkcja konwertujaca kody html znakow do znakow |
wordnet/models.py
@@ -33,6 +33,8 @@ class LexicalUnit(models.Model): | @@ -33,6 +33,8 @@ class LexicalUnit(models.Model): | ||
33 | definition = models.TextField(default="") | 33 | definition = models.TextField(default="") |
34 | # glossa | 34 | # glossa |
35 | glossa = models.TextField(default="") | 35 | glossa = models.TextField(default="") |
36 | + # haslo w Walentym | ||
37 | + entry = models.ForeignKey('dictionary.Entry', null=True, related_name='meanings') | ||
36 | 38 | ||
37 | def __unicode__(self): | 39 | def __unicode__(self): |
38 | return u'%s-%s' % (self.base, self.sense) | 40 | return u'%s-%s' % (self.base, self.sense) |