Commit dfb77ac503db408aa975a7e3e8ae50185a40939d
1 parent
8692f5ff
Reorganized lemmas filtering form and added new schemata and lemmas filtering fields.
Showing
14 changed files
with
1025 additions
and
781 deletions
dictionary/ajax_jqgrid.py
... | ... | @@ -11,26 +11,7 @@ def default_sort_rules(): |
11 | 11 | 'semanticist': { 'priority': None, 'sort_order': 'desc'}, |
12 | 12 | 'vocabulary': { 'priority': None, 'sort_order': 'desc'}, |
13 | 13 | 'status': { 'priority': None, 'sort_order': 'desc'}} |
14 | - | |
15 | -def default_filter_rules(): | |
16 | - return { 'pos': None, | |
17 | - 'owner': None, | |
18 | - 'phraseologist': None, | |
19 | - 'semanticist': None, | |
20 | - 'vocabulary': None, | |
21 | - 'status': None, | |
22 | - 'example_source': None, | |
23 | - 'approver': None, | |
24 | - 'reflex': None, | |
25 | - 'negativity': None, | |
26 | - 'predicativity': None, | |
27 | - 'aspect': None, | |
28 | - 'argument': '.*', | |
29 | - 'position': '.*', | |
30 | - 'frame_opinion' : None, | |
31 | - 'sender': None, | |
32 | - 'frame_phraseologic': False} | |
33 | - | |
14 | + | |
34 | 15 | class JqGridAjax(object): |
35 | 16 | model = None |
36 | 17 | search_field = None |
... | ... |
dictionary/ajax_lemma_view.py
... | ... | @@ -13,6 +13,9 @@ from django.core import serializers |
13 | 13 | |
14 | 14 | from common.js_to_obj import frameObjToSerializableDict, jsArgToObj, jsFrameToObj, jsPosToObj |
15 | 15 | from dictionary.convert_frames import frame_conversion |
16 | +from dictionary.filtering import default_filter_rules, prepare_filter_form, \ | |
17 | + save_lemma_filters_and_get_schemata_filter_setup, \ | |
18 | + schemata_filter_options | |
16 | 19 | from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ |
17 | 20 | Frame_Opinion_Value, Frame, NKJP_Example, NKJP_ArgSelection, \ |
18 | 21 | NKJP_Source, NKJP_Opinion, Position, \ |
... | ... | @@ -24,7 +27,7 @@ from dictionary.models import Vocabulary, Lemma, Lemma_Status, Frame_Opinion, \ |
24 | 27 | sorted_default_frame_char_vals, XcpExample, \ |
25 | 28 | POS, get_frame_char_and_its_value, get_frame_char_by_type_and_value_pk, \ |
26 | 29 | sortFrameChars, sortArguments, sortPositions, \ |
27 | - get_or_create_position, get_phraseologic_frames_only, pos_compatible | |
30 | + get_or_create_position, get_schemata_by_type, pos_compatible | |
28 | 31 | from dictionary.forms import AddPositionForm, FrameForm, Pos_Cat_Form, \ |
29 | 32 | AddNkjpExampleForm, MessageForm, SortForm, FilterForm, \ |
30 | 33 | SimilarLemmasNewForm, ChangeUserFunctionForm, \ |
... | ... | @@ -57,7 +60,7 @@ from django.core.validators import email_re |
57 | 60 | from accounts.models import UserSettings, UserStats, RealizedPhraseologyBinding, \ |
58 | 61 | can_modify_phraseology_only, get_anon_profile |
59 | 62 | |
60 | -from ajax_jqgrid import JqGridAjax, default_sort_rules, default_filter_rules | |
63 | +from ajax_jqgrid import JqGridAjax, default_sort_rules | |
61 | 64 | |
62 | 65 | import locale |
63 | 66 | locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8') |
... | ... | @@ -309,35 +312,7 @@ def get_lemma_preview(request, id, main_lemma_id): |
309 | 312 | |
310 | 313 | @ajax(method='get') |
311 | 314 | def get_frame_filter_options(request): |
312 | - # pobieranie wartosci aspektu | |
313 | - aspect_model = Frame_Char_Model.objects.get(model_name=u'ASPEKT') | |
314 | - aspect_vals_objs = aspect_model.frame_char_values.order_by('-priority') | |
315 | - aspect_str_list = [val.value for val in aspect_vals_objs] | |
316 | - | |
317 | - # pobieranie wartosci zwrotnosci | |
318 | - reflex_model = Frame_Char_Model.objects.get(model_name=u'ZWROTNOŚĆ') | |
319 | - reflex_vals_objs = reflex_model.frame_char_values.order_by('-priority') | |
320 | - reflex_str_list = [val.value for val in reflex_vals_objs] | |
321 | - | |
322 | - # pobieranie wartosci negatywnosci | |
323 | - neg_model = Frame_Char_Model.objects.get(model_name=u'NEGATYWNOŚĆ') | |
324 | - neg_vals_objs = neg_model.frame_char_values.order_by('-priority') | |
325 | - neg_str_list = [val.value for val in neg_vals_objs] | |
326 | - | |
327 | - # pobieranie wartosci predykatywnosci | |
328 | - pred_model = Frame_Char_Model.objects.get(model_name=u'PREDYKATYWNOŚĆ') | |
329 | - pred_vals_objs = pred_model.frame_char_values.order_by('-priority') | |
330 | - pred_str_list = [val.value for val in pred_vals_objs] | |
331 | - | |
332 | - # pobieranie opinii o schemacie | |
333 | - opinion_str_list = [val.value for val in Frame_Opinion_Value.objects.order_by('priority')] | |
334 | - | |
335 | - return {'reflex_options': reflex_str_list, | |
336 | - 'aspect_options': aspect_str_list, | |
337 | - 'neg_options': neg_str_list, | |
338 | - 'pred_options': pred_str_list, | |
339 | - 'opinion_options': opinion_str_list} | |
340 | - | |
315 | + return schemata_filter_options() | |
341 | 316 | |
342 | 317 | @render('lemma_desc.html') |
343 | 318 | @ajax(method='get', encode_result=False) |
... | ... | @@ -812,176 +787,15 @@ def get_sort_order(request): |
812 | 787 | |
813 | 788 | @render('filter_form.html') |
814 | 789 | @ajax(method='get', encode_result=False) |
815 | -def filter_form(request): | |
816 | - if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | |
817 | - if not request.session.has_key('filter_rules_lemma_preview'): | |
818 | - request.session['filter_rules_lemma_preview'] = default_filter_rules() | |
819 | - filter_rules = request.session['filter_rules_lemma_preview'] | |
820 | - else: | |
821 | - if not request.session.has_key('filter_rules'): | |
822 | - request.session['filter_rules'] = default_filter_rules() | |
823 | - filter_rules = request.session['filter_rules'] | |
824 | - | |
825 | - users = User.objects.none() | |
826 | - phraseologists = User.objects.none() | |
827 | - semanticists = User.objects.none() | |
828 | - vocabularies = Vocabulary.objects.none() | |
829 | - senders = User.objects.none() | |
830 | - statuses = get_anon_profile().visible_statuses.all() | |
831 | - can_confirm_example = False | |
832 | - if request.user.is_authenticated(): | |
833 | - users = User.objects.filter(lemmas__old=False).distinct().order_by('username') | |
834 | - phraseologists = User.objects.filter(phraseologist_lemmas__old=False).distinct().order_by('username') | |
835 | - semanticists = User.objects.filter(semanticist_lemmas__old=False).distinct().order_by('username') | |
836 | - vocabularies = request.user.visible_vocabularies.all() | |
837 | - senders = User.objects.order_by('groups__group_settings__priority') | |
838 | - statuses = Lemma_Status.objects.all() | |
839 | - if request.user.has_perm('dictionary.confirm_example') or request.user.is_superuser: | |
840 | - can_confirm_example = True | |
841 | - | |
842 | - form = FilterForm(users=users, | |
843 | - phraseologists=phraseologists, | |
844 | - semanticists=semanticists, | |
845 | - vocabularies=vocabularies, | |
846 | - senders=senders, | |
847 | - statuses=statuses, | |
848 | - sel_pos=filter_rules['pos'], | |
849 | - sel_user=filter_rules['owner'], | |
850 | - sel_phraseologist=filter_rules['phraseologist'], | |
851 | - sel_semanticist=filter_rules['semanticist'], | |
852 | - sel_vocabulary=filter_rules['vocabulary'], | |
853 | - sel_status=filter_rules['status'], | |
854 | - sel_reflex=filter_rules['reflex'], | |
855 | - sel_negativity=filter_rules['negativity'], | |
856 | - sel_predicativity=filter_rules['predicativity'], | |
857 | - sel_aspect=filter_rules['aspect'], | |
858 | - sel_has_argument=filter_rules['argument'], | |
859 | - sel_has_position=filter_rules['position'], | |
860 | - sel_frame_opinion=filter_rules['frame_opinion'], | |
861 | - can_confirm_example = can_confirm_example, | |
862 | - sel_example_source=filter_rules['example_source'], | |
863 | - sel_approver=filter_rules['approver'], | |
864 | - sel_sender=filter_rules['sender'], | |
865 | - frame_phraseologic=filter_rules['frame_phraseologic']) | |
790 | +def filter_form(request): | |
791 | + form = prepare_filter_form(request) | |
866 | 792 | return {'form': form} |
867 | 793 | |
868 | 794 | @ajax(method='post') |
869 | 795 | def filter_form_submit(request, form_data): |
870 | - filter_dict = dict((x['name'], x['value']) for x in form_data) | |
871 | - | |
872 | - if filter_dict['pos']: | |
873 | - pos_obj = POS.objects.get(id=filter_dict['pos']) | |
874 | - else: | |
875 | - pos_obj = None | |
876 | - | |
877 | - if filter_dict['owner']: | |
878 | - owner_obj = User.objects.get(id=filter_dict['owner']) | |
879 | - else: | |
880 | - owner_obj = None | |
881 | - | |
882 | - if filter_dict['phraseologist']: | |
883 | - phraseologist_obj = User.objects.get(id=filter_dict['phraseologist']) | |
884 | - else: | |
885 | - phraseologist_obj = None | |
886 | - | |
887 | - if filter_dict['semanticist']: | |
888 | - semanticist_obj = User.objects.get(id=filter_dict['semanticist']) | |
889 | - else: | |
890 | - semanticist_obj = None | |
891 | - | |
892 | - if filter_dict['vocabulary']: | |
893 | - vocabulary_obj = Vocabulary.objects.get(name=filter_dict['vocabulary']) | |
894 | - else: | |
895 | - vocabulary_obj = None | |
896 | - | |
897 | - if filter_dict['status']: | |
898 | - status_obj = Lemma_Status.objects.get(id=filter_dict['status']) | |
899 | - else: | |
900 | - status_obj = None | |
901 | - | |
902 | - if filter_dict['example_source']: | |
903 | - nkjp_source_obj = NKJP_Source.objects.get(id=filter_dict['example_source']) | |
904 | - else: | |
905 | - nkjp_source_obj = None | |
906 | - | |
907 | - if filter_dict['approver']: | |
908 | - approver_obj = User.objects.get(id=filter_dict['approver']) | |
909 | - else: | |
910 | - approver_obj = None | |
911 | - | |
912 | - if filter_dict['has_message_from']: | |
913 | - try: | |
914 | - sender_obj = User.objects.get(pk=filter_dict['has_message_from']) | |
915 | - except User.DoesNotExist: | |
916 | - sender_obj = None | |
917 | - else: | |
918 | - sender_obj = None | |
919 | - | |
920 | - reflex_obj, reflex_val = get_frame_char_and_its_value(filter_dict['reflex'], '*') | |
921 | - negativity_obj, negativity_val = get_frame_char_and_its_value(filter_dict['negativity'], '*') | |
922 | - aspect_obj, aspect_val = get_frame_char_and_its_value(filter_dict['aspect'], '*') | |
923 | - pred_obj, pred_val = get_frame_char_and_its_value(filter_dict['predicativity'], '*') | |
924 | - | |
925 | - argument = filter_dict['has_argument'] | |
926 | - position = filter_dict['has_position'] | |
927 | - | |
928 | - if filter_dict['frame_opinion']: | |
929 | - frame_opinion_obj = Frame_Opinion_Value.objects.get(id=filter_dict['frame_opinion']) | |
930 | - opinion_val = frame_opinion_obj.value | |
931 | - else: | |
932 | - frame_opinion_obj = None | |
933 | - opinion_val = '*' | |
934 | - | |
935 | - if 'frame_phraseologic' in filter_dict: | |
936 | - frame_phraseologic = filter_dict['frame_phraseologic'] | |
937 | - else: | |
938 | - frame_phraseologic = False | |
939 | - | |
940 | - if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | |
941 | - request.session['filter_rules_lemma_preview'] = {'pos' : pos_obj, | |
942 | - 'owner' : owner_obj, | |
943 | - 'phraseologist' : phraseologist_obj, | |
944 | - 'semanticist' : semanticist_obj, | |
945 | - 'vocabulary' : vocabulary_obj, | |
946 | - 'status' : status_obj, | |
947 | - 'example_source' : nkjp_source_obj, | |
948 | - 'approver' : approver_obj, | |
949 | - 'reflex' : reflex_obj, | |
950 | - 'negativity' : negativity_obj, | |
951 | - 'predicativity' : pred_obj, | |
952 | - 'aspect' : aspect_obj, | |
953 | - 'argument' : argument, | |
954 | - 'position' : position, | |
955 | - 'frame_opinion' : frame_opinion_obj, | |
956 | - 'sender' : sender_obj, | |
957 | - 'frame_phraseologic' : frame_phraseologic} | |
958 | - else: | |
959 | - request.session['filter_rules'] = {'pos' : pos_obj, | |
960 | - 'owner' : owner_obj, | |
961 | - 'phraseologist' : phraseologist_obj, | |
962 | - 'semanticist' : semanticist_obj, | |
963 | - 'vocabulary' : vocabulary_obj, | |
964 | - 'status' : status_obj, | |
965 | - 'example_source' : nkjp_source_obj, | |
966 | - 'approver' : approver_obj, | |
967 | - 'reflex' : reflex_obj, | |
968 | - 'negativity' : negativity_obj, | |
969 | - 'predicativity' : pred_obj, | |
970 | - 'aspect' : aspect_obj, | |
971 | - 'argument' : argument, | |
972 | - 'position' : position, | |
973 | - 'frame_opinion' : frame_opinion_obj, | |
974 | - 'sender' : sender_obj, | |
975 | - 'frame_phraseologic' : frame_phraseologic} | |
976 | - | |
977 | - return {'filter_frames': filter_dict['filter_frames'], | |
978 | - 'reflex' : reflex_val, | |
979 | - 'negativity' : negativity_val, | |
980 | - 'predicativity': pred_val, | |
981 | - 'opinion' : opinion_val, | |
982 | - 'aspect' : aspect_val, | |
983 | - 'position' : filter_dict['has_position'], | |
984 | - 'argument' : filter_dict['has_argument']} | |
796 | + filter_dict = dict((x['name'], x['value']) for x in form_data) | |
797 | + schemata_filter_options = save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict) | |
798 | + return schemata_filter_options | |
985 | 799 | |
986 | 800 | @ajax(method='post') |
987 | 801 | def save_columns(request, col_model, col_names, remap): |
... | ... | @@ -2842,9 +2656,36 @@ def arg_regex_frames(frames, string): |
2842 | 2656 | frames = frames.filter(reduce(operator.or_, alternative_queries)).distinct() |
2843 | 2657 | except: |
2844 | 2658 | frames = Frame.objects.none() |
2845 | - return frames | |
2659 | + return frames | |
2660 | + | |
2661 | +def lemma_regex_filter(lemmas, string): | |
2662 | + try: | |
2663 | + alternative_queries = [] | |
2664 | + for alternative in string.split('|'): | |
2665 | + possible_lemmas = lemmas | |
2666 | + for conj in alternative.split('&'): | |
2667 | + model_results = [] | |
2668 | + negation = False | |
2669 | + conj = conj.strip() | |
2670 | + if conj.startswith('!'): | |
2671 | + conj = conj.lstrip('!') | |
2672 | + negation = True | |
2673 | + regex = ur'^%s$' % escape_regex(conj) | |
2674 | + model_results = Lemma.objects.filter(old=False, | |
2675 | + entry_obj__name__regex=regex).distinct() | |
2676 | + if model_results.exists(): | |
2677 | + if negation: | |
2678 | + possible_lemmas = possible_lemmas.exclude(pk__in=model_results) | |
2679 | + else: | |
2680 | + possible_lemmas = possible_lemmas.filter(pk__in=model_results) | |
2681 | + elif not model_results.exists() and not negation: | |
2682 | + possible_lemmas = Lemma.objects.none() | |
2683 | + alternative_queries.append(Q(id__in=possible_lemmas)) | |
2684 | + lemmas = lemmas.filter(reduce(operator.or_, alternative_queries)).distinct() | |
2685 | + except: | |
2686 | + lemmas = Lemma.objects.none() | |
2687 | + return lemmas | |
2846 | 2688 | |
2847 | -# @TODO to co tutaj jest prezentowane jest bardzo glupie | |
2848 | 2689 | def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): |
2849 | 2690 | lemmas = Lemma.objects.none() |
2850 | 2691 | if user.is_authenticated(): |
... | ... | @@ -2877,9 +2718,33 @@ def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): |
2877 | 2718 | if filter_rules['status']: |
2878 | 2719 | lemmas = lemmas.filter(status=filter_rules['status']) |
2879 | 2720 | if filter_rules['frame_opinion']: |
2880 | - lemmas = lemmas.filter(frame_opinions__value=filter_rules['frame_opinion']) | |
2721 | + lemmas = lemmas.filter(frame_opinions__value=filter_rules['frame_opinion']) | |
2722 | + if filter_rules['lemma'] and filter_rules['lemma'] != '.*': | |
2723 | + lemmas = lemma_regex_filter(lemmas, filter_rules['lemma']) | |
2724 | + if filter_rules['sender']: | |
2725 | + lemmas = lemmas.filter(messages__sender=filter_rules['sender']) | |
2726 | + if filter_rules['pos']: | |
2727 | + lemmas = lemmas.filter(entry_obj__pos=filter_rules['pos']) | |
2728 | + if filter_rules['contains_phraseology']: | |
2729 | + phraseologic_lemmas = lemmas.filter(frames__phraseologic=True) | |
2730 | + if filter_rules['contains_phraseology'] == 'yes': | |
2731 | + lemmas = phraseologic_lemmas | |
2732 | + else: | |
2733 | + lemmas = lemmas.exclude(pk__in=phraseologic_lemmas) | |
2734 | + if filter_rules['example_source']: | |
2735 | + lemmas = lemmas.filter(Q(nkjp_examples__source=filter_rules['example_source']) & | |
2736 | + Q(nkjp_examples__approved=False)).distinct() | |
2737 | + napproved_examples = NKJP_Example.objects.filter(Q(source=filter_rules['example_source']) & | |
2738 | + Q(approved=False) & | |
2739 | + Q(lemmas__old=False) & | |
2740 | + ~Q(approvers=user)).distinct() | |
2741 | + | |
2742 | + if filter_rules['approver']: | |
2743 | + napproved_examples = napproved_examples.filter(approvers=filter_rules['approver']) | |
2744 | + lemmas = lemmas.filter(nkjp_examples__in=napproved_examples) | |
2745 | + lemmas = lemmas.distinct() | |
2881 | 2746 | |
2882 | - frames = Frame.objects.all() | |
2747 | + frames = Frame.objects | |
2883 | 2748 | if filter_rules['reflex']: |
2884 | 2749 | frames = frames.filter(characteristics=filter_rules['reflex']) |
2885 | 2750 | if filter_rules['negativity']: |
... | ... | @@ -2892,37 +2757,19 @@ def get_lemma_query(prepared_sort_rules, filter_rules, lemma_query, user): |
2892 | 2757 | frames = pos_regex_frames(frames, filter_rules['position']) |
2893 | 2758 | if filter_rules['argument'] and filter_rules['argument'] != '.*': |
2894 | 2759 | frames = arg_regex_frames(frames, filter_rules['argument']) |
2895 | - if filter_rules['frame_phraseologic']: | |
2896 | - frames = get_phraseologic_frames_only(frames) | |
2760 | + if filter_rules['schema_type']: | |
2761 | + frames = get_schemata_by_type(filter_rules['schema_type'], frames) | |
2897 | 2762 | |
2898 | 2763 | if (filter_rules['reflex'] or filter_rules['negativity'] or |
2899 | 2764 | filter_rules['aspect'] or filter_rules['predicativity'] or |
2900 | - filter_rules['frame_phraseologic'] or filter_rules['frame_opinion'] or | |
2765 | + filter_rules['schema_type'] or filter_rules['frame_opinion'] or | |
2901 | 2766 | (filter_rules['argument'] and filter_rules['argument'] != '.*') or |
2902 | 2767 | (filter_rules['position'] and filter_rules['position'] != '.*')): |
2903 | 2768 | if filter_rules['frame_opinion']: |
2904 | - lemmas = lemmas.filter(frame_opinions__frame__in=frames, | |
2769 | + lemmas = lemmas.filter(frame_opinions__frame__in=frames.all(), | |
2905 | 2770 | frame_opinions__value=filter_rules['frame_opinion']).distinct() |
2906 | 2771 | else: |
2907 | - lemmas = lemmas.filter(frames__in=frames).distinct() | |
2908 | - | |
2909 | - if filter_rules['sender']: | |
2910 | - lemmas = lemmas.filter(messages__sender=filter_rules['sender']) | |
2911 | - | |
2912 | - if filter_rules['pos']: | |
2913 | - lemmas = lemmas.filter(entry_obj__pos=filter_rules['pos']) | |
2914 | - | |
2915 | - if filter_rules['example_source']: | |
2916 | - lemmas = lemmas.filter(Q(nkjp_examples__source=filter_rules['example_source']) & | |
2917 | - Q(nkjp_examples__approved=False)).distinct() | |
2918 | - napproved_examples = NKJP_Example.objects.filter(Q(source=filter_rules['example_source']) & | |
2919 | - Q(approved=False) & | |
2920 | - Q(lemmas__old=False) & | |
2921 | - ~Q(approvers=user)).distinct() | |
2922 | - | |
2923 | - if filter_rules['approver']: | |
2924 | - napproved_examples = napproved_examples.filter(approvers=filter_rules['approver']) | |
2925 | - lemmas = lemmas.filter(nkjp_examples__in=napproved_examples) | |
2772 | + lemmas = lemmas.filter(frames__in=frames.all()).distinct() | |
2926 | 2773 | |
2927 | 2774 | lemmas = lemmas.distinct() |
2928 | 2775 | |
... | ... |
dictionary/filtering.py
0 → 100644
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | +from django.contrib.auth.models import User | |
4 | + | |
5 | +from accounts.models import get_anon_profile | |
6 | +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 | |
10 | + | |
11 | +def schemata_filter_options(): | |
12 | + # pobieranie wartosci aspektu | |
13 | + aspect_model = Frame_Char_Model.objects.get(model_name=u'ASPEKT') | |
14 | + aspect_vals_objs = aspect_model.frame_char_values.order_by('-priority') | |
15 | + aspect_options = [{'name': '*', 'value': '*'}] | |
16 | + aspect_options.extend([{'name': val.value, 'value': val.value} for val in aspect_vals_objs]) | |
17 | + | |
18 | + # pobieranie wartosci zwrotnosci | |
19 | + reflex_model = Frame_Char_Model.objects.get(model_name=u'ZWROTNOŚĆ') | |
20 | + reflex_vals_objs = reflex_model.frame_char_values.order_by('-priority') | |
21 | + reflex_options = [{'name': '*', 'value': '*'}] | |
22 | + reflex_options.extend([{'name': val.value, 'value': val.value} for val in reflex_vals_objs]) | |
23 | + | |
24 | + # pobieranie wartosci negatywnosci | |
25 | + neg_model = Frame_Char_Model.objects.get(model_name=u'NEGATYWNOŚĆ') | |
26 | + neg_vals_objs = neg_model.frame_char_values.order_by('-priority') | |
27 | + neg_options = [{'name': '*', 'value': '*'}] | |
28 | + neg_options.extend([{'name': val.value, 'value': val.value} for val in neg_vals_objs]) | |
29 | + | |
30 | + # pobieranie wartosci predykatywnosci | |
31 | + pred_model = Frame_Char_Model.objects.get(model_name=u'PREDYKATYWNOŚĆ') | |
32 | + pred_vals_objs = pred_model.frame_char_values.order_by('-priority') | |
33 | + pred_options = [{'name': '*', 'value': '*'}] | |
34 | + pred_options.extend([{'name': val.value, 'value': val.value} for val in pred_vals_objs]) | |
35 | + | |
36 | + # pobieranie opinii o schemacie | |
37 | + opinion_options = [{'name': '*', 'value': '*'}] | |
38 | + opinion_options.extend([{'name': val.value, 'value': val.value} for val in Frame_Opinion_Value.objects.order_by('priority')]) | |
39 | + | |
40 | + schema_type_options = [{'name': '*', 'value': '*'}, | |
41 | + {'name': 'normalny', 'value': 'normal'}, | |
42 | + {'name': 'frazeologiczny', 'value': 'phraseologic'}] | |
43 | + | |
44 | + return {'schema_type_options': schema_type_options, | |
45 | + 'reflex_options': reflex_options, | |
46 | + 'aspect_options': aspect_options, | |
47 | + 'neg_options': neg_options, | |
48 | + 'pred_options': pred_options, | |
49 | + 'opinion_options': opinion_options} | |
50 | + | |
51 | +def all_filter_rules_loaded(rules): | |
52 | + if set(default_filter_rules().keys()) != set(rules): | |
53 | + return False | |
54 | + return True | |
55 | + | |
56 | +def default_filter_rules(): | |
57 | + return {'lemma': '.*', | |
58 | + 'pos': None, | |
59 | + 'contains_phraseology': None, | |
60 | + 'owner': None, | |
61 | + 'phraseologist': None, | |
62 | + 'semanticist': None, | |
63 | + 'vocabulary': None, | |
64 | + 'status': None, | |
65 | + 'example_source': None, | |
66 | + 'approver': None, | |
67 | + 'reflex': None, | |
68 | + 'negativity': None, | |
69 | + 'predicativity': None, | |
70 | + 'aspect': None, | |
71 | + 'argument': '.*', | |
72 | + 'position': '.*', | |
73 | + 'frame_opinion' : None, | |
74 | + 'sender': None, | |
75 | + 'schema_type': None} | |
76 | + | |
77 | +def prepare_filter_form(request): | |
78 | + if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | |
79 | + if not request.session.has_key('filter_rules_lemma_preview'): | |
80 | + request.session['filter_rules_lemma_preview'] = default_filter_rules() | |
81 | + filter_rules = request.session['filter_rules_lemma_preview'] | |
82 | + else: | |
83 | + if not request.session.has_key('filter_rules'): | |
84 | + request.session['filter_rules'] = default_filter_rules() | |
85 | + filter_rules = request.session['filter_rules'] | |
86 | + | |
87 | + users = User.objects.none() | |
88 | + phraseologists = User.objects.none() | |
89 | + semanticists = User.objects.none() | |
90 | + vocabularies = Vocabulary.objects.none() | |
91 | + senders = User.objects.none() | |
92 | + statuses = get_anon_profile().visible_statuses.all() | |
93 | + can_confirm_example = False | |
94 | + if request.user.is_authenticated(): | |
95 | + users = User.objects.filter(lemmas__old=False).distinct().order_by('username') | |
96 | + phraseologists = User.objects.filter(phraseologist_lemmas__old=False).distinct().order_by('username') | |
97 | + semanticists = User.objects.filter(semanticist_lemmas__old=False).distinct().order_by('username') | |
98 | + vocabularies = request.user.visible_vocabularies.all() | |
99 | + senders = User.objects.order_by('groups__group_settings__priority') | |
100 | + statuses = Lemma_Status.objects.all() | |
101 | + if request.user.has_perm('dictionary.confirm_example') or request.user.is_superuser: | |
102 | + can_confirm_example = True | |
103 | + | |
104 | + form = FilterForm(users=users, | |
105 | + phraseologists=phraseologists, | |
106 | + semanticists=semanticists, | |
107 | + vocabularies=vocabularies, | |
108 | + senders=senders, | |
109 | + statuses=statuses, | |
110 | + lemma=filter_rules['lemma'], | |
111 | + sel_pos=filter_rules['pos'], | |
112 | + contains_phraseology=filter_rules['contains_phraseology'], | |
113 | + sel_user=filter_rules['owner'], | |
114 | + sel_phraseologist=filter_rules['phraseologist'], | |
115 | + sel_semanticist=filter_rules['semanticist'], | |
116 | + sel_vocabulary=filter_rules['vocabulary'], | |
117 | + sel_status=filter_rules['status'], | |
118 | + sel_reflex=filter_rules['reflex'], | |
119 | + sel_negativity=filter_rules['negativity'], | |
120 | + sel_predicativity=filter_rules['predicativity'], | |
121 | + sel_aspect=filter_rules['aspect'], | |
122 | + sel_has_argument=filter_rules['argument'], | |
123 | + sel_has_position=filter_rules['position'], | |
124 | + sel_frame_opinion=filter_rules['frame_opinion'], | |
125 | + can_confirm_example = can_confirm_example, | |
126 | + sel_example_source=filter_rules['example_source'], | |
127 | + sel_approver=filter_rules['approver'], | |
128 | + sel_sender=filter_rules['sender'], | |
129 | + sel_schema_type=filter_rules['schema_type']) | |
130 | + return form | |
131 | + | |
132 | +def save_lemma_filters_and_get_schemata_filter_setup(request, filter_dict): | |
133 | + if filter_dict['pos']: | |
134 | + pos_obj = POS.objects.get(id=filter_dict['pos']) | |
135 | + else: | |
136 | + pos_obj = None | |
137 | + | |
138 | + if filter_dict['owner']: | |
139 | + owner_obj = User.objects.get(id=filter_dict['owner']) | |
140 | + else: | |
141 | + owner_obj = None | |
142 | + | |
143 | + if filter_dict['phraseologist']: | |
144 | + phraseologist_obj = User.objects.get(id=filter_dict['phraseologist']) | |
145 | + else: | |
146 | + phraseologist_obj = None | |
147 | + | |
148 | + if filter_dict['semanticist']: | |
149 | + semanticist_obj = User.objects.get(id=filter_dict['semanticist']) | |
150 | + else: | |
151 | + semanticist_obj = None | |
152 | + | |
153 | + if filter_dict['vocabulary']: | |
154 | + vocabulary_obj = Vocabulary.objects.get(name=filter_dict['vocabulary']) | |
155 | + else: | |
156 | + vocabulary_obj = None | |
157 | + | |
158 | + if filter_dict['status']: | |
159 | + status_obj = Lemma_Status.objects.get(id=filter_dict['status']) | |
160 | + else: | |
161 | + status_obj = None | |
162 | + | |
163 | + if filter_dict['example_source']: | |
164 | + nkjp_source_obj = NKJP_Source.objects.get(id=filter_dict['example_source']) | |
165 | + else: | |
166 | + nkjp_source_obj = None | |
167 | + | |
168 | + if filter_dict['approver']: | |
169 | + approver_obj = User.objects.get(id=filter_dict['approver']) | |
170 | + else: | |
171 | + approver_obj = None | |
172 | + | |
173 | + if filter_dict['has_message_from']: | |
174 | + try: | |
175 | + sender_obj = User.objects.get(pk=filter_dict['has_message_from']) | |
176 | + except User.DoesNotExist: | |
177 | + sender_obj = None | |
178 | + else: | |
179 | + sender_obj = None | |
180 | + | |
181 | + reflex_obj, reflex_val = get_frame_char_and_its_value(filter_dict['reflex'], '*') | |
182 | + negativity_obj, negativity_val = get_frame_char_and_its_value(filter_dict['negativity'], '*') | |
183 | + 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'], '*') | |
185 | + | |
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 | |
189 | + else: | |
190 | + frame_opinion_obj = None | |
191 | + opinion_val = '*' | |
192 | + | |
193 | + if 'schema_type' in filter_dict: | |
194 | + schema_type = filter_dict['schema_type'] | |
195 | + else: | |
196 | + schema_type = None | |
197 | + if request.session.has_key('lemma_preview') and request.session['lemma_preview']: | |
198 | + request.session['filter_rules_lemma_preview'] = {'pos' : pos_obj, | |
199 | + 'contains_phraseology': filter_dict['contains_phraseology'], | |
200 | + 'owner' : owner_obj, | |
201 | + 'phraseologist' : phraseologist_obj, | |
202 | + 'semanticist' : semanticist_obj, | |
203 | + 'vocabulary' : vocabulary_obj, | |
204 | + 'status' : status_obj, | |
205 | + 'example_source' : nkjp_source_obj, | |
206 | + 'approver' : approver_obj, | |
207 | + 'reflex' : reflex_obj, | |
208 | + 'negativity' : negativity_obj, | |
209 | + 'predicativity' : pred_obj, | |
210 | + 'aspect' : aspect_obj, | |
211 | + 'argument' : filter_dict['has_argument'], | |
212 | + 'position' : filter_dict['has_position'], | |
213 | + 'lemma' : filter_dict['lemma'], | |
214 | + 'frame_opinion' : frame_opinion_obj, | |
215 | + 'sender' : sender_obj, | |
216 | + 'schema_type' : schema_type} | |
217 | + else: | |
218 | + request.session['filter_rules'] = {'pos' : pos_obj, | |
219 | + 'contains_phraseology': filter_dict['contains_phraseology'], | |
220 | + 'owner' : owner_obj, | |
221 | + 'phraseologist' : phraseologist_obj, | |
222 | + 'semanticist' : semanticist_obj, | |
223 | + 'vocabulary' : vocabulary_obj, | |
224 | + 'status' : status_obj, | |
225 | + 'example_source' : nkjp_source_obj, | |
226 | + 'approver' : approver_obj, | |
227 | + 'reflex' : reflex_obj, | |
228 | + 'negativity' : negativity_obj, | |
229 | + 'predicativity' : pred_obj, | |
230 | + 'aspect' : aspect_obj, | |
231 | + 'argument' : filter_dict['has_argument'], | |
232 | + 'position' : filter_dict['has_position'], | |
233 | + 'lemma' : filter_dict['lemma'], | |
234 | + 'frame_opinion' : frame_opinion_obj, | |
235 | + 'sender' : sender_obj, | |
236 | + 'schema_type' : schema_type} | |
237 | + | |
238 | + return {'filter_frames': filter_dict['filter_frames'], | |
239 | + 'schema_type' : schema_type, | |
240 | + 'reflex' : reflex_val, | |
241 | + 'negativity' : negativity_val, | |
242 | + 'predicativity': pred_val, | |
243 | + 'opinion' : opinion_val, | |
244 | + 'aspect' : aspect_val, | |
245 | + 'position' : filter_dict['has_position'], | |
246 | + 'argument' : filter_dict['has_argument']} | |
... | ... |
dictionary/forms.py
... | ... | @@ -529,9 +529,19 @@ class MessageForm(ModelForm): |
529 | 529 | exclude = ('sender', 'lemma', 'new', 'recipient') |
530 | 530 | |
531 | 531 | |
532 | -############################ sorting, filtering | |
532 | +############################ 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 | + | |
533 | 539 | class FilterForm(Form): |
540 | + # Lemma filters | |
541 | + lemma = forms.CharField(label=u'Lemat', required=False) | |
534 | 542 | pos = ModelChoiceField(label=u'Część mowy', queryset=POS.objects.none(), required=False) |
543 | + contains_phraseology = ChoiceField(choices=[('', '---------'), ('yes', 'zawiera'), ('no', 'nie zawiera')], | |
544 | + label=u'Frazeologia', required=False) | |
535 | 545 | owner = ModelChoiceField(label=u'Właściciel', queryset=User.objects.none(), required=False) |
536 | 546 | phraseologist = ModelChoiceField(label=u'Frazeolog', queryset=User.objects.none(), required=False) |
537 | 547 | semanticist = ModelChoiceField(label=u'Semantyk', queryset=User.objects.none(), required=False) |
... | ... | @@ -544,7 +554,10 @@ class FilterForm(Form): |
544 | 554 | approver = ModelChoiceField(label=u'Zatwierdzający przykład', queryset=User.objects.filter(Q(groups__permissions__codename='confirm_example') | |
545 | 555 | Q(is_superuser=True)).distinct().order_by('username'), |
546 | 556 | required=False) |
547 | - reflex = ModelChoiceField(label=u'Zwrotność', | |
557 | + # Schema filters | |
558 | + schema_type = ChoiceField(choices=[('', '---------'), ('normal', 'normalny'), ('phraseologic', 'frazeologiczny')], | |
559 | + label=u'Typ schematu', required=False) | |
560 | + reflex = ModelChoiceField(label=u'Zwrotność', | |
548 | 561 | queryset=Frame_Characteristic.objects.filter(type=u'ZWROTNOŚĆ').order_by('value__priority'), |
549 | 562 | required=False) |
550 | 563 | negativity = ModelChoiceField(label=u'Negatywność', |
... | ... | @@ -560,26 +573,32 @@ class FilterForm(Form): |
560 | 573 | has_position = forms.CharField(label=u'Zawiera pozycję', required=False) |
561 | 574 | frame_opinion = ModelChoiceField(label=u'Opinia o schemacie', queryset=Frame_Opinion_Value.objects.all(), |
562 | 575 | required=False) |
563 | - frame_phraseologic = forms.BooleanField(label=u'Schemat frazeologiczny', initial=False, | |
564 | - required=False) | |
565 | 576 | filter_frames = forms.BooleanField(label=u'Odfiltruj niepasujące schematy', initial=False, |
566 | 577 | required=False) |
578 | + # Frame filters | |
579 | +# role = | |
580 | +# selective_preferences = | |
581 | +# opinion = | |
567 | 582 | |
568 | 583 | def __init__(self, users, phraseologists, semanticists, vocabularies, statuses, senders, |
569 | - sel_pos=None, sel_user=None, sel_phraseologist=None, sel_semanticist=None, | |
570 | - sel_vocabulary=None, sel_status=None, frame_phraseologic=False,#sel_old_property=None, | |
584 | + lemma='.*', sel_pos=None, contains_phraseology=None, | |
585 | + sel_user=None, sel_phraseologist=None, sel_semanticist=None, | |
586 | + sel_vocabulary=None, sel_status=None, sel_schema_type=None, | |
571 | 587 | sel_reflex=None, sel_negativity=None, sel_predicativity=None, |
572 | - sel_aspect=None, sel_has_argument='.*', sel_has_position='.*', #sel_has_frame='.*', | |
588 | + sel_aspect=None, sel_has_argument='.*', sel_has_position='.*', | |
573 | 589 | sel_frame_opinion=None, can_confirm_example=False, sel_example_source=None, |
574 | 590 | sel_approver=None, sel_sender=None, *args, **kwargs): |
575 | 591 | super(FilterForm, self).__init__(*args, **kwargs) |
592 | + | |
576 | 593 | self.fields['pos'].queryset = POS.objects.exclude(tag='unk') |
577 | 594 | self.fields['owner'].queryset = users |
578 | 595 | self.fields['phraseologist'].queryset = phraseologists |
579 | 596 | self.fields['semanticist'].queryset = semanticists |
580 | 597 | self.fields['vocabulary'].queryset = vocabularies |
581 | 598 | self.fields['status'].queryset = statuses |
599 | + self.fields['lemma'].initial = lemma | |
582 | 600 | self.fields['pos'].initial = sel_pos |
601 | + self.fields['contains_phraseology'].initial = contains_phraseology | |
583 | 602 | self.fields['owner'].initial = sel_user |
584 | 603 | self.fields['phraseologist'].initial = sel_phraseologist |
585 | 604 | self.fields['semanticist'].initial = sel_semanticist |
... | ... | @@ -605,7 +624,7 @@ class FilterForm(Form): |
605 | 624 | self.fields['has_message_from'].initial = sel_sender |
606 | 625 | self.fields['has_message_from'].queryset = senders |
607 | 626 | |
608 | - self.fields['frame_phraseologic'].initial = frame_phraseologic | |
627 | + self.fields['schema_type'].initial = sel_schema_type | |
609 | 628 | |
610 | 629 | self.hide_unused_fields() |
611 | 630 | |
... | ... |
dictionary/models.py
... | ... | @@ -453,15 +453,22 @@ def positions_to_frame(positions, reflex, negativity, predicativity, aspect): |
453 | 453 | if frame_obj.has_phraseologic_arguments(): |
454 | 454 | frame_obj.phraseologic = True |
455 | 455 | frame_obj.save() |
456 | - return frame_obj | |
456 | + return frame_obj | |
457 | 457 | |
458 | -def get_phraseologic_frames_only(frames_query): | |
459 | - frames_query = frames_query.filter(phraseologic=True) | |
460 | -# phraseologic_arg_models = Argument_Model.objects.filter(phraseologic=True) | |
461 | -# phraseologic_arg_models_names = [arg_model.arg_model_name for arg_model in phraseologic_arg_models.all()] | |
462 | -# frames_query = frames_query.filter(Q(positions__arguments__type__in=phraseologic_arg_models_names) | | |
463 | -# Q(positions__arguments__atributes__values__argument__type__in=phraseologic_arg_models_names)) | |
464 | - return frames_query | |
458 | +def get_schemata_by_type(sch_type, schemata_query): | |
459 | + if sch_type == 'normal': | |
460 | + schemata_query = get_normal_schemata_only(schemata_query) | |
461 | + elif sch_type == 'phraseologic': | |
462 | + schemata_query = get_phraseologic_schemata_only(schemata_query) | |
463 | + return schemata_query | |
464 | + | |
465 | +def get_normal_schemata_only(schemata_query): | |
466 | + schemata_query = schemata_query.filter(phraseologic=False) | |
467 | + return schemata_query | |
468 | + | |
469 | +def get_phraseologic_schemata_only(schemata_query): | |
470 | + schemata_query = schemata_query.filter(phraseologic=True) | |
471 | + return schemata_query | |
465 | 472 | |
466 | 473 | |
467 | 474 | class NKJP_Example(Model): |
... | ... |
dictionary/static/js/lemma-view.js
... | ... | @@ -22,25 +22,6 @@ var nkjp_source_tab = ax_nkjp_source_vals; |
22 | 22 | // te wartosci maja zasieg na wszystkie hasla |
23 | 23 | window.schemas = new Array(); |
24 | 24 | var lemma_id = -1; |
25 | - var aspect_vals = []; | |
26 | - var reflex_vals = []; | |
27 | - var neg_vals = []; | |
28 | - var pred_vals = []; | |
29 | - var opinion_vals = []; | |
30 | - var filter_aspect_val = '*'; | |
31 | - var filter_reflex_val = '*'; | |
32 | - var filter_neg_val = '*'; | |
33 | - var filter_pred_val = '*'; | |
34 | - var filter_opinion_val = '*'; | |
35 | - var filter_position_val = '.*'; | |
36 | - var filter_argument_val = '.*'; | |
37 | - var prev_filter_aspect_val = '*'; | |
38 | - var prev_filter_reflex_val = '*'; | |
39 | - var prev_filter_neg_val = '*'; | |
40 | - var prev_filter_pred_val = '*'; | |
41 | - var prev_filter_opinion_val = '*'; | |
42 | - var prev_filter_position_val = '.*'; | |
43 | - var prev_filter_argument_val = '.*'; | |
44 | 25 | var prev_lemma_id = -1; |
45 | 26 | |
46 | 27 | // te wartosci trzeba czyscic przy ladowaniu innego hasla |
... | ... | @@ -84,33 +65,6 @@ function resetLemmaVersions() { |
84 | 65 | window.nkjp_lemma_examples); |
85 | 66 | frames_modif.push(lemma_version); |
86 | 67 | } |
87 | - | |
88 | -function initiateFrameFilters() | |
89 | -{ | |
90 | - $.ajaxJSON({ | |
91 | - method: 'get', | |
92 | - url: ajax_get_frame_filter_options, | |
93 | - data: { | |
94 | - //message_id: message_id, | |
95 | - }, | |
96 | - callback: function(result) { | |
97 | - window.aspect_vals = ['*']; | |
98 | - window.reflex_vals = ['*']; | |
99 | - window.neg_vals = ['*']; | |
100 | - window.pred_vals = ['*']; | |
101 | - window.opinion_vals = ['*']; | |
102 | - $.merge(window.aspect_vals, result['aspect_options']); | |
103 | - $.merge(window.reflex_vals, result['reflex_options']); | |
104 | - $.merge(window.neg_vals, result['neg_options']); | |
105 | - $.merge(window.pred_vals, result['pred_options']); | |
106 | - $.merge(window.opinion_vals, result['opinion_options']); | |
107 | - }, | |
108 | - | |
109 | - error_callback: function(xhr, status, error) { | |
110 | - error_alert(status + ': ' + error); | |
111 | - }, | |
112 | - }); | |
113 | -} | |
114 | 68 | |
115 | 69 | function argsToRemove(example, elementToRemoveId) |
116 | 70 | { |
... | ... | @@ -211,196 +165,6 @@ function addPinnedExamplesDialog() { |
211 | 165 | |
212 | 166 | /////////////////////////////////////////////////////////////// |
213 | 167 | |
214 | -function filter_update(id) | |
215 | -{ | |
216 | - if(id == 'frame_filter') | |
217 | - { | |
218 | - window.filter_aspect_val = $('#frame_filter #aspect_filter').val(); | |
219 | - window.filter_reflex_val = $('#frame_filter #reflex_filter').val(); | |
220 | - window.filter_neg_val = $('#frame_filter #neg_filter').val(); | |
221 | - window.filter_pred_val = $('#frame_filter #pred_filter').val(); | |
222 | - window.filter_opinion_val = $('#frame_filter #opinion_filter').val(); | |
223 | - window.filter_position_val = $('#frame_filter #position_filter').val(); | |
224 | - window.filter_argument_val = $('#frame_filter #argument_filter').val(); | |
225 | - } | |
226 | - else if(id == 'prev_frame_filter') | |
227 | - { | |
228 | - window.prev_filter_aspect_val = $('#prev_frame_filter #aspect_filter').val(); | |
229 | - window.prev_filter_reflex_val = $('#prev_frame_filter #reflex_filter').val(); | |
230 | - window.prev_filter_neg_val = $('#prev_frame_filter #neg_filter').val(); | |
231 | - window.prev_filter_pred_val = $('#prev_frame_filter #pred_filter').val(); | |
232 | - window.prev_filter_opinion_val = $('#prev_frame_filter #opinion_filter').val(); | |
233 | - window.prev_filter_position_val = $('#prev_frame_filter #position_filter').val(); | |
234 | - window.prev_filter_argument_val = $('#prev_frame_filter #argument_filter').val(); | |
235 | - } | |
236 | -} | |
237 | - | |
238 | - | |
239 | -function draw_frames_filter(id) | |
240 | -{ | |
241 | - var frame_filter = document.getElementById(id); | |
242 | - | |
243 | - p = document.createElement('p'); | |
244 | - text = document.createTextNode("Aspekt: "); | |
245 | - p.appendChild(text); | |
246 | - var select = document.createElement('select'); | |
247 | - select.setAttribute('id', 'aspect_filter'); | |
248 | - select.setAttribute('name', 'ASPEKT'); | |
249 | - p.appendChild(select); | |
250 | - for(var i=0; i<aspect_vals.length; i++) | |
251 | - { | |
252 | - var option = document.createElement('option'); | |
253 | - option.setAttribute('value', aspect_vals[i]); | |
254 | - option.appendChild(document.createTextNode(aspect_vals[i])); | |
255 | - select.appendChild(option); | |
256 | - } | |
257 | - frame_filter.appendChild(p); | |
258 | - | |
259 | - p = document.createElement('p'); | |
260 | - text = document.createTextNode("Zwrotność: "); | |
261 | - p.appendChild(text); | |
262 | - select = document.createElement('select'); | |
263 | - select.setAttribute('id', 'reflex_filter'); | |
264 | - select.setAttribute('name', 'ZWROTNOSC'); | |
265 | - p.appendChild(select); | |
266 | - for(var i=0; i<reflex_vals.length; i++) | |
267 | - { | |
268 | - var option = document.createElement('option'); | |
269 | - option.setAttribute('value', reflex_vals[i]); | |
270 | - option.appendChild(document.createTextNode(reflex_vals[i])); | |
271 | - select.appendChild(option); | |
272 | - } | |
273 | - frame_filter.appendChild(p); | |
274 | - | |
275 | - p = document.createElement('p'); | |
276 | - text = document.createTextNode("Negatywność: "); | |
277 | - p.appendChild(text); | |
278 | - select = document.createElement('select'); | |
279 | - select.setAttribute('id', 'neg_filter'); | |
280 | - select.setAttribute('name', 'NEGATYWNOŚĆ'); | |
281 | - p.appendChild(select); | |
282 | - for(var i=0; i<neg_vals.length; i++) | |
283 | - { | |
284 | - var option = document.createElement('option'); | |
285 | - option.setAttribute('value', neg_vals[i]); | |
286 | - option.appendChild(document.createTextNode(neg_vals[i])); | |
287 | - select.appendChild(option); | |
288 | - } | |
289 | - frame_filter.appendChild(p); | |
290 | - | |
291 | - p = document.createElement('p'); | |
292 | - text = document.createTextNode("Predykatywność: "); | |
293 | - p.appendChild(text); | |
294 | - select = document.createElement('select'); | |
295 | - select.setAttribute('id', 'pred_filter'); | |
296 | - select.setAttribute('name', 'PREDYKATYWNOŚĆ'); | |
297 | - p.appendChild(select); | |
298 | - for(var i=0; i<pred_vals.length; i++) | |
299 | - { | |
300 | - var option = document.createElement('option'); | |
301 | - option.setAttribute('value', pred_vals[i]); | |
302 | - option.appendChild(document.createTextNode(pred_vals[i])); | |
303 | - select.appendChild(option); | |
304 | - } | |
305 | - frame_filter.appendChild(p); | |
306 | - | |
307 | - p = document.createElement('p'); | |
308 | - text = document.createTextNode("Opinia: "); | |
309 | - p.appendChild(text); | |
310 | - select = document.createElement('select'); | |
311 | - select.setAttribute('id', 'opinion_filter'); | |
312 | - select.setAttribute('name', 'OPINIA'); | |
313 | - p.appendChild(select); | |
314 | - for(var i=0; i<opinion_vals.length; i++) | |
315 | - { | |
316 | - var option = document.createElement('option'); | |
317 | - option.setAttribute('value', opinion_vals[i]); | |
318 | - option.appendChild(document.createTextNode(opinion_vals[i])); | |
319 | - select.appendChild(option); | |
320 | - } | |
321 | - frame_filter.appendChild(p); | |
322 | - | |
323 | - p = document.createElement('p'); | |
324 | - text = document.createTextNode("Typ frazy: "); | |
325 | - p.appendChild(text); | |
326 | - select = document.createElement('input'); | |
327 | - select.setAttribute('id', 'argument_filter'); | |
328 | - select.setAttribute('name', 'ARGUMENT'); | |
329 | - p.appendChild(select); | |
330 | - frame_filter.appendChild(p); | |
331 | - | |
332 | - p = document.createElement('p'); | |
333 | - text = document.createTextNode("Pozycja: "); | |
334 | - p.appendChild(text); | |
335 | - select = document.createElement('input'); | |
336 | - select.setAttribute('id', 'position_filter'); | |
337 | - select.setAttribute('name', 'POZYCJA'); | |
338 | - p.appendChild(select); | |
339 | - frame_filter.appendChild(p); | |
340 | - | |
341 | - if(id == 'frame_filter') | |
342 | - { | |
343 | - $('#frame_filter #aspect_filter').val(window.filter_aspect_val); | |
344 | - $('#frame_filter #reflex_filter').val(window.filter_reflex_val); | |
345 | - $('#frame_filter #neg_filter').val(window.filter_neg_val); | |
346 | - $('#frame_filter #pred_filter').val(window.filter_pred_val); | |
347 | - $('#frame_filter #opinion_filter').val(window.filter_opinion_val); | |
348 | - $('#frame_filter #position_filter').val(window.filter_position_val); | |
349 | - $('#frame_filter #argument_filter').val(window.filter_argument_val); | |
350 | - } | |
351 | - else if(id == 'prev_frame_filter') | |
352 | - { | |
353 | - $('#prev_frame_filter #aspect_filter').val(window.prev_filter_aspect_val); | |
354 | - $('#prev_frame_filter #reflex_filter').val(window.prev_filter_reflex_val); | |
355 | - $('#prev_frame_filter #neg_filter').val(window.prev_filter_neg_val); | |
356 | - $('#prev_frame_filter #pred_filter').val(window.prev_filter_pred_val); | |
357 | - $('#prev_frame_filter #opinion_filter').val(window.prev_filter_opinion_val); | |
358 | - $('#prev_frame_filter #position_filter').val(window.prev_filter_position_val); | |
359 | - $('#prev_frame_filter #argument_filter').val(window.prev_filter_argument_val); | |
360 | - } | |
361 | - | |
362 | - //attach autocomplete | |
363 | - $('#' + id + ' #argument_filter').autocomplete({ | |
364 | - // triggers when selection performed | |
365 | - select: function(event, ui){ | |
366 | - filter_update(id); | |
367 | - }, | |
368 | - //define callback to format results | |
369 | - source: function(req, add){ | |
370 | - //pass request to server | |
371 | - $.getJSON(ajax_argument_lookup, req, function(data) { | |
372 | - //create array for response objects | |
373 | - var suggestions = []; | |
374 | - $.each(data['result'], function(i, val){ | |
375 | - suggestions.push(val[0]); | |
376 | - }); | |
377 | - //pass array to callback | |
378 | - add(suggestions); | |
379 | - }); | |
380 | - }, | |
381 | - }); | |
382 | - $('#' + id + ' #position_filter').autocomplete({ | |
383 | - // triggers when selection performed | |
384 | - select: function(event, ui){ | |
385 | - filter_update(id); | |
386 | - }, | |
387 | - //define callback to format results | |
388 | - source: function(req, add){ | |
389 | - //pass request to server | |
390 | - $.getJSON(ajax_position_lookup, req, function(data) { | |
391 | - //create array for response objects | |
392 | - var suggestions = []; | |
393 | - $.each(data['result'], function(i, val){ | |
394 | - suggestions.push(val[0]); | |
395 | - }); | |
396 | - //pass array to callback | |
397 | - add(suggestions); | |
398 | - }); | |
399 | - }, | |
400 | - }); | |
401 | -} | |
402 | - | |
403 | - | |
404 | 168 | function load_content(id) { |
405 | 169 | $('#add-table-elem-dialog').dialog('close'); |
406 | 170 | if(lemma_id != id) |
... | ... | @@ -1152,17 +916,17 @@ function draw_frames(schemas, parent, table_name, nkjp_examples, table_class, le |
1152 | 916 | first = true; |
1153 | 917 | for(var j=0; j<schemas.length; j++) |
1154 | 918 | { |
1155 | - if(schemas[j].characteristics[3]==aspect_vals[k] && schemas[j].characteristics[0]==reflex_vals[i] && | |
1156 | - schemas[j].characteristics[1]==neg_vals[l] && schemas[j].characteristics[2]==pred_vals[m]) | |
919 | + if(schemas[j].characteristics[3]==aspect_vals[k].value && schemas[j].characteristics[0]==reflex_vals[i].value && | |
920 | + schemas[j].characteristics[1]==neg_vals[l].value && schemas[j].characteristics[2]==pred_vals[m].value) | |
1157 | 921 | { |
1158 | 922 | if(first) |
1159 | 923 | { |
1160 | 924 | div = document.createElement('div'); |
1161 | 925 | strong = document.createElement('strong'); |
1162 | - if(reflex_vals[i]) | |
1163 | - strong.appendChild(document.createTextNode(lemma_entry+" "+reflex_vals[i]+" "+"("+neg_vals[l]+","+pred_vals[m]+","+aspect_vals[k]+"):")); | |
926 | + if(reflex_vals[i].value) | |
927 | + strong.appendChild(document.createTextNode(lemma_entry+" "+reflex_vals[i].name+" "+"("+neg_vals[l].name+","+pred_vals[m].name+","+aspect_vals[k].name+"):")); | |
1164 | 928 | else |
1165 | - strong.appendChild(document.createTextNode(lemma_entry+" "+"("+neg_vals[l]+","+pred_vals[m]+","+aspect_vals[k]+"):")); | |
929 | + strong.appendChild(document.createTextNode(lemma_entry+" "+"("+neg_vals[l].name+","+pred_vals[m].name+","+aspect_vals[k].name+"):")); | |
1166 | 930 | div.appendChild(strong); |
1167 | 931 | parent.appendChild(div); |
1168 | 932 | first = false; |
... | ... | @@ -3244,125 +3008,6 @@ function escape_regex(str) |
3244 | 3008 | split('}').join('\\}') |
3245 | 3009 | } |
3246 | 3010 | |
3247 | -function has_positions(frame, pos_term) | |
3248 | -{ | |
3249 | - var alternatives = pos_term.split('|'); | |
3250 | - for(var h=0; h<alternatives.length; h++) { | |
3251 | - var allConjsMatch = true; | |
3252 | - var conjs = alternatives[h].split('&'); | |
3253 | - | |
3254 | - for(var i=0; i<conjs.length; i++) { | |
3255 | - try { | |
3256 | - var matched_poss = []; | |
3257 | - var conj = conjs[i].trim(); | |
3258 | - var regEx = conj; | |
3259 | - if (regEx.substring(0, 1) == '!') { | |
3260 | - regEx = regEx.substring(1); | |
3261 | - } | |
3262 | - var posRe = new RegExp('^'+escape_regex(regEx)+'$'); | |
3263 | - matched_poss = $.grep(frame.positions, | |
3264 | - function(pos){ | |
3265 | - return pos.text_rep.match(posRe); | |
3266 | - }); | |
3267 | - if((matched_poss.length > 0 && conj.startsWith('!')) || | |
3268 | - (matched_poss.length == 0 && !conj.startsWith('!'))) { | |
3269 | - allConjsMatch = false; | |
3270 | - break; | |
3271 | - } | |
3272 | - } | |
3273 | - catch(e) { | |
3274 | - allConjsMatch = false; | |
3275 | - break; | |
3276 | - } | |
3277 | - } | |
3278 | - if(allConjsMatch) { | |
3279 | - return true; | |
3280 | - } | |
3281 | - } | |
3282 | - | |
3283 | - return false; | |
3284 | -} | |
3285 | - | |
3286 | -function has_arguments(frame, arg_term) { | |
3287 | - var alternatives = arg_term.split('|'); | |
3288 | - for(var h=0; h<alternatives.length; h++) { | |
3289 | - var allConjsMatch = true; | |
3290 | - var conjs = alternatives[h].split('&'); | |
3291 | - for(var i=0; i<conjs.length; i++) { | |
3292 | - try { | |
3293 | - var matched_args = []; | |
3294 | - var conj = conjs[i].trim(); | |
3295 | - var regEx = conj; | |
3296 | - if (regEx.substring(0, 1) == '!') { | |
3297 | - regEx = regEx.substring(1); | |
3298 | - } | |
3299 | - var argRe = new RegExp('^'+escape_regex(regEx)+'$'); | |
3300 | - | |
3301 | - for(var j=0; j<frame.positions.length; j++) { | |
3302 | - matched_args = $.grep(frame.positions[j].arguments, function(arg) { | |
3303 | - return arg.text_rep.match(argRe); | |
3304 | - }); | |
3305 | - if(matched_args.length > 0) { | |
3306 | - break; | |
3307 | - } | |
3308 | - } | |
3309 | - if((matched_args.length > 0 && conj.startsWith('!')) || | |
3310 | - (matched_args.length == 0 && !conj.startsWith('!'))) { | |
3311 | - allConjsMatch = false; | |
3312 | - break; | |
3313 | - } | |
3314 | - } | |
3315 | - catch(e) { | |
3316 | - allConjsMatch = false; | |
3317 | - break; | |
3318 | - } | |
3319 | - } | |
3320 | - if(allConjsMatch){ | |
3321 | - return true; | |
3322 | - } | |
3323 | - } | |
3324 | - return false; | |
3325 | -} | |
3326 | - | |
3327 | -function filter_frames(schemas, filter_id) | |
3328 | -{ | |
3329 | - var aspect_val = $('#'+filter_id+' #aspect_filter').val(); | |
3330 | - var reflex_val = $('#'+filter_id+' #reflex_filter').val(); | |
3331 | - var neg_val = $('#'+filter_id+' #neg_filter').val(); | |
3332 | - var pred_val = $('#'+filter_id+' #pred_filter').val(); | |
3333 | - var opinion_val = $('#'+filter_id+' #opinion_filter').val(); | |
3334 | - var position_val = $('#'+filter_id+' #position_filter').val().trim(); | |
3335 | - var argument_val = $('#'+filter_id+' #argument_filter').val().trim(); | |
3336 | - var filtered_frames = new Array(); | |
3337 | - | |
3338 | - if(position_val == '.*') | |
3339 | - position_val = '' | |
3340 | - if(argument_val == '.*') | |
3341 | - argument_val = '' | |
3342 | - | |
3343 | - for(var i=0; i<schemas.length; i++) | |
3344 | - { | |
3345 | - if((schemas[i].characteristics[3] == aspect_val || aspect_val == '*') | |
3346 | - && (schemas[i].characteristics[0] == reflex_val || reflex_val == '*') | |
3347 | - && (schemas[i].characteristics[1] == neg_val || neg_val == '*') | |
3348 | - && (schemas[i].characteristics[2] == pred_val || pred_val == '*') | |
3349 | - && (schemas[i].opinion == opinion_val || opinion_val == '*')) | |
3350 | - { | |
3351 | - frameMatch = false; | |
3352 | - if(position_val) | |
3353 | - frameMatch = has_positions(schemas[i], position_val) | |
3354 | - if(argument_val && (frameMatch || !position_val)) | |
3355 | - { | |
3356 | - | |
3357 | - frameMatch = has_arguments(schemas[i], argument_val) | |
3358 | - } | |
3359 | - if(frameMatch || (!argument_val && !position_val)) | |
3360 | - filtered_frames.push(schemas[i]); | |
3361 | - } | |
3362 | - } | |
3363 | - return filtered_frames; | |
3364 | -} | |
3365 | - | |
3366 | 3011 | function draw_filtered_frames(schemas, parent_id, table_id, filter_id, nkjp_examples, table_class, lemma_entry) |
3367 | 3012 | { |
3368 | 3013 | var parent = document.getElementById(parent_id); |
... | ... |
dictionary/static/js/lemma_grid.js
... | ... | @@ -198,128 +198,6 @@ function createSearchDialog() { |
198 | 198 | width: 'auto' }); |
199 | 199 | } |
200 | 200 | |
201 | -function filter_form_submit() { | |
202 | - this_form = $(this); | |
203 | - form_data = this_form.serializeArray(); | |
204 | - | |
205 | - var owner = ''; | |
206 | - var vocabulary = ''; | |
207 | - var status = ''; | |
208 | - var filter_frames = false; | |
209 | - | |
210 | - form_data = $.map(form_data, function(elem) | |
211 | - { | |
212 | - if (elem.name != 'owner' && elem.name != 'vocabulary' && | |
213 | - elem.name != 'status' && | |
214 | - elem.name != 'reflex' && elem.name != 'negativity' && elem.name != 'aspect' && | |
215 | - elem.name != 'has_argument' && elem.name != 'has_position' && | |
216 | - elem.name != 'approver' && elem.name != 'has_message_from' && | |
217 | - elem.name != 'filter_frames') | |
218 | - return elem; | |
219 | - else { | |
220 | - if (elem.name == 'owner') | |
221 | - owner = elem.value; | |
222 | - else if (elem.name == 'vocabulary') | |
223 | - vocabulary = elem.value; | |
224 | - else if (elem.name == 'status') | |
225 | - status = elem.value; | |
226 | - else if (elem.name == 'has_message_from') | |
227 | - has_message_from = elem.value; | |
228 | - else if (elem.name == 'reflex') | |
229 | - reflex = elem.value; | |
230 | - else if (elem.name == 'negativity') | |
231 | - negativity = elem.value; | |
232 | - else if (elem.name == 'aspect') | |
233 | - aspect = elem.value; | |
234 | - else if (elem.name == 'has_argument') | |
235 | - has_argument = elem.value; | |
236 | - else if (elem.name == 'has_position') | |
237 | - has_position = elem.value; | |
238 | - else if (elem.name == 'approver') | |
239 | - approver = elem.value; | |
240 | - else if (elem.name == 'filter_frames') | |
241 | - filter_frames = elem.value; | |
242 | - } | |
243 | - }); | |
244 | - | |
245 | - form_data.push({name: 'owner', value: owner}); | |
246 | - form_data.push({name: 'vocabulary', value: vocabulary}); | |
247 | - form_data.push({name: 'status', value: status}); | |
248 | - form_data.push({name: 'has_message_from', value: has_message_from}); | |
249 | - form_data.push({name: 'reflex', value: reflex}); | |
250 | - form_data.push({name: 'negativity', value: negativity}); | |
251 | - form_data.push({name: 'aspect', value: aspect}); | |
252 | - form_data.push({name: 'has_argument', value: has_argument}); | |
253 | - form_data.push({name: 'has_position', value: has_position}); | |
254 | - form_data.push({name: 'approver', value: approver}); | |
255 | - form_data.push({name: 'filter_frames', value: filter_frames}); | |
256 | - | |
257 | - act_lemma_id = window.prev_lemma_id; | |
258 | - if(window.activeLemmaPanel != 'preview_lemma') | |
259 | - act_lemma_id = window.lemma_id; | |
260 | - | |
261 | - form_data.push({name: 'lemma_id', value: act_lemma_id}) | |
262 | - | |
263 | - $.ajaxJSON({ | |
264 | - method: 'post', | |
265 | - url: ajax_filter_form_submit, | |
266 | - data: { | |
267 | - form_data: form_data | |
268 | - }, | |
269 | - | |
270 | - callback: function(result) { | |
271 | - $('#search-panel-dialog').dialog('close'); | |
272 | - if(result['filter_frames']) | |
273 | - { | |
274 | - if(window.activeLemmaPanel == 'preview_lemma') | |
275 | - { | |
276 | - window.prev_filter_reflex_val = result['reflex']; | |
277 | - window.prev_filter_neg_val = result['negativity']; | |
278 | - window.prev_filter_pred_val = result['predicativity']; | |
279 | - window.prev_filter_opinion_val = result['opinion']; | |
280 | - window.prev_filter_aspect_val = result['aspect']; | |
281 | - window.prev_filter_position_val = result['position']; | |
282 | - window.prev_filter_argument_val = result['argument']; | |
283 | - $('#prev_frame_filter #reflex_filter').val(result['reflex']); | |
284 | - $('#prev_frame_filter #neg_filter').val(result['negativity']); | |
285 | - $('#prev_frame_filter #pred_filter').val(result['predicativity']); | |
286 | - $('#prev_frame_filter #opinion_filter').val(result['opinion']); | |
287 | - $('#prev_frame_filter #aspect_filter').val(result['aspect']); | |
288 | - $('#prev_frame_filter #argument_filter').val(result['argument']); | |
289 | - $('#prev_frame_filter #position_filter').val(result['position']); | |
290 | - $('#prev_frame_filter #argument_filter').trigger('change'); | |
291 | - } | |
292 | - else | |
293 | - { | |
294 | - window.filter_reflex_val = result['reflex']; | |
295 | - window.filter_neg_val = result['negativity']; | |
296 | - window.filter_pred_val = result['predicativity']; | |
297 | - window.filter_opinion_val = result['opinion']; | |
298 | - window.filter_aspect_val = result['aspect']; | |
299 | - window.filter_position_val = result['position']; | |
300 | - window.filter_argument_val = result['argument']; | |
301 | - $('#frame_filter #reflex_filter').val(result['reflex']); | |
302 | - $('#frame_filter #neg_filter').val(result['negativity']); | |
303 | - $('#frame_filter #pred_filter').val(result['predicativity']); | |
304 | - $('#frame_filter #opinion_filter').val(result['opinion']); | |
305 | - $('#frame_filter #aspect_filter').val(result['aspect']); | |
306 | - $('#frame_filter #argument_filter').val(result['argument']); | |
307 | - $('#frame_filter #position_filter').val(result['position']); | |
308 | - $('#frame_filter #argument_filter').trigger('change'); | |
309 | - } | |
310 | - } | |
311 | - grid.trigger("reloadGrid"); | |
312 | - }, | |
313 | - error_callback: function(xhr, status, error) { | |
314 | - error_alert(status + ': ' + error); | |
315 | - }, | |
316 | - bad_data_callback: function(result) { | |
317 | - return true; | |
318 | - }, | |
319 | - }); | |
320 | - return false; | |
321 | -} | |
322 | - | |
323 | 201 | function sort_form_submit() { |
324 | 202 | this_form = $(this); |
325 | 203 | form_data = this_form.serializeArray(); |
... | ... |
dictionary/static/js/lemmas_filtering.js
0 → 100644
1 | +function filter_form_submit() { | |
2 | + this_form = $(this); | |
3 | + form_data = this_form.serializeArray(); | |
4 | + | |
5 | + var filter_frames = false; | |
6 | + | |
7 | + form_data = $.map(form_data, function(elem) | |
8 | + { | |
9 | + if (elem.name != 'filter_frames') return elem; | |
10 | + else { | |
11 | + if (elem.name == 'filter_frames') filter_frames = elem.value; | |
12 | + } | |
13 | + }); | |
14 | + form_data.push({name: 'filter_frames', value: filter_frames}); | |
15 | + | |
16 | + act_lemma_id = window.prev_lemma_id; | |
17 | + if(window.activeLemmaPanel != 'preview_lemma') | |
18 | + act_lemma_id = window.lemma_id; | |
19 | + | |
20 | + form_data.push({name: 'lemma_id', value: act_lemma_id}) | |
21 | + | |
22 | + $.ajaxJSON({ | |
23 | + method: 'post', | |
24 | + url: ajax_filter_form_submit, | |
25 | + data: { | |
26 | + form_data: form_data | |
27 | + }, | |
28 | + | |
29 | + callback: function(result) { | |
30 | + $('#search-panel-dialog').dialog('close'); | |
31 | + if(result['filter_frames']) | |
32 | + { | |
33 | + if(window.activeLemmaPanel == 'preview_lemma') | |
34 | + { | |
35 | + window.prev_filter_schema_type_val = result['schema_type']; | |
36 | + window.prev_filter_reflex_val = result['reflex']; | |
37 | + window.prev_filter_neg_val = result['negativity']; | |
38 | + window.prev_filter_pred_val = result['predicativity']; | |
39 | + window.prev_filter_opinion_val = result['opinion']; | |
40 | + window.prev_filter_aspect_val = result['aspect']; | |
41 | + window.prev_filter_position_val = result['position']; | |
42 | + window.prev_filter_argument_val = result['argument']; | |
43 | + $('#prev_frame_filter #schema_type_filter').val(result['schema_type']); | |
44 | + $('#prev_frame_filter #reflex_filter').val(result['reflex']); | |
45 | + $('#prev_frame_filter #neg_filter').val(result['negativity']); | |
46 | + $('#prev_frame_filter #pred_filter').val(result['predicativity']); | |
47 | + $('#prev_frame_filter #opinion_filter').val(result['opinion']); | |
48 | + $('#prev_frame_filter #aspect_filter').val(result['aspect']); | |
49 | + $('#prev_frame_filter #argument_filter').val(result['argument']); | |
50 | + $('#prev_frame_filter #position_filter').val(result['position']); | |
51 | + $('#prev_frame_filter #argument_filter').trigger('change'); | |
52 | + } | |
53 | + else | |
54 | + { | |
55 | + window.filter_schema_type_val = result['schema_type']; | |
56 | + window.filter_reflex_val = result['reflex']; | |
57 | + window.filter_neg_val = result['negativity']; | |
58 | + window.filter_pred_val = result['predicativity']; | |
59 | + window.filter_opinion_val = result['opinion']; | |
60 | + window.filter_aspect_val = result['aspect']; | |
61 | + window.filter_position_val = result['position']; | |
62 | + window.filter_argument_val = result['argument']; | |
63 | + $('#frame_filter #schema_type_filter').val(result['schema_type']); | |
64 | + $('#frame_filter #reflex_filter').val(result['reflex']); | |
65 | + $('#frame_filter #neg_filter').val(result['negativity']); | |
66 | + $('#frame_filter #pred_filter').val(result['predicativity']); | |
67 | + $('#frame_filter #opinion_filter').val(result['opinion']); | |
68 | + $('#frame_filter #aspect_filter').val(result['aspect']); | |
69 | + $('#frame_filter #argument_filter').val(result['argument']); | |
70 | + $('#frame_filter #position_filter').val(result['position']); | |
71 | + $('#frame_filter #argument_filter').trigger('change'); | |
72 | + } | |
73 | + } | |
74 | + grid.trigger("reloadGrid"); | |
75 | + }, | |
76 | + error_callback: function(xhr, status, error) { | |
77 | + error_alert(status + ': ' + error); | |
78 | + }, | |
79 | + bad_data_callback: function(result) { | |
80 | + return true; | |
81 | + }, | |
82 | + }); | |
83 | + return false; | |
84 | +} | |
... | ... |
dictionary/static/js/schemata_filtering.js
0 → 100644
1 | +var schema_type_vals = []; | |
2 | +var aspect_vals = []; | |
3 | +var reflex_vals = []; | |
4 | +var neg_vals = []; | |
5 | +var pred_vals = []; | |
6 | +var opinion_vals = []; | |
7 | +var filter_schema_type_val = '*'; | |
8 | +var filter_aspect_val = '*'; | |
9 | +var filter_reflex_val = '*'; | |
10 | +var filter_neg_val = '*'; | |
11 | +var filter_pred_val = '*'; | |
12 | +var filter_opinion_val = '*'; | |
13 | +var filter_position_val = '.*'; | |
14 | +var filter_argument_val = '.*'; | |
15 | +var prev_filter_schema_type_val = '*'; | |
16 | +var prev_filter_aspect_val = '*'; | |
17 | +var prev_filter_reflex_val = '*'; | |
18 | +var prev_filter_neg_val = '*'; | |
19 | +var prev_filter_pred_val = '*'; | |
20 | +var prev_filter_opinion_val = '*'; | |
21 | +var prev_filter_position_val = '.*'; | |
22 | +var prev_filter_argument_val = '.*'; | |
23 | + | |
24 | +function cancel_schemata_filtering() { | |
25 | + window.filter_position_val = '.*'; | |
26 | + window.filter_argument_val = '.*'; | |
27 | + window.filter_schema_type_val = '*'; | |
28 | + window.filter_aspect_val = '*'; | |
29 | + window.filter_reflex_val = '*'; | |
30 | + window.filter_neg_val = '*'; | |
31 | + window.filter_pred_val = '*'; | |
32 | + window.filter_opinion_val = '*'; | |
33 | + $('#frame_filter #argument_filter').val(window.filter_argument_val); | |
34 | + $('#frame_filter #position_filter').val(window.filter_position_val); | |
35 | + $('#frame_filter #schema_type_filter').val(window.filter_schema_type_val); | |
36 | + $('#frame_filter #aspect_filter').val(window.filter_aspect_val); | |
37 | + $('#frame_filter #reflex_filter').val(window.filter_reflex_val); | |
38 | + $('#frame_filter #neg_filter').val(window.filter_neg_val); | |
39 | + $('#frame_filter #pred_filter').val(window.filter_pred_val); | |
40 | + $('#frame_filter #opinion_filter').val(window.filter_opinion_val); | |
41 | + $('#frame_filter #argument_filter').trigger('change'); | |
42 | +} | |
43 | + | |
44 | +function cancel_prev_schemata_filtering() { | |
45 | + window.prev_filter_position_val = '.*'; | |
46 | + window.prev_filter_argument_val = '.*'; | |
47 | + window.prev_filter_schema_type_val = '*'; | |
48 | + window.prev_filter_aspect_val = '*'; | |
49 | + window.prev_filter_reflex_val = '*'; | |
50 | + window.prev_filter_neg_val = '*'; | |
51 | + window.prev_filter_pred_val = '*'; | |
52 | + window.prev_filter_opinion_val = '*'; | |
53 | + $('#prev_frame_filter #argument_filter').val(window.prev_filter_argument_val); | |
54 | + $('#prev_frame_filter #position_filter').val(window.prev_filter_position_val); | |
55 | + $('#prev_frame_filter #schema_type_filter').val(window.prev_filter_schema_type_val); | |
56 | + $('#prev_frame_filter #aspect_filter').val(window.prev_filter_aspect_val); | |
57 | + $('#prev_frame_filter #reflex_filter').val(window.prev_filter_reflex_val); | |
58 | + $('#prev_frame_filter #neg_filter').val(window.prev_filter_neg_val); | |
59 | + $('#prev_frame_filter #pred_filter').val(window.prev_filter_pred_val); | |
60 | + $('#prev_frame_filter #opinion_filter').val(window.prev_filter_opinion_val); | |
61 | + $('#prev_frame_filter #argument_filter').trigger('change'); | |
62 | +} | |
63 | + | |
64 | +function initiateFrameFilters() { | |
65 | + $.ajaxJSON({ | |
66 | + method: 'get', | |
67 | + url: ajax_get_frame_filter_options, | |
68 | + data: { | |
69 | + //message_id: message_id, | |
70 | + }, | |
71 | + callback: function(result) { | |
72 | + window.schema_type_vals = result['schema_type_options']; | |
73 | + window.aspect_vals = result['aspect_options']; | |
74 | + window.reflex_vals = result['reflex_options']; | |
75 | + window.neg_vals = result['neg_options']; | |
76 | + window.pred_vals = result['pred_options']; | |
77 | + window.opinion_vals = result['opinion_options']; | |
78 | + }, | |
79 | + | |
80 | + error_callback: function(xhr, status, error) { | |
81 | + error_alert(status + ': ' + error); | |
82 | + }, | |
83 | + }); | |
84 | +} | |
85 | + | |
86 | +function filter_update(id) { | |
87 | + if(id == 'frame_filter') | |
88 | + { | |
89 | + window.filter_schema_type_val = $('#frame_filter #schema_type_filter').val(); | |
90 | + window.filter_aspect_val = $('#frame_filter #aspect_filter').val(); | |
91 | + window.filter_reflex_val = $('#frame_filter #reflex_filter').val(); | |
92 | + window.filter_neg_val = $('#frame_filter #neg_filter').val(); | |
93 | + window.filter_pred_val = $('#frame_filter #pred_filter').val(); | |
94 | + window.filter_opinion_val = $('#frame_filter #opinion_filter').val(); | |
95 | + window.filter_position_val = $('#frame_filter #position_filter').val(); | |
96 | + window.filter_argument_val = $('#frame_filter #argument_filter').val(); | |
97 | + } | |
98 | + else if(id == 'prev_frame_filter') | |
99 | + { | |
100 | + window.prev_filter_schema_type_val = $('#prev_frame_filter #schema_type_filter').val(); | |
101 | + window.prev_filter_aspect_val = $('#prev_frame_filter #aspect_filter').val(); | |
102 | + window.prev_filter_reflex_val = $('#prev_frame_filter #reflex_filter').val(); | |
103 | + window.prev_filter_neg_val = $('#prev_frame_filter #neg_filter').val(); | |
104 | + window.prev_filter_pred_val = $('#prev_frame_filter #pred_filter').val(); | |
105 | + window.prev_filter_opinion_val = $('#prev_frame_filter #opinion_filter').val(); | |
106 | + window.prev_filter_position_val = $('#prev_frame_filter #position_filter').val(); | |
107 | + window.prev_filter_argument_val = $('#prev_frame_filter #argument_filter').val(); | |
108 | + } | |
109 | +} | |
110 | + | |
111 | +function draw_frames_filter(id) { | |
112 | + var frame_filter = document.getElementById(id); | |
113 | + | |
114 | + p = document.createElement('p'); | |
115 | + text = document.createTextNode("Typ schematu: "); | |
116 | + p.appendChild(text); | |
117 | + var select = document.createElement('select'); | |
118 | + select.setAttribute('id', 'schema_type_filter'); | |
119 | + select.setAttribute('name', 'schema_type'); | |
120 | + p.appendChild(select); | |
121 | + for(var i=0; i<schema_type_vals.length; i++) | |
122 | + { | |
123 | + var option = document.createElement('option'); | |
124 | + option.setAttribute('value', schema_type_vals[i].value); | |
125 | + option.appendChild(document.createTextNode(schema_type_vals[i].name)); | |
126 | + select.appendChild(option); | |
127 | + } | |
128 | + frame_filter.appendChild(p); | |
129 | + | |
130 | + p = document.createElement('p'); | |
131 | + text = document.createTextNode("Aspekt: "); | |
132 | + p.appendChild(text); | |
133 | + var select = document.createElement('select'); | |
134 | + select.setAttribute('id', 'aspect_filter'); | |
135 | + select.setAttribute('name', 'ASPEKT'); | |
136 | + p.appendChild(select); | |
137 | + for(var i=0; i<aspect_vals.length; i++) | |
138 | + { | |
139 | + var option = document.createElement('option'); | |
140 | + option.setAttribute('value', aspect_vals[i].value); | |
141 | + option.appendChild(document.createTextNode(aspect_vals[i].name)); | |
142 | + select.appendChild(option); | |
143 | + } | |
144 | + frame_filter.appendChild(p); | |
145 | + | |
146 | + p = document.createElement('p'); | |
147 | + text = document.createTextNode("Zwrotność: "); | |
148 | + p.appendChild(text); | |
149 | + select = document.createElement('select'); | |
150 | + select.setAttribute('id', 'reflex_filter'); | |
151 | + select.setAttribute('name', 'ZWROTNOSC'); | |
152 | + p.appendChild(select); | |
153 | + for(var i=0; i<reflex_vals.length; i++) | |
154 | + { | |
155 | + var option = document.createElement('option'); | |
156 | + option.setAttribute('value', reflex_vals[i].value); | |
157 | + option.appendChild(document.createTextNode(reflex_vals[i].name)); | |
158 | + select.appendChild(option); | |
159 | + } | |
160 | + frame_filter.appendChild(p); | |
161 | + | |
162 | + p = document.createElement('p'); | |
163 | + text = document.createTextNode("Negatywność: "); | |
164 | + p.appendChild(text); | |
165 | + select = document.createElement('select'); | |
166 | + select.setAttribute('id', 'neg_filter'); | |
167 | + select.setAttribute('name', 'NEGATYWNOŚĆ'); | |
168 | + p.appendChild(select); | |
169 | + for(var i=0; i<neg_vals.length; i++) | |
170 | + { | |
171 | + var option = document.createElement('option'); | |
172 | + option.setAttribute('value', neg_vals[i].value); | |
173 | + option.appendChild(document.createTextNode(neg_vals[i].name)); | |
174 | + select.appendChild(option); | |
175 | + } | |
176 | + frame_filter.appendChild(p); | |
177 | + | |
178 | + p = document.createElement('p'); | |
179 | + text = document.createTextNode("Predykatywność: "); | |
180 | + p.appendChild(text); | |
181 | + select = document.createElement('select'); | |
182 | + select.setAttribute('id', 'pred_filter'); | |
183 | + select.setAttribute('name', 'PREDYKATYWNOŚĆ'); | |
184 | + p.appendChild(select); | |
185 | + for(var i=0; i<pred_vals.length; i++) | |
186 | + { | |
187 | + var option = document.createElement('option'); | |
188 | + option.setAttribute('value', pred_vals[i].value); | |
189 | + option.appendChild(document.createTextNode(pred_vals[i].name)); | |
190 | + select.appendChild(option); | |
191 | + } | |
192 | + frame_filter.appendChild(p); | |
193 | + | |
194 | + p = document.createElement('p'); | |
195 | + text = document.createTextNode("Opinia: "); | |
196 | + p.appendChild(text); | |
197 | + select = document.createElement('select'); | |
198 | + select.setAttribute('id', 'opinion_filter'); | |
199 | + select.setAttribute('name', 'OPINIA'); | |
200 | + p.appendChild(select); | |
201 | + for(var i=0; i<opinion_vals.length; i++) | |
202 | + { | |
203 | + var option = document.createElement('option'); | |
204 | + option.setAttribute('value', opinion_vals[i].value); | |
205 | + option.appendChild(document.createTextNode(opinion_vals[i].name)); | |
206 | + select.appendChild(option); | |
207 | + } | |
208 | + frame_filter.appendChild(p); | |
209 | + | |
210 | + p = document.createElement('p'); | |
211 | + text = document.createTextNode("Typ frazy: "); | |
212 | + p.appendChild(text); | |
213 | + select = document.createElement('input'); | |
214 | + select.setAttribute('id', 'argument_filter'); | |
215 | + select.setAttribute('name', 'ARGUMENT'); | |
216 | + p.appendChild(select); | |
217 | + frame_filter.appendChild(p); | |
218 | + | |
219 | + p = document.createElement('p'); | |
220 | + text = document.createTextNode("Pozycja: "); | |
221 | + p.appendChild(text); | |
222 | + select = document.createElement('input'); | |
223 | + select.setAttribute('id', 'position_filter'); | |
224 | + select.setAttribute('name', 'POZYCJA'); | |
225 | + p.appendChild(select); | |
226 | + frame_filter.appendChild(p); | |
227 | + | |
228 | + if(id == 'frame_filter') | |
229 | + { | |
230 | + $('#frame_filter #schema_type_filter').val(window.filter_schema_type_val); | |
231 | + $('#frame_filter #aspect_filter').val(window.filter_aspect_val); | |
232 | + $('#frame_filter #reflex_filter').val(window.filter_reflex_val); | |
233 | + $('#frame_filter #neg_filter').val(window.filter_neg_val); | |
234 | + $('#frame_filter #pred_filter').val(window.filter_pred_val); | |
235 | + $('#frame_filter #opinion_filter').val(window.filter_opinion_val); | |
236 | + $('#frame_filter #position_filter').val(window.filter_position_val); | |
237 | + $('#frame_filter #argument_filter').val(window.filter_argument_val); | |
238 | + } | |
239 | + else if(id == 'prev_frame_filter') | |
240 | + { | |
241 | + $('#prev_frame_filter #schema_type_filter').val(window.prev_filter_schema_type_val); | |
242 | + $('#prev_frame_filter #aspect_filter').val(window.prev_filter_aspect_val); | |
243 | + $('#prev_frame_filter #reflex_filter').val(window.prev_filter_reflex_val); | |
244 | + $('#prev_frame_filter #neg_filter').val(window.prev_filter_neg_val); | |
245 | + $('#prev_frame_filter #pred_filter').val(window.prev_filter_pred_val); | |
246 | + $('#prev_frame_filter #opinion_filter').val(window.prev_filter_opinion_val); | |
247 | + $('#prev_frame_filter #position_filter').val(window.prev_filter_position_val); | |
248 | + $('#prev_frame_filter #argument_filter').val(window.prev_filter_argument_val); | |
249 | + } | |
250 | + | |
251 | + //attach autocomplete | |
252 | + $('#' + id + ' #argument_filter').autocomplete({ | |
253 | + // triggers when selection performed | |
254 | + select: function(event, ui){ | |
255 | + filter_update(id); | |
256 | + }, | |
257 | + //define callback to format results | |
258 | + source: function(req, add){ | |
259 | + //pass request to server | |
260 | + $.getJSON(ajax_argument_lookup, req, function(data) { | |
261 | + //create array for response objects | |
262 | + var suggestions = []; | |
263 | + $.each(data['result'], function(i, val){ | |
264 | + suggestions.push(val[0]); | |
265 | + }); | |
266 | + //pass array to callback | |
267 | + add(suggestions); | |
268 | + }); | |
269 | + }, | |
270 | + }); | |
271 | + $('#' + id + ' #position_filter').autocomplete({ | |
272 | + // triggers when selection performed | |
273 | + select: function(event, ui){ | |
274 | + filter_update(id); | |
275 | + }, | |
276 | + //define callback to format results | |
277 | + source: function(req, add){ | |
278 | + //pass request to server | |
279 | + $.getJSON(ajax_position_lookup, req, function(data) { | |
280 | + //create array for response objects | |
281 | + var suggestions = []; | |
282 | + $.each(data['result'], function(i, val){ | |
283 | + suggestions.push(val[0]); | |
284 | + }); | |
285 | + //pass array to callback | |
286 | + add(suggestions); | |
287 | + }); | |
288 | + }, | |
289 | + }); | |
290 | +} | |
291 | + | |
292 | +function filter_frames(schemas, filter_id) { | |
293 | + var schema_type_val = $('#'+filter_id+' #schema_type_filter').val(); | |
294 | + var aspect_val = $('#'+filter_id+' #aspect_filter').val(); | |
295 | + var reflex_val = $('#'+filter_id+' #reflex_filter').val(); | |
296 | + var neg_val = $('#'+filter_id+' #neg_filter').val(); | |
297 | + var pred_val = $('#'+filter_id+' #pred_filter').val(); | |
298 | + var opinion_val = $('#'+filter_id+' #opinion_filter').val(); | |
299 | + var position_val = $('#'+filter_id+' #position_filter').val().trim(); | |
300 | + var argument_val = $('#'+filter_id+' #argument_filter').val().trim(); | |
301 | + var filtered_frames = new Array(); | |
302 | + | |
303 | + if(position_val == '.*') | |
304 | + position_val = '' | |
305 | + if(argument_val == '.*') | |
306 | + argument_val = '' | |
307 | + | |
308 | + for(var i=0; i<schemas.length; i++) | |
309 | + { | |
310 | + if((schemas[i].characteristics[3] == aspect_val || aspect_val == '*') | |
311 | + && (schemas[i].characteristics[0] == reflex_val || reflex_val == '*') | |
312 | + && (schemas[i].characteristics[1] == neg_val || neg_val == '*') | |
313 | + && (schemas[i].characteristics[2] == pred_val || pred_val == '*') | |
314 | + && (schemas[i].opinion == opinion_val || opinion_val == '*') | |
315 | + && schema_type_valid(schemas[i], schema_type_val)) | |
316 | + { | |
317 | + frameMatch = false; | |
318 | + if(position_val) | |
319 | + frameMatch = has_positions(schemas[i], position_val) | |
320 | + if(argument_val && (frameMatch || !position_val)) | |
321 | + { | |
322 | + | |
323 | + frameMatch = has_arguments(schemas[i], argument_val) | |
324 | + } | |
325 | + if(frameMatch || (!argument_val && !position_val)) | |
326 | + filtered_frames.push(schemas[i]); | |
327 | + } | |
328 | + } | |
329 | + return filtered_frames; | |
330 | +} | |
331 | + | |
332 | +function has_positions(frame, pos_term) { | |
333 | + var alternatives = pos_term.split('|'); | |
334 | + for(var h=0; h<alternatives.length; h++) { | |
335 | + var allConjsMatch = true; | |
336 | + var conjs = alternatives[h].split('&'); | |
337 | + | |
338 | + for(var i=0; i<conjs.length; i++) { | |
339 | + try { | |
340 | + var matched_poss = []; | |
341 | + var conj = conjs[i].trim(); | |
342 | + var regEx = conj; | |
343 | + if (regEx.substring(0, 1) == '!') { | |
344 | + regEx = regEx.substring(1); | |
345 | + } | |
346 | + var posRe = new RegExp('^'+escape_regex(regEx)+'$'); | |
347 | + matched_poss = $.grep(frame.positions, | |
348 | + function(pos){ | |
349 | + return pos.text_rep.match(posRe); | |
350 | + }); | |
351 | + if((matched_poss.length > 0 && conj.startsWith('!')) || | |
352 | + (matched_poss.length == 0 && !conj.startsWith('!'))) { | |
353 | + allConjsMatch = false; | |
354 | + break; | |
355 | + } | |
356 | + } | |
357 | + catch(e) { | |
358 | + allConjsMatch = false; | |
359 | + break; | |
360 | + } | |
361 | + } | |
362 | + if(allConjsMatch) { | |
363 | + return true; | |
364 | + } | |
365 | + } | |
366 | + | |
367 | + return false; | |
368 | +} | |
369 | + | |
370 | +function has_arguments(frame, arg_term) { | |
371 | + var alternatives = arg_term.split('|'); | |
372 | + for(var h=0; h<alternatives.length; h++) { | |
373 | + var allConjsMatch = true; | |
374 | + var conjs = alternatives[h].split('&'); | |
375 | + for(var i=0; i<conjs.length; i++) { | |
376 | + try { | |
377 | + var matched_args = []; | |
378 | + var conj = conjs[i].trim(); | |
379 | + var regEx = conj; | |
380 | + if (regEx.substring(0, 1) == '!') { | |
381 | + regEx = regEx.substring(1); | |
382 | + } | |
383 | + var argRe = new RegExp('^'+escape_regex(regEx)+'$'); | |
384 | + | |
385 | + for(var j=0; j<frame.positions.length; j++) { | |
386 | + matched_args = $.grep(frame.positions[j].arguments, function(arg) { | |
387 | + return arg.text_rep.match(argRe); | |
388 | + }); | |
389 | + if(matched_args.length > 0) { | |
390 | + break; | |
391 | + } | |
392 | + } | |
393 | + if((matched_args.length > 0 && conj.startsWith('!')) || | |
394 | + (matched_args.length == 0 && !conj.startsWith('!'))) { | |
395 | + allConjsMatch = false; | |
396 | + break; | |
397 | + } | |
398 | + } | |
399 | + catch(e) { | |
400 | + allConjsMatch = false; | |
401 | + break; | |
402 | + } | |
403 | + } | |
404 | + if(allConjsMatch){ | |
405 | + return true; | |
406 | + } | |
407 | + } | |
408 | + return false; | |
409 | +} | |
410 | + | |
411 | +function schema_type_valid(schema, filter_option) { | |
412 | + if(filter_option == '*') return true; | |
413 | + else if(filter_option == 'normal' && !schema.is_phraseologic) return true; | |
414 | + else if(filter_option == 'phraseologic' && schema.is_phraseologic) return true; | |
415 | + else return false; | |
416 | +} | |
... | ... |
dictionary/templates/filter_form.html
... | ... | @@ -36,13 +36,156 @@ $(function(){ |
36 | 36 | }, |
37 | 37 | }); |
38 | 38 | |
39 | + $('#filter-form-tabs').tabs(); | |
39 | 40 | |
40 | 41 | }); |
41 | 42 | |
42 | 43 | </script> |
43 | 44 | |
44 | 45 | <form class="filter-form" method="post"> {% csrf_token %} |
45 | - {{ form.as_p }} | |
46 | +<div id="filter-form-tabs"> | |
47 | + <ul> | |
48 | + <li><a href="#lemma-filters">Hasło</a></li> | |
49 | + <li><a href="#schema-filters">Schematy</a></li> | |
50 | + </ul> | |
51 | + <div id="lemma-filters"> | |
52 | + {% if not form.lemma.is_hidden %} | |
53 | + <p class="fieldWrapper"> | |
54 | + {{ form.lemma.errors }} | |
55 | + {{ form.lemma.label_tag }}: {{ form.lemma }} | |
56 | + </p> | |
57 | + {% endif %} | |
58 | + {% if not form.pos.is_hidden %} | |
59 | + <p class="fieldWrapper"> | |
60 | + {{ form.pos.errors }} | |
61 | + {{ form.pos.label_tag }}: {{ form.pos }} | |
62 | + </p> | |
63 | + {% endif %} | |
64 | + {% if not form.contains_phraseology.is_hidden %} | |
65 | + <p class="fieldWrapper"> | |
66 | + {{ form.contains_phraseology.errors }} | |
67 | + {{ form.contains_phraseology.label_tag }}: {{ form.contains_phraseology }} | |
68 | + </p> | |
69 | + {% endif %} | |
70 | + {% if not form.owner.is_hidden or not form.phraseologist.is_hidden or not form.semanticist.is_hidden %} | |
71 | + <hr> | |
72 | + {% endif %} | |
73 | + {% if not form.owner.is_hidden %} | |
74 | + <p class="fieldWrapper"> | |
75 | + {{ form.owner.errors }} | |
76 | + {{ form.owner.label_tag }}: {{ form.owner }} | |
77 | + </p> | |
78 | + {% endif %} | |
79 | + {% if not form.phraseologist.is_hidden %} | |
80 | + <p class="fieldWrapper"> | |
81 | + {{ form.phraseologist.errors }} | |
82 | + {{ form.phraseologist.label_tag }}: {{ form.phraseologist }} | |
83 | + </p> | |
84 | + {% endif %} | |
85 | + {% if not form.semanticist.is_hidden %} | |
86 | + <p class="fieldWrapper"> | |
87 | + {{ form.semanticist.errors }} | |
88 | + {{ form.semanticist.label_tag }}: {{ form.semanticist }} | |
89 | + </p> | |
90 | + {% endif %} | |
91 | + {% if not form.vocabulary.is_hidden or not form.status.is_hidden or not form.has_message_from.is_hidden %} | |
92 | + <hr> | |
93 | + {% endif %} | |
94 | + {% if not form.vocabulary.is_hidden %} | |
95 | + <p class="fieldWrapper"> | |
96 | + {{ form.vocabulary.errors }} | |
97 | + {{ form.vocabulary.label_tag }}: {{ form.vocabulary }} | |
98 | + </p> | |
99 | + {% endif %} | |
100 | + {% if not form.status.is_hidden %} | |
101 | + <p class="fieldWrapper"> | |
102 | + {{ form.status.errors }} | |
103 | + {{ form.status.label_tag }}: {{ form.status }} | |
104 | + </p> | |
105 | + {% endif %} | |
106 | + {% if not form.has_message_from.is_hidden %} | |
107 | + <p class="fieldWrapper"> | |
108 | + {{ form.has_message_from.errors }} | |
109 | + {{ form.has_message_from.label_tag }}: {{ form.has_message_from }} | |
110 | + </p> | |
111 | + {% endif %} | |
112 | + {% if not form.example_source.is_hidden or not form.approver.is_hidden %} | |
113 | + <hr> | |
114 | + {% endif %} | |
115 | + {% if not form.example_source.is_hidden %} | |
116 | + <p class="fieldWrapper"> | |
117 | + {{ form.example_source.errors }} | |
118 | + {{ form.example_source.label_tag }}: {{ form.example_source }} | |
119 | + </p> | |
120 | + {% endif %} | |
121 | + {% if not form.approver.is_hidden %} | |
122 | + <p class="fieldWrapper"> | |
123 | + {{ form.approver.errors }} | |
124 | + {{ form.approver.label_tag }}: {{ form.approver }} | |
125 | + </p> | |
126 | + {% endif %} | |
127 | + </div> | |
128 | + <div id="schema-filters"> | |
129 | + {% if not form.frame_opinion.is_hidden %} | |
130 | + <p class="fieldWrapper"> | |
131 | + {{ form.frame_opinion.errors }} | |
132 | + {{ form.frame_opinion.label_tag }}: {{ form.frame_opinion }} | |
133 | + </p> | |
134 | + {% endif %} | |
135 | + {% if not form.schema_type.is_hidden %} | |
136 | + <p class="fieldWrapper"> | |
137 | + {{ form.schema_type.errors }} | |
138 | + {{ form.schema_type.label_tag }}: {{ form.schema_type }} | |
139 | + </p> | |
140 | + {% endif %} | |
141 | + {% if not form.reflex.is_hidden %} | |
142 | + <p class="fieldWrapper"> | |
143 | + {{ form.reflex.errors }} | |
144 | + {{ form.reflex.label_tag }}: {{ form.reflex }} | |
145 | + </p> | |
146 | + {% endif %} | |
147 | + {% if not form.negativity.is_hidden %} | |
148 | + <p class="fieldWrapper"> | |
149 | + {{ form.negativity.errors }} | |
150 | + {{ form.negativity.label_tag }}: {{ form.negativity }} | |
151 | + </p> | |
152 | + {% endif %} | |
153 | + {% if not form.predicativity.is_hidden %} | |
154 | + <p class="fieldWrapper"> | |
155 | + {{ form.predicativity.errors }} | |
156 | + {{ form.predicativity.label_tag }}: {{ form.predicativity }} | |
157 | + </p> | |
158 | + {% endif %} | |
159 | + {% if not form.aspect.is_hidden %} | |
160 | + <p class="fieldWrapper"> | |
161 | + {{ form.aspect.errors }} | |
162 | + {{ form.aspect.label_tag }}: {{ form.aspect }} | |
163 | + </p> | |
164 | + {% endif %} | |
165 | + {% if not form.has_argument.is_hidden %} | |
166 | + <p class="fieldWrapper"> | |
167 | + {{ form.has_argument.errors }} | |
168 | + {{ form.has_argument.label_tag }}: {{ form.has_argument }} | |
169 | + </p> | |
170 | + {% endif %} | |
171 | + {% if not form.has_position.is_hidden %} | |
172 | + <p class="fieldWrapper"> | |
173 | + {{ form.has_position.errors }} | |
174 | + {{ form.has_position.label_tag }}: {{ form.has_position }} | |
175 | + </p> | |
176 | + {% endif %} | |
177 | + {% if not form.filter_frames.is_hidden %} | |
178 | + <p class="fieldWrapper"> | |
179 | + {{ form.filter_frames.errors }} | |
180 | + {{ form.filter_frames.label_tag }}: {{ form.filter_frames }} | |
181 | + </p> | |
182 | + {% endif %} | |
183 | + </div> | |
184 | + </div> | |
185 | + {% for hidden in form.hidden_fields %} | |
186 | + {{ hidden }} | |
187 | + {% endfor %} | |
188 | + {{ form.non_field_errors }} | |
46 | 189 | <p class="lexeme-save"> |
47 | 190 | <button type="submit" id="filter-form-submit"> |
48 | 191 | Filtruj |
... | ... | @@ -54,4 +197,5 @@ $(function(){ |
54 | 197 | Anuluj |
55 | 198 | </button> |
56 | 199 | </p> |
200 | + | |
57 | 201 | </form> |
... | ... |
dictionary/templates/lemma_preview.html
... | ... | @@ -122,7 +122,8 @@ function unselectPrevTd(id) |
122 | 122 | } |
123 | 123 | |
124 | 124 | function draw_filtered_prev_frames() |
125 | - { | |
125 | + { | |
126 | + window.prev_filter_schema_type_val = $('#prev_frame_filter #schema_type_filter').val(); | |
126 | 127 | window.prev_filter_aspect_val = $('#prev_frame_filter #aspect_filter').val(); |
127 | 128 | window.prev_filter_reflex_val = $('#prev_frame_filter #reflex_filter').val(); |
128 | 129 | window.prev_filter_neg_val = $('#prev_frame_filter #neg_filter').val(); |
... | ... | @@ -229,6 +230,7 @@ $(document).ready(function() { |
229 | 230 | $('#prev_filter_frames_options').click(function(){ |
230 | 231 | $('#prev_filter_frames_options #options').slideToggle('fast'); |
231 | 232 | }); |
233 | + $('#prev_frame_filter #schema_type_filter').change(draw_filtered_prev_frames); | |
232 | 234 | $('#prev_frame_filter #aspect_filter').change(draw_filtered_prev_frames); |
233 | 235 | $('#prev_frame_filter #reflex_filter').change(draw_filtered_prev_frames); |
234 | 236 | $('#prev_frame_filter #neg_filter').change(draw_filtered_prev_frames); |
... | ... | @@ -239,22 +241,6 @@ $(document).ready(function() { |
239 | 241 | $('#prev_filter_frames_options #options').click(function(event) { |
240 | 242 | event.stopPropagation(); |
241 | 243 | }); |
242 | - $('#cancel_prev_frame_filter').click(function(event) { | |
243 | - window.prev_filter_position_val = '.*'; | |
244 | - window.prev_filter_argument_val = '.*'; | |
245 | - window.prev_filter_aspect_val = '*'; | |
246 | - window.prev_filter_reflex_val = '*'; | |
247 | - window.prev_filter_neg_val = '*'; | |
248 | - window.prev_filter_pred_val = '*'; | |
249 | - window.prev_filter_opinion_val = '*'; | |
250 | - $('#prev_frame_filter #argument_filter').val(window.prev_filter_argument_val); | |
251 | - $('#prev_frame_filter #position_filter').val(window.prev_filter_position_val); | |
252 | - $('#prev_frame_filter #aspect_filter').val(window.prev_filter_aspect_val); | |
253 | - $('#prev_frame_filter #reflex_filter').val(window.prev_filter_reflex_val); | |
254 | - $('#prev_frame_filter #neg_filter').val(window.prev_filter_neg_val); | |
255 | - $('#prev_frame_filter #pred_filter').val(window.prev_filter_pred_val); | |
256 | - $('#prev_frame_filter #opinion_filter').val(window.prev_filter_opinion_val); | |
257 | - $('#prev_frame_filter #argument_filter').trigger('change'); | |
258 | - }); | |
244 | + $('#cancel_prev_frame_filter').click(cancel_prev_schemata_filtering); | |
259 | 245 | }); |
260 | 246 | </script> |
... | ... |
dictionary/templates/lemma_view.html
... | ... | @@ -20,6 +20,8 @@ |
20 | 20 | <script type="text/javascript" src="{{ STATIC_URL }}js/lemma_grid.js"></script> |
21 | 21 | <script type="text/javascript" src="{{ STATIC_URL }}js/semantics_coupling.js"></script> |
22 | 22 | <script type="text/javascript" src="{{ STATIC_URL }}js/lemma-view.js"></script> |
23 | + <script type="text/javascript" src="{{ STATIC_URL }}js/lemmas_filtering.js"></script> | |
24 | + <script type="text/javascript" src="{{ STATIC_URL }}js/schemata_filtering.js"></script> | |
23 | 25 | |
24 | 26 | {% endblock %} |
25 | 27 | |
... | ... |
dictionary/templates/new_frames.html
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | |
12 | 12 | function draw_filtered_new_frames() |
13 | 13 | { |
14 | + window.filter_schema_type_val = $('#frame_filter #schema_type_filter').val(); | |
14 | 15 | window.filter_aspect_val = $('#frame_filter #aspect_filter').val(); |
15 | 16 | window.filter_reflex_val = $('#frame_filter #reflex_filter').val(); |
16 | 17 | window.filter_neg_val = $('#frame_filter #neg_filter').val(); |
... | ... | @@ -255,6 +256,7 @@ $(document).ready(function() { |
255 | 256 | $('#filter_frames_options').click(function(){ |
256 | 257 | $('#filter_frames_options #options').slideToggle('fast'); |
257 | 258 | }); |
259 | + $('#frame_filter #schema_type_filter').change(draw_filtered_new_frames); | |
258 | 260 | $('#frame_filter #aspect_filter').change(draw_filtered_new_frames); |
259 | 261 | $('#frame_filter #reflex_filter').change(draw_filtered_new_frames); |
260 | 262 | $('#frame_filter #neg_filter').change(draw_filtered_new_frames); |
... | ... | @@ -265,23 +267,7 @@ $(document).ready(function() { |
265 | 267 | $('#filter_frames_options #options').click(function(event) { |
266 | 268 | event.stopPropagation(); |
267 | 269 | }); |
268 | - $('#cancel_frame_filter').click(function(event) { | |
269 | - window.filter_position_val = '.*'; | |
270 | - window.filter_argument_val = '.*'; | |
271 | - window.filter_aspect_val = '*'; | |
272 | - window.filter_reflex_val = '*'; | |
273 | - window.filter_neg_val = '*'; | |
274 | - window.filter_pred_val = '*'; | |
275 | - window.filter_opinion_val = '*'; | |
276 | - $('#frame_filter #argument_filter').val(window.filter_argument_val); | |
277 | - $('#frame_filter #position_filter').val(window.filter_position_val); | |
278 | - $('#frame_filter #aspect_filter').val(window.filter_aspect_val); | |
279 | - $('#frame_filter #reflex_filter').val(window.filter_reflex_val); | |
280 | - $('#frame_filter #neg_filter').val(window.filter_neg_val); | |
281 | - $('#frame_filter #pred_filter').val(window.filter_pred_val); | |
282 | - $('#frame_filter #opinion_filter').val(window.filter_opinion_val); | |
283 | - $('#frame_filter #argument_filter').trigger('change'); | |
284 | - }); | |
270 | + $('#cancel_frame_filter').click(cancel_schemata_filtering); | |
285 | 271 | |
286 | 272 | {% if can_modify %} |
287 | 273 | {% if perms.dictionary.add_syntactic_frames or perms.dictionary.add_phraseologic_frames %} |
... | ... |
dictionary/views.py
... | ... | @@ -32,7 +32,8 @@ from django.http import HttpResponse |
32 | 32 | import settings |
33 | 33 | from accounts.models import UserSettings |
34 | 34 | from common.decorators import render |
35 | -from dictionary.ajax_jqgrid import default_sort_rules, default_filter_rules | |
35 | +from dictionary.ajax_jqgrid import default_sort_rules | |
36 | +from dictionary.filtering import all_filter_rules_loaded, default_filter_rules | |
36 | 37 | from dictionary.forms import UserCreateForm, GetVocabularyForm, ArgStatsForm |
37 | 38 | from dictionary.models import PositionCategory, NKJP_Opinion, NKJP_Source, \ |
38 | 39 | Vocabulary, Message, RealizationType |
... | ... | @@ -86,10 +87,12 @@ def lemma_view(request): |
86 | 87 | if not 'status' in request.session['sort_rules_lemma_preview']: |
87 | 88 | request.session['sort_rules_lemma_preview']['status'] = { 'priority': None, 'sort_order': 'desc'} |
88 | 89 | |
89 | - if not request.session.has_key('filter_rules'): | |
90 | + if (not request.session.has_key('filter_rules') or | |
91 | + not all_filter_rules_loaded(request.session['filter_rules'])): | |
90 | 92 | request.session['filter_rules'] = default_filter_rules() |
91 | 93 | |
92 | - if not request.session.has_key('filter_rules_lemma_preview'): | |
94 | + if (not request.session.has_key('filter_rules_lemma_preview') or | |
95 | + not all_filter_rules_loaded(request.session['filter_rules_lemma_preview'])): | |
93 | 96 | request.session['filter_rules_lemma_preview'] = default_filter_rules() |
94 | 97 | |
95 | 98 | if not request.session.has_key('lemma_preview'): |
... | ... |