Commit 514eddc53619d302df00b5ec04a94e69fb387cce
1 parent
2eca62e6
Backslash error and other minor errors fixes.
Showing
12 changed files
with
258 additions
and
958 deletions
dictionary/ajax_lemma_status.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | |
4 | -#All rights reserved. | |
5 | - | |
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | |
7 | -#that the following conditions are met: | |
8 | - | |
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | |
10 | -# the following disclaimer. | |
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | |
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | |
13 | - | |
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | |
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | |
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | |
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
21 | -# POSSIBILITY OF SUCH DAMAGE. | |
22 | - | |
23 | 3 | import operator |
24 | 4 | |
25 | 5 | from django.db.models import Q |
... | ... | @@ -36,9 +16,7 @@ from semantics.utils import get_frames_differences |
36 | 16 | |
37 | 17 | @render('lemma_status.html') |
38 | 18 | @ajax(method='get', encode_result=False) |
39 | -def get_lemma_status(request, id): | |
40 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
41 | - id = request.session['lemma_from_note_id'] | |
19 | +def get_lemma_status(request, id): | |
42 | 20 | selected_lemma = Lemma.objects.get(id=id) |
43 | 21 | abort_status = None |
44 | 22 | next_statuses = [] |
... | ... |
dictionary/ajax_lemma_view.py
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | |
3 | -#Copyright (c) 2012, Bartłomiej Nitoń | |
4 | -#All rights reserved. | |
5 | - | |
6 | -#Redistribution and use in source and binary forms, with or without modification, are permitted provided | |
7 | -#that the following conditions are met: | |
8 | - | |
9 | -# Redistributions of source code must retain the above copyright notice, this list of conditions and | |
10 | -# the following disclaimer. | |
11 | -# Redistributions in binary form must reproduce the above copyright notice, this list of conditions | |
12 | -# and the following disclaimer in the documentation and/or other materials provided with the distribution. | |
13 | - | |
14 | -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | |
15 | -# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
16 | -# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | |
17 | -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | |
18 | -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
19 | -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
20 | -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
21 | -# POSSIBILITY OF SUCH DAMAGE. | |
22 | - | |
23 | 3 | import math |
24 | 4 | import copy |
25 | 5 | import re |
... | ... | @@ -82,8 +62,6 @@ from ajax_jqgrid import JqGridAjax, default_sort_rules, default_filter_rules |
82 | 62 | import locale |
83 | 63 | locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8') |
84 | 64 | |
85 | -import HTMLParser | |
86 | - | |
87 | 65 | DEFAULT_SAVE_PATH = os.path.join(PROJECT_PATH, 'tmp') |
88 | 66 | |
89 | 67 | def reverse(string): |
... | ... | @@ -178,18 +156,19 @@ def nkjpExamplesObjToJs(nkjp_examples, user, lemma): |
178 | 156 | |
179 | 157 | confirmed = True |
180 | 158 | approvers_count = lemma.entry_obj.pos.example_approvers_num |
181 | - #Configuration.objects.get(selected_conf=True).example_approvers_num | |
182 | 159 | if example.source.confirmation_required and example.approvers.count() < approvers_count: |
183 | 160 | try: |
184 | 161 | example.approvers.get(username=user.username) |
185 | 162 | except: |
186 | - confirmed = False | |
187 | - | |
188 | - sentence = example.sentence.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
189 | - comment = example.comment.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
190 | - h = HTMLParser.HTMLParser() | |
191 | - sentence = h.unescape(sentence) | |
192 | - comment = h.unescape(comment) | |
163 | + confirmed = False | |
164 | + | |
165 | + sentence = example.sentence | |
166 | + comment = example.comment | |
167 | +# sentence = example.sentence.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
168 | +# comment = example.comment.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
169 | +# h = HTMLParser.HTMLParser() | |
170 | +# sentence = h.unescape(sentence) | |
171 | +# comment = h.unescape(comment) | |
193 | 172 | |
194 | 173 | example_dict = { 'example_id' : example.id, |
195 | 174 | 'frame_id' : frame_table_id, |
... | ... | @@ -219,18 +198,19 @@ def nkjpLemmaExamplesObjToJs(nkjp_examples, user, lemma): |
219 | 198 | for example in nkjp_examples: |
220 | 199 | confirmed = True |
221 | 200 | approvers_count = lemma.entry_obj.pos.example_approvers_num |
222 | - #Configuration.objects.get(selected_conf=True).example_approvers_num | |
223 | 201 | if example.source.confirmation_required and example.approvers.count() < approvers_count: |
224 | 202 | try: |
225 | 203 | example.approvers.get(username=user.username) |
226 | 204 | except: |
227 | 205 | confirmed = False |
228 | 206 | |
229 | - sentence = example.sentence.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
230 | - comment = example.comment.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
231 | - h = HTMLParser.HTMLParser() | |
232 | - sentence = h.unescape(sentence) | |
233 | - comment = h.unescape(comment) | |
207 | + sentence = example.sentence | |
208 | + comment = example.comment | |
209 | +# sentence = example.sentence.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
210 | +# comment = example.comment.replace('\\', '\\\\').replace("\n", "\\n").replace("\r", "\\r").replace("\t", "\\t").replace("\"", "\\\"") | |
211 | +# h = HTMLParser.HTMLParser() | |
212 | +# sentence = h.unescape(sentence) | |
213 | +# comment = h.unescape(comment) | |
234 | 214 | |
235 | 215 | example_dict = { 'example_id' : example.id, |
236 | 216 | 'frame_id' : '', |
... | ... | @@ -249,8 +229,6 @@ def nkjpLemmaExamplesObjToJs(nkjp_examples, user, lemma): |
249 | 229 | @render('old_frames.html') |
250 | 230 | @ajax(method='get', encode_result=False) |
251 | 231 | def get_old_frames(request, id): |
252 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
253 | - id = request.session['lemma_from_note_id'] | |
254 | 232 | selected_lemma = Lemma.objects.get(id=id) |
255 | 233 | old_frames = selected_lemma.old_frames |
256 | 234 | reflexed_frames = [] |
... | ... | @@ -376,42 +354,39 @@ def get_lemma_desc(request, id): |
376 | 354 | @render('new_frames.html') |
377 | 355 | @ajax(method='get', encode_result=False) |
378 | 356 | def get_new_frames(request, id): |
379 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
380 | - id = request.session['lemma_from_note_id'] | |
381 | - | |
382 | 357 | selected_lemma = Lemma.objects.get(id=id) |
383 | - new_frames = selected_lemma.frames.order_by('text_rep') | |
358 | + #new_frames = selected_lemma.frames.order_by('text_rep') | |
384 | 359 | |
385 | 360 | # sprawdz czy uzytkownik jest wlascicielem wybranego hasla |
386 | 361 | can_modify = user_can_modify(selected_lemma, request.user) |
387 | 362 | |
388 | - serialized_frames = [] | |
389 | - for frame in new_frames: | |
390 | - serialized_frames.append(frameObjToSerializableDict(selected_lemma, frame, True)) | |
391 | - json_frames = json_encode(serialized_frames) | |
392 | - | |
393 | - # konwertowanie przykladow na zrozumiale przez java sript | |
394 | - nkjp_examples = selected_lemma.nkjp_examples.order_by('source__priority', | |
395 | - 'opinion__priority', | |
396 | - 'sentence') | |
397 | - nkjp_examples_js = nkjpExamplesObjToJs(nkjp_examples, request.user, selected_lemma) | |
398 | - | |
399 | - json_nkjp_examples = json_encode(nkjp_examples_js) | |
400 | - | |
363 | +# serialized_frames = [] | |
364 | +# for frame in new_frames: | |
365 | +# serialized_frames.append(frameObjToSerializableDict(selected_lemma, frame, True)) | |
366 | +# json_frames = json_encode(serialized_frames) | |
367 | +# | |
368 | +# # konwertowanie przykladow na zrozumiale przez java sript | |
369 | +# nkjp_examples = selected_lemma.nkjp_examples.order_by('source__priority', | |
370 | +# 'opinion__priority', | |
371 | +# 'sentence') | |
372 | +# nkjp_examples_js = nkjpExamplesObjToJs(nkjp_examples, request.user, selected_lemma) | |
373 | +# | |
374 | +# json_nkjp_examples = json_encode(nkjp_examples_js) | |
375 | +# | |
401 | 376 | add_nkjp_form = AddNkjpExampleForm() |
402 | - | |
403 | - lemma_nkjp_examples = selected_lemma.lemma_nkjp_examples.order_by('source__priority', | |
404 | - 'opinion__priority', | |
405 | - 'sentence') | |
406 | - lemma_nkjp_examples_js = nkjpLemmaExamplesObjToJs(lemma_nkjp_examples, request.user, selected_lemma) | |
407 | - json_lemma_nkjp_examples = json_encode(lemma_nkjp_examples_js) | |
408 | - | |
409 | - return {'serialized_frames': json_frames, | |
377 | +# | |
378 | +# lemma_nkjp_examples = selected_lemma.lemma_nkjp_examples.order_by('source__priority', | |
379 | +# 'opinion__priority', | |
380 | +# 'sentence') | |
381 | +# lemma_nkjp_examples_js = nkjpLemmaExamplesObjToJs(lemma_nkjp_examples, request.user, selected_lemma) | |
382 | +# json_lemma_nkjp_examples = json_encode(lemma_nkjp_examples_js) | |
383 | + | |
384 | + return {#'serialized_frames': json_frames, | |
410 | 385 | 'add_nkjp_form': add_nkjp_form, |
411 | - 'nkjp_examples': json_nkjp_examples, | |
386 | + #'nkjp_examples': json_nkjp_examples, | |
412 | 387 | 'can_modify': can_modify, |
413 | 388 | 'selected_lemma': selected_lemma, |
414 | - 'lemma_nkjp_examples': json_lemma_nkjp_examples, | |
389 | + #'lemma_nkjp_examples': json_lemma_nkjp_examples, | |
415 | 390 | 'skladnica_examples': selected_lemma.skladnica_frames.exists(), |
416 | 391 | 'xcp_examples': selected_lemma.entry_obj.xcp_examples.exists()} |
417 | 392 | |
... | ... | @@ -427,9 +402,7 @@ def get_ctrl_preview(request, id): |
427 | 402 | |
428 | 403 | @render('lemma_examples.html') |
429 | 404 | @ajax(method='get', encode_result=False) |
430 | -def get_lemma_examples(request, id): | |
431 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
432 | - id = request.session['lemma_from_note_id'] | |
405 | +def get_lemma_examples(request, id): | |
433 | 406 | selected_lemma = Lemma.objects.get(id=id) |
434 | 407 | lemma_nkjp_examples = selected_lemma.lemma_nkjp_examples.order_by('source__priority', |
435 | 408 | 'opinion__priority', |
... | ... | @@ -490,9 +463,6 @@ def example_got_assigned_semantics(request, lemma_id, example_id): |
490 | 463 | @render('lemma_notes.html') |
491 | 464 | @ajax(method='get', encode_result=False) |
492 | 465 | def get_lemma_notes(request, id): |
493 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
494 | - id = request.session['lemma_from_note_id'] | |
495 | - request.session['lemma_from_note_id'] = '' | |
496 | 466 | selected_lemma = Lemma.objects.get(id=id) |
497 | 467 | add_note_form = MessageForm() |
498 | 468 | messages = selected_lemma.messages.filter(private=False).order_by('-time') |
... | ... | @@ -672,9 +642,7 @@ def restore_lemma(request, change_id, lemma_id): |
672 | 642 | |
673 | 643 | @render('change_ctrl.html') |
674 | 644 | @ajax(method='get', encode_result=False) |
675 | -def get_change_ctrl(request, id): | |
676 | - if request.session.has_key('lemma_from_note_id') and request.session['lemma_from_note_id']: | |
677 | - id = request.session['lemma_from_note_id'] | |
645 | +def get_change_ctrl(request, id): | |
678 | 646 | selected_lemma = Lemma.objects.get(id=id) |
679 | 647 | old_versions = selected_lemma.old_versions.order_by('-time') |
680 | 648 | can_modify = (user_can_modify(selected_lemma, request.user) and |
... | ... | @@ -2180,7 +2148,7 @@ def get_frame_chars(request, frame_id): |
2180 | 2148 | @ajax(method='get', encode_result=False) |
2181 | 2149 | def xcp_example_propositions(request, frame, argument_ids, lemma_id): |
2182 | 2150 | propositions = [] |
2183 | - lemma_obj = Lemma.objects.get(old=False, id=lemma_id) | |
2151 | + lemma_obj = Lemma.objects.get(id=lemma_id) | |
2184 | 2152 | entry = lemma_obj.entry_obj |
2185 | 2153 | # TODO: zlikwidowac zaslepke na przyslowki |
2186 | 2154 | if entry.pos.tag != 'adv': |
... | ... | @@ -3211,3 +3179,28 @@ def get_examples(request, lemma_id): |
3211 | 3179 | json_examples = json_encode(examples_js) |
3212 | 3180 | return {'examples': json_examples, |
3213 | 3181 | 'can_modify': user_can_modify(lemma, request.user)} |
3182 | + | |
3183 | +@ajax(method='get') | |
3184 | +def get_schemata_and_examples(request, lemma_id): | |
3185 | + lemma = Lemma.objects.get(id=lemma_id) | |
3186 | + | |
3187 | + examples = lemma.nkjp_examples.order_by('source__priority', | |
3188 | + 'opinion__priority', | |
3189 | + 'sentence') | |
3190 | + examples_js = nkjpExamplesObjToJs(examples, request.user, lemma) | |
3191 | + json_examples = json_encode(examples_js) | |
3192 | + | |
3193 | + lemma_examples = lemma.lemma_nkjp_examples.order_by('source__priority', | |
3194 | + 'opinion__priority', | |
3195 | + 'sentence') | |
3196 | + lemma_examples_js = nkjpLemmaExamplesObjToJs(lemma_examples, request.user, lemma) | |
3197 | + json_lemma_examples = json_encode(lemma_examples_js) | |
3198 | + | |
3199 | + schemata = lemma.frames.order_by('text_rep') | |
3200 | + serialized_schemata = [frameObjToSerializableDict(lemma, schema, True) for schema in schemata] | |
3201 | + json_schemata = json_encode(serialized_schemata) | |
3202 | + | |
3203 | + return {'examples': json_examples, | |
3204 | + 'lemma_examples': json_lemma_examples, | |
3205 | + 'schemata': json_schemata, | |
3206 | + 'can_modify': user_can_modify(lemma, request.user)} | |
... | ... |
dictionary/management/commands/approve_examples.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +from django.core.management.base import BaseCommand | |
4 | + | |
5 | +from dictionary.models import NKJP_Example | |
6 | + | |
7 | +class Command(BaseCommand): | |
8 | + args = 'none' | |
9 | + help = "" | |
10 | + | |
11 | + def handle(self, **options): | |
12 | + approve_examples() | |
13 | + | |
14 | +def approve_examples(): | |
15 | + for example in NKJP_Example.objects.filter(approved=False): | |
16 | + if example.approvers.count() > 0: | |
17 | + example.approved = True | |
18 | + example.save() | |
19 | + print example | |
20 | + | |
0 | 21 | \ No newline at end of file |
... | ... |
dictionary/management/commands/get_examples.py
1 | 1 | #-*- coding:utf-8 -*- |
2 | 2 | |
3 | 3 | import codecs |
4 | -import operator | |
4 | +import datetime | |
5 | 5 | import os |
6 | -import re | |
7 | -from subprocess import call | |
8 | -from tempfile import mkdtemp, mkstemp | |
9 | 6 | |
10 | 7 | from django.core.management.base import BaseCommand |
11 | -from django.utils.encoding import smart_str | |
12 | -from django.db.models import Q | |
13 | 8 | |
14 | -#import corpus2 | |
15 | -from common.morfeusz import analyse | |
16 | - | |
17 | -from dictionary.models import Argument, Lemma | |
9 | +from dictionary.models import Lemma, get_ready_statuses | |
18 | 10 | from settings import PROJECT_PATH |
19 | 11 | |
20 | 12 | BASE_PATH = os.path.join(PROJECT_PATH, 'data') |
21 | -#['gotowe', 'sprawdzone', 'tymczasowy'] | |
22 | -STATUSES_LS = [u'zalążkowe', u'gotowe', u'sprawdzone', | |
23 | - u'(F) w obróbce', u'(F) gotowe', u'(F) sprawdzone', | |
24 | - u'(S) w obróbce', u'(S) gotowe', u'(S) sprawdzone'] | |
25 | - | |
26 | -NOUN_TAGS = ['subst', 'ger'] | |
27 | - | |
28 | -#VERBTAGLIST = ['fin', 'praet', 'bedzie', 'inf', 'imps', 'impt', | |
29 | -# 'winien', 'pred'] | |
30 | -#ADJTAGLIST = ['adj', 'pact', 'ppas'] | |
31 | -#INTERPTAGLIST = ['interp'] | |
32 | -#NUMERALTAGLIST = ['num', 'numcol'] | |
33 | - | |
34 | -XCES_HEADER = """<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE cesAna SYSTEM 'xcesAnaIPI.dtd'><cesAna type="pre_morph" version="WROC-1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
35 | -<chunkList xml:base="text.xml"> | |
36 | -""" | |
37 | -XCES_FOOTER = """</chunkList> | |
38 | -</cesAna> | |
39 | -""" | |
40 | - | |
41 | -WCRFT_CONFIG = 'nkjp_s2.ini' | |
42 | - | |
43 | -LABELS = ('haslo', | |
44 | - 'status hasla', | |
45 | - 'identyfikator schematu', | |
46 | - 'schemat', | |
47 | - 'opinia o schemacie', | |
48 | - 'przyklad', | |
49 | - 'otagowany przyklad', | |
50 | - 'fragmenty przykladu', | |
51 | - 'opinia o przykladzie', | |
52 | - 'zrodlo przykladu', | |
53 | - 'wybor argumentow') | |
54 | 13 | |
55 | - | |
56 | -ARG_TYPES_BY_PRIORITY = ['fixed', | |
57 | - # frazy przyimkowe | |
58 | - 'preplexnp', 'comprepnp', 'prepnp', 'prepncp', 'prepadjp', | |
59 | - # frazy rzeczownikowe | |
60 | - 'lexnp', 'np', | |
61 | - # frazy rzeczownikowo-zdaniowe | |
62 | - 'ncp', 'cp', | |
63 | - # adjp | |
64 | - 'adjp', | |
65 | - # bezokoliczniki | |
66 | - 'infp', | |
67 | - # refl | |
68 | - 'refl', | |
69 | - # xp | |
70 | - 'xp', | |
71 | - # advp | |
72 | - 'advp', | |
73 | - # nonch | |
74 | - 'nonch', | |
75 | - # lemma - nie jest sortowane chyba, bo dodawane na innym etapie niz reszta argumentow | |
76 | - 'lemma', | |
77 | - # xp | |
78 | - 'xp' | |
79 | - ] | |
14 | +LABELS = (u'hasło', | |
15 | + u'status hasła', | |
16 | + u'identyfikator schematu', | |
17 | + u'schemat', | |
18 | + u'opinia o schemacie', | |
19 | + u'przykład', | |
20 | + u'opinia o przykładzie', | |
21 | + u'zródło przykładu', | |
22 | + u'wybór typów fraz') | |
80 | 23 | |
81 | 24 | class Command(BaseCommand): |
82 | 25 | help = 'Get pinned examples from Slowal.' |
83 | 26 | |
84 | 27 | def handle(self, **options): |
85 | - get_examples() | |
86 | - | |
87 | -def write_examples(q_statuses): | |
88 | - try: | |
89 | - examples_file = codecs.open(os.path.join(BASE_PATH, | |
90 | - 'examples_gotowe_plus.txt'), 'wt', 'utf-8') | |
91 | - for lemma in Lemma.objects.filter(old=False).filter(reduce(operator.or_, q_statuses)).order_by('entry').all(): | |
92 | - print lemma | |
93 | - examples_file.write(lemma.entry+'\n') | |
94 | - for frame in lemma.frames.order_by('text_rep').all(): | |
95 | - if lemma.frame_opinions.get(frame=frame).value.value != u'zła': | |
96 | - examples_file.write('\t%s\n' % frame.text_rep) | |
97 | - for example in lemma.nkjp_examples.filter(frame=frame): | |
98 | - examples_file.write('\t\t--> %s\n' % example.sentence) | |
99 | - examples_file.write('\n\n') | |
100 | - finally: | |
101 | - examples_file.close() | |
102 | - | |
103 | -def write_xces_opening(outfile): | |
104 | - outfile.write(XCES_HEADER) | |
105 | - | |
106 | -def write_xces_closing(outfile): | |
107 | - outfile.write(XCES_FOOTER) | |
28 | + get_examples() | |
29 | + | |
30 | +def get_examples(): | |
31 | + ready_statuses = get_ready_statuses() | |
32 | + write_detailed_examples(ready_statuses) | |
33 | + # write_examples(ready_statuses) | |
108 | 34 | |
109 | -def write_paragraph(what, outfile): | |
110 | - if len(what) > 0 and not what.isspace(): | |
111 | - outfile.write(u'<chunk type="p" id="p1">') | |
112 | - outfile.write(what) | |
113 | - outfile.write(u'</chunk>\n') | |
114 | - | |
115 | -def sentence_to_xces(sentence): | |
35 | +def write_detailed_examples(statuses): | |
116 | 36 | try: |
117 | - tmp_folder = mkdtemp() | |
118 | - os.chdir(tmp_folder) | |
119 | - tmp_file, tmpfilename = mkstemp(dir=tmp_folder) | |
120 | - os.close(tmp_file) | |
121 | - outfile = codecs.open(tmpfilename, 'wt', 'utf-8') | |
122 | - write_xces_opening(outfile) | |
123 | - write_paragraph(sentence, outfile) | |
124 | - write_xces_closing(outfile) | |
125 | - finally: | |
126 | - outfile.close() | |
127 | - return tmpfilename | |
128 | - | |
129 | -def chunks(rdr): | |
130 | - """Yields subsequent paragraphs from a reader.""" | |
131 | - while True: | |
132 | - chunk = rdr.get_next_chunk() | |
133 | - if not chunk: | |
134 | - break | |
135 | - yield chunk | |
136 | - | |
137 | -#def tag_sentence(tagged_sentence_path): | |
138 | -# sentences_count = 0 | |
139 | -# tagged_sentence_chunks = [] | |
140 | -# tagset = corpus2.get_named_tagset('nkjp') | |
141 | -# rdr = corpus2.TokenReader.create_path_reader('xces', tagset, tagged_sentence_path) | |
142 | -# for chunk in chunks(rdr): | |
143 | -# for sent in chunk.sentences(): | |
144 | -# sentences_count += 1 | |
145 | -# for tok in sent.tokens(): | |
146 | -# prefered_lexeme = tok.get_preferred_lexeme(tagset) | |
147 | -# base_form = prefered_lexeme.lemma_utf8().decode('utf-8') | |
148 | -# orth_form = tok.orth_utf8().decode('utf-8') | |
149 | -# tags = tagset.tag_to_string(prefered_lexeme.tag()) | |
150 | -# sentence_chunk = u'%s[%s>%s]' % (orth_form, base_form, tags) | |
151 | -# tagged_sentence_chunks.append(sentence_chunk) | |
152 | -# tagged_sentence = ' '.join(tagged_sentence_chunks) | |
153 | -# if sentences_count > 1: | |
154 | -# pass | |
155 | -# return tagged_sentence | |
156 | - | |
157 | -#def get_tagged_sentence(sentence): | |
158 | -# tagged_sentence = 'Error!' | |
159 | -# try: | |
160 | -# tmp_folder = mkdtemp() | |
161 | -# os.chdir(tmp_folder) | |
162 | -# xces_file, xces_path = mkstemp(dir=tmp_folder) | |
163 | -# os.close(xces_file) | |
164 | -# tagged_sentence_file, tagged_sentence_path = mkstemp(dir=tmp_folder) | |
165 | -# os.close(tagged_sentence_file) | |
166 | -# xces_file = codecs.open(xces_path, 'wt', 'utf-8') | |
167 | -# write_xces_opening(xces_file) | |
168 | -# write_paragraph(sentence, xces_file) | |
169 | -# write_xces_closing(xces_file) | |
170 | -# xces_file.close() | |
171 | -# try: | |
172 | -# call(['wcrft', WCRFT_CONFIG, xces_path, '-O', tagged_sentence_path, '-C', '-i', 'premorph']) | |
173 | -# tagged_sentence = tag_sentence(tagged_sentence_path) | |
174 | -# except: | |
175 | -# print 'Tagging failed.' | |
176 | -# finally: | |
177 | -# xces_file.close() | |
178 | -# os.remove(xces_path) | |
179 | -# os.remove(tagged_sentence_path) | |
180 | -# return tagged_sentence | |
181 | - | |
182 | -def write_detailed_examples(q_statuses): | |
183 | - try: | |
184 | - examples_file = codecs.open(os.path.join(BASE_PATH, | |
185 | - 'detailed_examples_20150616.csv'), 'wt', 'utf-8') | |
186 | - examples_file.write(u'%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % LABELS) | |
187 | - for lemma in Lemma.objects.filter(old=False).filter(reduce(operator.or_, q_statuses)).order_by('entry').all(): | |
37 | + lemmas = Lemma.objects.filter(old=False) | |
38 | + lemmas = lemmas.filter(status__in=statuses) | |
39 | + now = datetime.datetime.now().strftime('%Y%m%d') | |
40 | + examples_file = codecs.open(os.path.join(BASE_PATH, 'detailed_examples_%s.csv' % now), 'wt', 'utf-8') | |
41 | + examples_file.write(u'%s\n' % u'\t'.join(LABELS)) | |
42 | + for lemma in lemmas.order_by('entry_obj__name'): | |
188 | 43 | print lemma |
189 | - lemma_entry = lemma.entry | |
44 | + lemma_entry = lemma.entry_obj.name | |
190 | 45 | lemma_status = lemma.status.status |
191 | 46 | for frame in lemma.frames.order_by('text_rep').all(): |
192 | - frame_text_rep = frame.text_rep | |
47 | + if not lemma.phraseology_ready() and frame.phraseologic: | |
48 | + continue | |
193 | 49 | frame_opinion = lemma.frame_opinions.filter(frame=frame).all()[0].value |
194 | 50 | for example in lemma.nkjp_examples.filter(frame=frame): |
195 | - sentence = example.sentence.replace('\n', ' ').replace('\r', '').replace('\t', ' ') | |
196 | - #tagged_sentence = get_tagged_sentence(sentence) mozna wlaczyc w razie czego | |
197 | - tagged_sentence = '' | |
198 | - example_opinion = example.opinion.opinion | |
199 | - example_source = example.source.source | |
51 | + sentence = example.sentence.replace('\n', ' ').replace('\r', '').replace('\t', ' ') | |
200 | 52 | arguments_selection = u'%s' % u' + '.join([u'%s' % selection.__unicode__() for selection in example.arguments.all()]) |
201 | - examples_file.write(u'%s\t%s\t%d\t%s\t%s\t%s\t%s\t\t%s\t%s\t%s\n' % (lemma_entry, | |
202 | - lemma_status, | |
203 | - frame.id, | |
204 | - frame_text_rep, | |
205 | - frame_opinion, | |
206 | - sentence, | |
207 | - tagged_sentence, | |
208 | - example_opinion, | |
209 | - example_source, | |
210 | - arguments_selection)) | |
53 | + examples_file.write(u'%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n' % (lemma_entry, | |
54 | + lemma_status, | |
55 | + frame.id, | |
56 | + frame.get_position_spaced_text_rep(), | |
57 | + frame_opinion, | |
58 | + sentence, | |
59 | + example.opinion.opinion, | |
60 | + example.source.source, | |
61 | + arguments_selection)) | |
211 | 62 | finally: |
212 | 63 | examples_file.close() |
213 | - | |
214 | -def get_arguments(arguments_selection): | |
215 | - arguments = [] | |
216 | - positions = arguments_selection.split('+') | |
217 | - for position in positions: | |
218 | - category = '' | |
219 | - position = position.strip().lstrip('[').rstrip(']') | |
220 | - if position.startswith('subj'): | |
221 | - category = 'subj' | |
222 | - elif position.startswith('obj'): | |
223 | - category = 'obj' | |
224 | - selection = re.findall(ur'<.*?>', position)[0] | |
225 | - for arg in selection.lstrip('<').rstrip('>').split(';'): | |
226 | - if category: | |
227 | - arguments.append(u'%s:%s' % (category, arg)) | |
228 | - else: | |
229 | - arguments.append(arg) | |
230 | - arguments = sort_arguments(arguments) | |
231 | - return arguments | |
232 | - | |
233 | -def sort_arguments(arguments): | |
234 | - sorted_arguments = [] | |
235 | - for type in ARG_TYPES_BY_PRIORITY: | |
236 | - for arg in arguments: | |
237 | - (arg_type, attributes, category) = arg_from_text_rep(arg) | |
238 | - if arg_type == type: | |
239 | - sorted_arguments.append(arg) | |
240 | - return sorted_arguments | |
241 | - | |
242 | -def arg_from_text_rep(argument): | |
243 | - attributes = [] | |
244 | - category = '' | |
245 | - if ':' in argument: | |
246 | - arg_split = argument.split(':') | |
247 | - category = arg_split[0] | |
248 | - argument = arg_split[1] | |
249 | - arg_parts = argument.split('(') | |
250 | - arg_type = arg_parts[0] | |
251 | - if len(arg_parts) > 1: | |
252 | - attributes = arg_parts[1].rstrip(')').replace("'", "").split(',') | |
253 | - return arg_type, attributes, category | |
254 | - | |
255 | -def tokenize_sentence(sentence): | |
256 | - token_idx = 0 | |
257 | - tokens = [] | |
258 | - chunks = sentence.split('] ') | |
259 | - for chunk in chunks: | |
260 | - if chunk.startswith('[[['): | |
261 | - token = {'idx': token_idx, | |
262 | - 'orth': '[', | |
263 | - 'base': '[', | |
264 | - 'tags': ['interp'], | |
265 | - 'argument': '', | |
266 | - 'argument_start': -1, | |
267 | - 'argument_end': -1, | |
268 | - 'occupied': False} | |
269 | - elif chunk.startswith('>'): | |
270 | - token = {'idx': token_idx, | |
271 | - 'orth': '>', | |
272 | - 'base': '>', | |
273 | - 'tags': ['interp'], | |
274 | - 'argument': '', | |
275 | - 'argument_start': -1, | |
276 | - 'argument_end': -1, | |
277 | - 'occupied': False} | |
278 | - else: | |
279 | - chunk_parts = chunk.split('[') | |
280 | - (base, tags) = (chunk_parts[1].split('>'))#rstrip(']').) | |
281 | - orth = chunk_parts[0].lower() | |
282 | - token = {'idx': token_idx, | |
283 | - 'orth': orth, | |
284 | - 'base': base, | |
285 | - 'tags': tags.split(':'), | |
286 | - 'argument': '', | |
287 | - 'argument_start': -1, | |
288 | - 'argument_end': -1, | |
289 | - 'occupied': False} | |
290 | - tokens.append(token) | |
291 | - token_idx += 1 | |
292 | - return tokens | |
293 | - | |
294 | -def case_conversion(case, category): | |
295 | - if case == 'instr': | |
296 | - case = 'inst' | |
297 | - elif case == 'part': | |
298 | - case = u'gen|acc' | |
299 | - elif case == 'str' and (category == 'subj' or not category): | |
300 | - case = 'nom' | |
301 | - elif case == 'str' and category == 'obj': | |
302 | - case = 'acc' | |
303 | - return case | |
304 | - | |
305 | -def number_conversion(number): | |
306 | - if number == '_': | |
307 | - number = '' | |
308 | - return number | |
309 | - | |
310 | -def aspect_conversion(aspect): | |
311 | - if aspect == '_': | |
312 | - aspect = '' | |
313 | - return aspect | |
314 | - | |
315 | -def phrase_type_conversion(phrase_type): | |
316 | - if phrase_type == u'że': | |
317 | - phrase_type = u'że|iż' | |
318 | - elif phrase_type == u'żeby': | |
319 | - phrase_type = u'żeby|aby|by|iżby|ażeby' | |
320 | - elif phrase_type == u'żeby2': | |
321 | - phrase_type = u'że|iż|żeby' # !!! nie wiem co ma być pod żeby2 | |
322 | - elif phrase_type == u'int': | |
323 | - phrase_type = u'kiedy|jak|czy' # !!! nie wiem co ma być pod int | |
324 | - elif phrase_type == u'jakby': | |
325 | - phrase_type = u'jakby|jak gdyby' | |
326 | - return phrase_type | |
327 | 64 | |
328 | -def complex_prep_lemma_conversion(lemma): | |
329 | - if lemma == u'powodu': | |
330 | - lemma = u'powód' | |
331 | - elif lemma == u'sprawie': | |
332 | - lemma = u'sprawa' | |
333 | - elif lemma == u'kwestii': | |
334 | - lemma = u'kwestia' | |
335 | - elif lemma == u'roli': | |
336 | - lemma = u'rola' | |
337 | - elif lemma == u'okolicach': | |
338 | - lemma = u'okolica' | |
339 | - elif lemma == u'czasie': | |
340 | - lemma = u'czas' | |
341 | - elif lemma == u'stronie': | |
342 | - lemma = u'strona' | |
343 | - elif lemma == u'początku': | |
344 | - lemma = u'początek' | |
345 | - return lemma | |
346 | - | |
347 | -def proper_case(token, case): | |
348 | - possible_cases = [case] | |
349 | - proper_case = False | |
350 | - if '|' in case: | |
351 | - possible_cases = case.split('|') | |
352 | - if len(set(token['tags']) & set(possible_cases)) == 1: | |
353 | - proper_case = True | |
354 | - return proper_case | |
355 | - | |
356 | -def get_matching_token(tokens, orth='', base='', case='', | |
357 | - number='', phrase_type='', aspect='', | |
358 | - degree='', pos=''): | |
359 | -# print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
360 | -# print 'orth: %s, base: %s, case: %s, number: %s, pos: %s' % (orth, | |
361 | -# base, | |
362 | -# case, | |
363 | -# number, | |
364 | -# pos) | |
365 | - matching_token = None | |
366 | - for token in tokens: | |
367 | - match = True | |
368 | - if token['occupied']: | |
369 | - continue | |
370 | - if orth and not token['orth'] == orth: | |
371 | - match = False | |
372 | - if base and not token['base'] == base: | |
373 | - match = False | |
374 | - if case and not proper_case(token, case): | |
375 | - match = False | |
376 | - if number and not number in token['tags']: | |
377 | - match = False | |
378 | - if aspect and not aspect in token['tags']: | |
379 | - match = False | |
380 | - if degree and not degree in token['tags']: | |
381 | - match = False | |
382 | - if pos and not pos in token['tags']: | |
383 | - match = False | |
384 | - if match: | |
385 | - matching_token = token | |
386 | - break | |
387 | - return matching_token | |
388 | - | |
389 | -def fill_token_data(token, argument, start_idx, end_idx): | |
390 | - token['argument'] = argument | |
391 | - token['argument_start'] = start_idx | |
392 | - token['argument_end'] = end_idx | |
393 | - | |
394 | -def mark_fixed(tokens, argument, tresc): | |
395 | - tresc_idx = 0 | |
396 | - tresc_orths = tresc.split() | |
397 | - tresc_start = -1 | |
398 | - tresc_end = -1 | |
399 | - for token in tokens: | |
400 | - if token['occupied']: | |
401 | - continue | |
402 | - if token['orth'] == tresc_orths[tresc_idx]: | |
403 | - tresc_idx += 1 | |
404 | - if tresc_start == -1: | |
405 | - tresc_start = tokens.index(token) | |
406 | - else: | |
407 | - tresc_idx = 0 | |
408 | - tresc_start = -1 | |
409 | - if tresc_idx == len(tresc_orths): | |
410 | - tresc_end = tokens.index(token) | |
411 | - break | |
412 | - for token in tokens[tresc_start:tresc_end+1]: | |
413 | - fill_token_data(token, argument, tresc_start, tresc_end) | |
414 | - token['occupied'] = True | |
415 | - | |
416 | -def mark_preplexnp(tokens, argument, preposition, case, number, lemma): | |
417 | - preposition_token = get_matching_token(tokens, orth='', base=preposition, | |
418 | - case=case, number='', pos='prep') # !! case nie powinien być zgodny z lematem?? | |
419 | - start_idx = tokens.index(preposition_token) | |
420 | - lemma_token = get_matching_token(tokens[start_idx:], orth='', base=lemma, | |
421 | - case=case, number=number, pos='subst') | |
422 | - end_idx = tokens.index(lemma_token) | |
423 | - fill_token_data(preposition_token, argument, start_idx, end_idx) | |
424 | - fill_token_data(lemma_token, argument, start_idx, end_idx) | |
425 | - for token in tokens[start_idx:end_idx+1]: | |
426 | - token['occupied'] = True | |
427 | - | |
428 | -def mark_comprepnp(tokens, argument, preposition, lemma): | |
429 | - if preposition == u'co' and lemma == u'do': | |
430 | - preposition_token = get_matching_token(tokens, orth='co', base='', | |
431 | - case='', number='', pos='subst') # !! czy pos nie powinien byc subst | |
432 | - start_idx = tokens.index(preposition_token) | |
433 | - lemma_token = get_matching_token(tokens[start_idx:], orth='do', base='', | |
434 | - case='', number='', pos='prep') | |
435 | - end_idx = tokens.index(lemma_token) | |
436 | - else: | |
437 | - preposition_token = get_matching_token(tokens, orth='', base=preposition, | |
438 | - case='', number='', pos='prep') # !! case nie powinien być zgodny z lematem?? | |
439 | - start_idx = tokens.index(preposition_token) | |
440 | - lemma_base = complex_prep_lemma_conversion(lemma) | |
441 | - lemma_token = get_matching_token(tokens[start_idx:], orth='', base=lemma_base, | |
442 | - case='', number='', pos='subst') | |
443 | - end_idx = tokens.index(lemma_token) | |
444 | - noun_token = get_matching_token(tokens[end_idx+1:], orth='', base='', | |
445 | - case='', number='', pos='subst') # za proste, glupoty wychodza | |
446 | - end_idx = tokens.index(noun_token) | |
447 | - fill_token_data(preposition_token, argument, start_idx, end_idx) | |
448 | - fill_token_data(lemma_token, argument, start_idx, end_idx) | |
449 | - fill_token_data(noun_token, argument, start_idx, end_idx) | |
450 | - for token in tokens[start_idx:end_idx+1]: | |
451 | - token['occupied'] = True | |
452 | - | |
453 | -def mark_prepnp(tokens, argument, preposition, case): | |
454 | - preposition_token = get_matching_token(tokens, orth='', base=preposition, | |
455 | - case=case, number='', pos='prep') # !! case nie powinien być zgodny z lematem?? | |
456 | - start_idx = tokens.index(preposition_token) | |
457 | - noun_token = get_matching_token(tokens[start_idx:], orth='', base='', | |
458 | - case=case, number='', pos='subst') | |
459 | - end_idx = tokens.index(noun_token) | |
460 | - fill_token_data(preposition_token, argument, start_idx, end_idx) | |
461 | - fill_token_data(noun_token, argument, start_idx, end_idx) | |
462 | - for token in tokens[start_idx:end_idx+1]: | |
463 | - token['occupied'] = True | |
464 | - | |
465 | -def mark_phrase(tokens, start_idx, argument, phrase_type): | |
466 | - for phrase in phrase_type.split('|'): | |
467 | - phrase_parts = phrase.split() | |
468 | - if len(phrase_parts) > 1: | |
469 | - phrase_token1 = get_matching_token(tokens[start_idx+1:], orth='', base=phrase_parts[0], | |
470 | - case='', number='', pos='') | |
471 | - if phrase_token1: | |
472 | - phrase_start_idx = tokens.index(phrase_token1) | |
473 | - phrase_token2 = get_matching_token(tokens[phrase_start_idx+1:], orth='', base=phrase_parts[1], | |
474 | - case='', number='', pos='') | |
475 | - if phrase_token1 and phrase_token2: | |
476 | - phrase_end_idx = tokens.index(phrase_token2) | |
477 | - fill_token_data(phrase_token1, argument, phrase_start_idx, phrase_end_idx) | |
478 | - fill_token_data(phrase_token2, argument, phrase_start_idx, phrase_end_idx) | |
479 | - break | |
480 | - else: | |
481 | - phrase_token = get_matching_token(tokens[start_idx+1:], base=phrase) | |
482 | - if phrase_token: | |
483 | - phrase_end_idx = tokens.index(phrase_token) | |
484 | - phrase_start_idx = phrase_end_idx | |
485 | - fill_token_data(phrase_token, argument, phrase_start_idx, phrase_end_idx) | |
486 | - break | |
487 | - return phrase_start_idx, phrase_end_idx | |
488 | - | |
489 | -def mark_prepncp(tokens, argument, preposition, case, phrase_type): | |
490 | - preposition_token = get_matching_token(tokens, orth='', base=preposition, | |
491 | - case=case, number='', pos='prep') # !! case nie powinien być zgodny z lematem?? | |
492 | - start_idx = tokens.index(preposition_token) | |
493 | - noun_token = get_matching_token(tokens[start_idx:], orth='', base='', | |
494 | - case=case, number='', pos='subst') | |
495 | - end_idx = tokens.index(noun_token) | |
496 | - xx, end_idx = mark_phrase(tokens, end_idx, argument, phrase_type) | |
497 | - fill_token_data(preposition_token, argument, start_idx, end_idx) | |
498 | - fill_token_data(noun_token, argument, start_idx, end_idx) | |
499 | - for token in tokens[start_idx:end_idx+1]: | |
500 | - token['occupied'] = True | |
501 | - | |
502 | -def mark_prepadjp(tokens, argument, preposition, case): | |
503 | - preposition_token = get_matching_token(tokens, orth='', base=preposition, | |
504 | - case=case, number='', pos='prep') # !! case nie powinien być zgodny z lematem?? | |
505 | - start_idx = tokens.index(preposition_token) | |
506 | - adj_token = get_matching_token(tokens[start_idx:], orth='', base='', | |
507 | - case=case, number='', pos='adj') | |
508 | - end_idx = tokens.index(adj_token) | |
509 | - fill_token_data(preposition_token, argument, start_idx, end_idx) | |
510 | - fill_token_data(adj_token, argument, start_idx, end_idx) | |
511 | - for token in tokens[start_idx:end_idx+1]: | |
512 | - token['occupied'] = True | |
513 | - | |
514 | -def mark_lexnp(tokens, argument, case, number, lemma): | |
515 | - lemma_token = get_matching_token(tokens, orth='', base=lemma, | |
516 | - case=case, number=number, pos='subst') | |
517 | - start_idx = tokens.index(lemma_token) | |
518 | - end_idx = start_idx | |
519 | - fill_token_data(lemma_token, argument, start_idx, end_idx) | |
520 | - for token in tokens[start_idx:end_idx+1]: | |
521 | - token['occupied'] = True | |
522 | - | |
523 | -def mark_np(tokens, argument, case): | |
524 | - noun_token = get_matching_token(tokens, orth='', base='', | |
525 | - case=case, number='', pos='subst') | |
526 | - start_idx = tokens.index(noun_token) | |
527 | - end_idx = start_idx | |
528 | - fill_token_data(noun_token, argument, start_idx, end_idx) | |
529 | - for token in tokens[start_idx:end_idx+1]: | |
530 | - token['occupied'] = True | |
531 | - | |
532 | -def mark_ncp(tokens, argument, case, phrase_type): | |
533 | - noun_token = get_matching_token(tokens, orth='', base='', | |
534 | - case=case, number='', pos='subst') | |
535 | - start_idx = tokens.index(noun_token) | |
536 | - xx, end_idx = mark_phrase(tokens, start_idx, argument, phrase_type) | |
537 | - fill_token_data(noun_token, argument, start_idx, end_idx) | |
538 | - for token in tokens[start_idx:end_idx+1]: | |
539 | - token['occupied'] = True | |
540 | - | |
541 | -def mark_cp(tokens, argument, phrase_type): | |
542 | - start_idx, end_idx = mark_phrase(tokens, -1, argument, phrase_type) | |
543 | - for token in tokens[start_idx:end_idx+1]: | |
544 | - token['occupied'] = True | |
545 | - | |
546 | -def mark_adjp(tokens, argument, case): | |
547 | - adj_token = get_matching_token(tokens, case=case, pos='adj') | |
548 | - start_idx = tokens.index(adj_token) | |
549 | - end_idx = start_idx | |
550 | - fill_token_data(adj_token, argument, start_idx, end_idx) | |
551 | - for token in tokens[start_idx:end_idx+1]: | |
552 | - token['occupied'] = True | |
553 | - | |
554 | -def mark_infp(tokens, argument, aspect): | |
555 | - inf_token = get_matching_token(tokens, orth='', base='', | |
556 | - case='', number='', aspect=aspect, pos='inf') | |
557 | - start_idx = tokens.index(inf_token) | |
558 | - end_idx = start_idx | |
559 | - fill_token_data(inf_token, argument, start_idx, end_idx) | |
560 | - for token in tokens[start_idx:end_idx+1]: | |
561 | - token['occupied'] = True | |
562 | - | |
563 | -def mark_lemma(tokens, argument, lemma, sie, aspect): | |
564 | - lemma_token = get_matching_token(tokens, orth='', base=lemma, | |
565 | - case='', number='', aspect=aspect, | |
566 | - pos='') | |
567 | - start_idx = tokens.index(lemma_token) | |
568 | - if sie: | |
569 | - sie_token = get_matching_token(tokens[start_idx:], orth='', base=u'się', | |
570 | - case='', number='', pos='') | |
571 | - end_idx = tokens.index(sie_token) | |
572 | - fill_token_data(sie_token, argument, start_idx, end_idx) | |
573 | - else: | |
574 | - end_idx = start_idx | |
575 | - fill_token_data(lemma_token, argument, start_idx, end_idx) | |
576 | - | |
577 | - for token in tokens[start_idx:end_idx+1]: | |
578 | - token['occupied'] = True | |
579 | - | |
580 | -def mark_nonch(tokens, argument, nonch): | |
581 | - for pronoun in nonch.split('|'): | |
582 | - pronoun_parts = pronoun.split() | |
583 | - if len(pronoun_parts) > 1: | |
584 | - matched_tokens = [] | |
585 | - parts_matched = True | |
586 | - pronoun_start_idx = 0 | |
587 | - for pronoun_part in pronoun_parts: | |
588 | - pronoun_token = get_matching_token(tokens[pronoun_start_idx+1:], orth='', base=pronoun_part, | |
589 | - case='', number='', pos='') | |
590 | - if pronoun_token: | |
591 | - pronoun_start_idx = tokens.index(pronoun_token) | |
592 | - matched_tokens.append(pronoun_token) | |
593 | - else: | |
594 | - parts_matched = False | |
595 | - break | |
596 | - if parts_matched: | |
597 | - start_idx = tokens.index(matched_tokens[0]) | |
598 | - end_idx = tokens.index(matched_tokens[-1]) | |
599 | - for token in matched_tokens: | |
600 | - fill_token_data(token, argument, start_idx, end_idx) | |
601 | - break | |
602 | - else: | |
603 | - pronoun_token = get_matching_token(tokens, orth='', base=pronoun, | |
604 | - case='', number='', pos='') | |
605 | - if pronoun_token: | |
606 | - start_idx = tokens.index(pronoun_token) | |
607 | - end_idx = start_idx | |
608 | - fill_token_data(pronoun_token, argument, start_idx, end_idx) | |
609 | - break | |
610 | - for token in tokens[start_idx:end_idx+1]: | |
611 | - token['occupied'] = True | |
612 | - | |
613 | -def mark_advp(tokens, argument, advp_type): | |
614 | - if advp_type == 'pron': | |
615 | - possible_bases = ['tak', 'jak'] | |
616 | - for base in possible_bases: | |
617 | - advp_token = get_matching_token(tokens, base=base, pos='adv') | |
618 | - if advp_token: | |
619 | - break | |
620 | - elif advp_type == 'misc': | |
621 | - possible_degrees = ['com', 'sup'] | |
622 | - for degree in possible_degrees: | |
623 | - advp_token = get_matching_token(tokens, degree=degree, pos='adv') | |
624 | - if advp_token: | |
625 | - break | |
626 | - start_idx = tokens.index(advp_token) | |
627 | - end_idx = start_idx | |
628 | - fill_token_data(advp_token, argument, start_idx, end_idx) | |
629 | - for token in tokens[start_idx:end_idx+1]: | |
630 | - token['occupied'] = True | |
631 | - | |
632 | -def count_occupied(tokens): | |
633 | - occupied_tokens = [token for token in tokens if token['occupied']] | |
634 | - return len(occupied_tokens) | |
635 | - | |
636 | -def mark_arg_in_sentence(argument, sentence_tokens): | |
637 | - (arg_type, attributes, category) = arg_from_text_rep(argument) | |
638 | - if arg_type == 'fixed': | |
639 | - mark_fixed(sentence_tokens, argument, attributes[0]) | |
640 | - elif arg_type == 'preplexnp': | |
641 | - preposition = attributes[0] | |
642 | - case = case_conversion(attributes[1], category) | |
643 | - number = number_conversion(attributes[2]) | |
644 | - lemma = attributes[3] | |
645 | - mark_preplexnp(sentence_tokens, argument, preposition, case, number, lemma) | |
646 | - elif arg_type == 'comprepnp': | |
647 | - complex_preposition_parts = attributes[0].split() | |
648 | - preposition = complex_preposition_parts[0] | |
649 | - lemma = complex_preposition_parts[1] | |
650 | - mark_comprepnp(sentence_tokens, argument, preposition, lemma) | |
651 | - elif arg_type == 'prepnp': | |
652 | - preposition = attributes[0] | |
653 | - case = case_conversion(attributes[1], category) | |
654 | - mark_prepnp(sentence_tokens, argument, preposition, case) | |
655 | - elif arg_type == 'prepncp': | |
656 | - preposition = attributes[0] | |
657 | - case = case_conversion(attributes[1], category) | |
658 | - phrase_type = phrase_type_conversion(attributes[2]) | |
659 | - mark_prepncp(sentence_tokens, argument, preposition, case, phrase_type) | |
660 | - elif arg_type == 'prepadjp': | |
661 | - preposition = attributes[0] | |
662 | - case = case_conversion(attributes[1], category) | |
663 | - mark_prepadjp(sentence_tokens, argument, preposition, case) | |
664 | - elif arg_type == 'lexnp': | |
665 | - case = case_conversion(attributes[0], category) | |
666 | - number = number_conversion(attributes[1]) | |
667 | - lemma = attributes[2] | |
668 | - mark_lexnp(sentence_tokens, argument, case, number, lemma) | |
669 | - elif arg_type == 'np': | |
670 | - case = case_conversion(attributes[0], category) | |
671 | - mark_np(sentence_tokens, argument, case) | |
672 | - elif arg_type == 'ncp': | |
673 | - case = case_conversion(attributes[0], category) | |
674 | - phrase_type = phrase_type_conversion(attributes[1]) | |
675 | - mark_ncp(sentence_tokens, argument, case, phrase_type) | |
676 | - elif arg_type == 'cp': | |
677 | - phrase_type = phrase_type_conversion(attributes[0]) | |
678 | - mark_cp(sentence_tokens, argument, phrase_type) | |
679 | - elif arg_type == 'adjp': | |
680 | - case = case_conversion(attributes[0], category) | |
681 | - mark_adjp(sentence_tokens, argument, case) | |
682 | - elif arg_type == 'infp': | |
683 | - aspect = aspect_conversion(attributes[0]) | |
684 | - mark_infp(sentence_tokens, argument, aspect) | |
685 | - elif arg_type == u'nonch': | |
686 | - nonch = u'co|coś|nic|to|to samo co' | |
687 | - mark_nonch(sentence_tokens, argument, nonch) | |
688 | - elif arg_type == 'lemma': | |
689 | - lemma = attributes[0] | |
690 | - sie = attributes[1] | |
691 | - aspect = aspect_conversion(attributes[2]) | |
692 | - mark_lemma(sentence_tokens, argument, lemma, sie, aspect) | |
693 | - elif arg_type == 'advp': | |
694 | - advp_type = attributes[0] | |
695 | - mark_advp(sentence_tokens, argument, advp_type) | |
696 | -# elif arg_type == 'xp': | |
697 | -# argument_obj = Argument.objects.get(text_rep=argument) | |
698 | -# realizations = [realization.argument.text_rep for realization in argument_obj.realizations.all()] | |
699 | -# start_occupacy = count_occupied(sentence_tokens) | |
700 | -# for realization in sort_arguments(realizations): | |
701 | -# mark_arg_in_sentence(realization, sentence_tokens) | |
702 | -# if count_occupied(sentence_tokens) > start_occupacy: | |
703 | -# break | |
704 | - | |
705 | - | |
706 | -def cut_sentence_chunks(sentence_tokens): | |
707 | - endpoint = -1 | |
708 | - ignore = False | |
709 | - sentence_chunks = [] | |
710 | - for token in sentence_tokens: | |
711 | - if token['argument'] and not ignore: | |
712 | - orths = [tok['orth'] for tok in sentence_tokens[token['argument_start']:token['argument_end']+1] if tok['argument']] | |
713 | - arg_realization = u'%s (%s)' % (u' '.join(orths), token['argument']) | |
714 | - endpoint = token['argument_end'] | |
715 | - sentence_chunks.append(arg_realization) | |
716 | - ignore = True | |
717 | - if token['idx'] == endpoint: | |
718 | - ignore = False | |
719 | - return u' '.join(sentence_chunks) | |
720 | - | |
721 | -def get_sentence_chunk(arguments, sentence_tokens): | |
722 | - for arg in arguments: | |
723 | - mark_arg_in_sentence(arg, sentence_tokens) | |
724 | - return cut_sentence_chunks(sentence_tokens) | |
725 | - | |
726 | -def create_lemma_argument(lemma_entry, frame_text_rep): | |
727 | - frame_parts = frame_text_rep.split(':') | |
728 | - sie = frame_parts[0] | |
729 | - aspect = frame_parts[2] | |
730 | - frame_structure = frame_parts[3] | |
731 | - if not sie and u'refl' in frame_structure: | |
732 | - sie = u'się' | |
733 | - argument = u'lemma(%s,%s,%s)' % (lemma_entry, sie, aspect) | |
734 | - return argument | |
735 | - | |
736 | -def get_arguments_coverage(): | |
737 | - try: | |
738 | - first_line = True | |
65 | +def write_examples(statuses): | |
66 | + try: | |
739 | 67 | examples_file = codecs.open(os.path.join(BASE_PATH, |
740 | - 'detailed_examples_v2.csv'), 'rt', 'utf-8') | |
741 | - output_file = codecs.open(os.path.join(BASE_PATH, | |
742 | - 'detailed_examples_cover_v2.csv'), 'wt', 'utf-8') | |
743 | - output_file.write(u'%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % LABELS) | |
744 | - for line in examples_file: | |
745 | - if first_line: | |
746 | - first_line = False | |
747 | - continue | |
748 | - if 'Error!!!' in line: | |
749 | - continue | |
750 | - line = line.strip() | |
751 | - example_data = line.split('\t') | |
752 | - lemma_entry = example_data[0] | |
753 | - lemma_status = example_data[1] | |
754 | - frame_text_rep = example_data[2] | |
755 | - frame_opinion = example_data[3] | |
756 | - sentence = example_data[4] | |
757 | - tagged_sentence = example_data[5] | |
758 | - example_opinion = example_data[6] | |
759 | - example_source = example_data[7] | |
760 | - arguments_selection = example_data[8] | |
761 | - if not tagged_sentence: | |
762 | - sentence_chunk = u'Error!!! Błąd tagowania.' | |
763 | - else: | |
764 | -# print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
765 | -# print sentence | |
766 | - lemma_argument = create_lemma_argument(lemma_entry, frame_text_rep) | |
767 | - arguments = [lemma_argument] | |
768 | - arguments.extend(get_arguments(arguments_selection)) | |
769 | - sentence_tokens = tokenize_sentence(tagged_sentence) | |
770 | - try: | |
771 | - sentence_chunk = get_sentence_chunk(arguments, sentence_tokens) | |
772 | - except: | |
773 | - sentence_chunk = u'Error!!! Nie dopasowano wszystkich argumentów.' | |
774 | - output_file.write(u'%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % (lemma_entry, | |
775 | - lemma_status, | |
776 | - frame_text_rep, | |
777 | - frame_opinion, | |
778 | - sentence, | |
779 | - tagged_sentence, | |
780 | - sentence_chunk, | |
781 | - example_opinion, | |
782 | - example_source, | |
783 | - arguments_selection)) | |
68 | + 'examples_gotowe_plus.txt'), 'wt', 'utf-8') | |
69 | + for lemma in Lemma.objects.filter(old=False).filter(status__in=statuses).order_by('entry').all(): | |
70 | + print lemma | |
71 | + examples_file.write(lemma.entry+'\n') | |
72 | + for frame in lemma.frames.order_by('text_rep').all(): | |
73 | + if lemma.frame_opinions.get(frame=frame).value.value != u'zła': | |
74 | + examples_file.write('\t%s\n' % frame.text_rep) | |
75 | + for example in lemma.nkjp_examples.filter(frame=frame): | |
76 | + examples_file.write('\t\t--> %s\n' % example.sentence) | |
77 | + examples_file.write('\n\n') | |
784 | 78 | finally: |
785 | - examples_file.close() | |
786 | - output_file.close() | |
787 | - | |
788 | -def get_examples(): | |
789 | - q_statuses = [] | |
790 | - for status in STATUSES_LS: | |
791 | - q_statuses.append(Q(status__status=status)) | |
792 | - write_detailed_examples(q_statuses) | |
793 | -# write_examples(q_statuses) | |
794 | -# get_arguments_coverage() | |
795 | - | |
796 | 79 | \ No newline at end of file |
80 | + examples_file.close() | |
... | ... |
dictionary/models.py
dictionary/static/js/lemma-view.js
... | ... | @@ -68,7 +68,7 @@ var nkjp_source_tab = ax_nkjp_source_vals; |
68 | 68 | var lemma_entry = ''; |
69 | 69 | var prev_lemma_entry = ''; |
70 | 70 | var selected_notes_row_id = -1; |
71 | - var can_modify = false; | |
71 | + //var can_modify = false; | |
72 | 72 | |
73 | 73 | //////////////////////////////////////////////////////////////// |
74 | 74 | |
... | ... | @@ -402,7 +402,6 @@ function draw_frames_filter(id) |
402 | 402 | |
403 | 403 | |
404 | 404 | function load_content(id) { |
405 | - ShowProgressAnimation(); | |
406 | 405 | $('#add-table-elem-dialog').dialog('close'); |
407 | 406 | if(lemma_id != id) |
408 | 407 | $('#ready-note-dialog').dialog('close'); |
... | ... | @@ -410,15 +409,17 @@ function load_content(id) { |
410 | 409 | |
411 | 410 | if(window.activeLemmaPanel == 'preview_lemma') |
412 | 411 | { |
412 | + ShowProgressAnimation(); | |
413 | 413 | $('#preview_lemma').load(ajax_lemma_preview, 'id='+id+'&main_lemma_id='+window.lemma_id, function(){ |
414 | 414 | window.prev_lemma_id=id; |
415 | + loadPrevSchemataAndExamples(); | |
415 | 416 | createSplitter('prevFramesSplit', 'prev-lemma-tables', 'prev_tabs'); |
416 | 417 | areNewPreviewEntriesRelated(); |
417 | - HideProgressAnimation(); | |
418 | 418 | }); |
419 | 419 | } |
420 | 420 | else |
421 | 421 | { |
422 | + ShowProgressAnimation(); | |
422 | 423 | // czyszczenie wartosci |
423 | 424 | window.elem_in_bucket = ''; |
424 | 425 | window.selected_notes_row_id = -1; |
... | ... | @@ -446,10 +447,13 @@ function load_content(id) { |
446 | 447 | window.notesNotSaved = false; |
447 | 448 | window.lemmaExNotSaved = false; |
448 | 449 | |
449 | - $('#new_frames').load(ajax_new_frames, 'id='+id, function(){ | |
450 | + $('#new_frames').load(ajax_new_frames, 'id='+id, function(data){ | |
450 | 451 | window.lemma_id = id; |
452 | + | |
453 | + loadSchemataAndExamples(); | |
454 | + | |
451 | 455 | createSplitter('framesSplit','new-frame-tables', 'tabs'); |
452 | - if(window.can_modify) | |
456 | + /*if(window.can_modify) | |
453 | 457 | { |
454 | 458 | addSyntacticFramesPerm = user_has_perm('dictionary.add_syntactic_frames'); |
455 | 459 | addPhraseologicFramesPerm = user_has_perm('dictionary.add_phraseologic_frames'); |
... | ... | @@ -464,15 +468,7 @@ function load_content(id) { |
464 | 468 | $(document).bind('keydown', 'shift+d', function(evt){duplicateElement(); return false; }); |
465 | 469 | $(document).bind('keydown', 'shift+c', function(evt){copyElement(); return false; }); |
466 | 470 | $(document).bind('keydown', 'shift+v', function(evt){pasteElement(); return false; }); |
467 | - $(document).bind('keydown', 'shift+w', function(evt){ | |
468 | - if(window.change) | |
469 | - { | |
470 | - error_alert('Przed walidacją/zmianą statusu hasło musi zostać zapisane.'); | |
471 | - return false; | |
472 | - } | |
473 | - validate_new_frames(false, false); | |
474 | - return false; | |
475 | - }); | |
471 | + $(document).bind('keydown', 'shift+w', function(evt){validateSchemata(); return false; }); | |
476 | 472 | if(addSyntacticFramesPerm) { |
477 | 473 | $(document).bind('keydown', 'shift+x', function(evt){cutElement(); return false; }); |
478 | 474 | $(document).bind('keydown', 'shift+m', function(evt){reserveLemma(); return false; }); |
... | ... | @@ -485,18 +481,14 @@ function load_content(id) { |
485 | 481 | } |
486 | 482 | else |
487 | 483 | { |
488 | - $(document).unbind('keydown') | |
484 | + $(document).unbind('keydown'); | |
489 | 485 | $.get(ajax_user_has_perm, {perm: 'dictionary.own_lemmas'}, function(result) { |
490 | 486 | if(result['has_perm']) { |
491 | 487 | $(document).bind('keydown', 'shift+m', function(evt){reserveLemma(); return false; }); |
492 | 488 | } |
493 | 489 | }); |
494 | - } | |
495 | - | |
496 | - window.frames_modif = new Array(); | |
497 | - window.frames_modif_idx = 0; | |
498 | - var lemma_version = new Lemma_Version(window.schemas, window.nkjp_examples, window.nkjp_lemma_examples); | |
499 | - frames_modif.push(lemma_version); | |
490 | + }*/ | |
491 | + | |
500 | 492 | if(document.getElementById("lemma_example_show")) |
501 | 493 | { |
502 | 494 | draw_nkjp_table(document.getElementById("lemma_example_show"), '', window.nkjp_lemma_examples, 'NkjpLemmaTableRow', 'nkjpLemma_') |
... | ... | @@ -506,20 +498,10 @@ function load_content(id) { |
506 | 498 | addPinnedExamplesDialog(); |
507 | 499 | $('#lemma_desc').load(ajax_get_lemma_desc, 'id='+id); |
508 | 500 | areNewPreviewEntriesRelated(); |
509 | - HideProgressAnimation(); | |
510 | 501 | refresh_example_propositions(); |
511 | 502 | }); |
512 | 503 | $('#change_ctrl').load(ajax_change_ctrl, 'id='+id); |
513 | 504 | $('#semantics').load(ajax_semantics, 'id='+id); |
514 | - $('#examples').load(ajax_lemma_examples, 'id='+id, function(){ | |
515 | - window.frames_modif = new Array(); // UWAGA, przestawic do lemma-view | |
516 | - window.frames_modif_idx = 0; | |
517 | - var lemma_version = new Lemma_Version(window.schemas, window.nkjp_examples, window.nkjp_lemma_examples); // TO | |
518 | - frames_modif.push(lemma_version); | |
519 | - draw_nkjp_table(document.getElementById("lemma_example_show"), '', window.nkjp_lemma_examples, 'NkjpLemmaTableRow', 'nkjpLemma_') | |
520 | - $("tr.NkjpLemmaTableRow").click(function(){ | |
521 | - selectLemmaNkjpTr(this.id)}); | |
522 | - }); | |
523 | 505 | $('#status').load(ajax_lemma_status, 'id='+id, function(){ |
524 | 506 | $("#lemma-status-change button").click(validate_and_change_status); |
525 | 507 | $('#ready-note-dialog').dialog({ autoOpen: false, |
... | ... | @@ -539,12 +521,72 @@ function load_content(id) { |
539 | 521 | |
540 | 522 | $('#preview_lemma').load(ajax_lemma_preview, 'id='+prevId+'&main_lemma_id='+id, function(){ |
541 | 523 | window.prev_lemma_id=prevId; |
524 | + loadPrevSchemataAndExamples(); | |
542 | 525 | createSplitter('prevFramesSplit', 'prev-lemma-tables', 'prev_tabs'); |
543 | 526 | areNewPreviewEntriesRelated(); |
544 | 527 | }); |
545 | 528 | } |
546 | 529 | } |
547 | 530 | |
531 | +function validateSchemata() { | |
532 | + if(window.change) { | |
533 | + error_alert('Przed walidacją/zmianą statusu hasło musi zostać zapisane.'); | |
534 | + return false; | |
535 | + } | |
536 | + validate_new_frames(false, false); | |
537 | +} | |
538 | + | |
539 | +function loadSchemataAndExamples() { | |
540 | + $.ajaxJSON({ | |
541 | + method: 'get', | |
542 | + url: ajax_get_schemata_and_examples, | |
543 | + data: { | |
544 | + lemma_id: window.lemma_id | |
545 | + }, | |
546 | + | |
547 | + callback: function(result) { | |
548 | + window.schemas = serializedObjToObj(result['schemata']); | |
549 | + window.nkjp_examples = serializedNkjpToObj(result['examples']); | |
550 | + window.nkjp_lemma_examples = serializedNkjpToObj(result['lemma_examples']); | |
551 | + resetLemmaVersions(); | |
552 | + var frame_class = 'InactiveFrameTable'; | |
553 | + if(result['can_modify']) { | |
554 | + frame_class = 'ActiveFrameTable'; | |
555 | + } | |
556 | + draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', | |
557 | + 'frame_filter', window.nkjp_examples, frame_class, | |
558 | + window.lemma_entry, window.lemma_entry); | |
559 | + $('#examples').load(ajax_lemma_examples, 'id='+window.lemma_id, function(){ | |
560 | + draw_nkjp_table(document.getElementById("lemma_example_show"), '', | |
561 | + window.nkjp_lemma_examples, 'NkjpLemmaTableRow', 'nkjpLemma_') | |
562 | + $("tr.NkjpLemmaTableRow").click(function(){selectLemmaNkjpTr(this.id)}); | |
563 | + HideProgressAnimation(); | |
564 | + }); | |
565 | + $("span#new-frames-count").empty(); | |
566 | + $("span#new-frames-count").append(window.schemas.length); | |
567 | + $("span#lemma-examples-count").empty(); | |
568 | + $("span#lemma-examples-count").append(window.nkjp_lemma_examples.length); | |
569 | + }, | |
570 | + }); | |
571 | +} | |
572 | + | |
573 | +function loadPrevSchemataAndExamples() { | |
574 | + $.ajaxJSON({ | |
575 | + method: 'get', | |
576 | + url: ajax_get_schemata_and_examples, | |
577 | + data: { | |
578 | + lemma_id: window.prev_lemma_id | |
579 | + }, | |
580 | + callback: function(result) { | |
581 | + window.prev_frames = serializedObjToObj(result['schemata']); | |
582 | + window.prev_nkjp_examples = serializedNkjpToObj(result['examples']); | |
583 | + draw_filtered_frames(window.prev_frames, 'prev-lemma-tables', 'prev-lemma-table', 'prev_frame_filter', | |
584 | + window.prev_nkjp_examples, 'InactiveFrameTable', window.prev_lemma_entry); | |
585 | + HideProgressAnimation(); | |
586 | + }, | |
587 | + }); | |
588 | +} | |
589 | + | |
548 | 590 | // klasa reprezentujaca wersje hasla, do cofania i dodawania |
549 | 591 | function Lemma_Version(schemas, nkjp_examples, nkjp_lemma_examples) |
550 | 592 | { |
... | ... | @@ -1074,9 +1116,11 @@ function remove_example_from_lemma(lemma_id, example_id, examplesTabId) { |
1074 | 1116 | function addFrameClickEvents(tableClass, tableId) { |
1075 | 1117 | selector = 'table.'+tableClass+'#'+tableId+' td'; |
1076 | 1118 | if(tableId === 'new-frame-table') { |
1077 | - $(selector).dblclick(function(e){ | |
1078 | - e.stopPropagation(); | |
1079 | - openEditForm(this.id)}); | |
1119 | + if(tableClass === 'ActiveFrameTable') { | |
1120 | + $(selector).dblclick(function(e){ | |
1121 | + e.stopPropagation(); | |
1122 | + openEditForm(this.id)}); | |
1123 | + } | |
1080 | 1124 | $(selector).click(function(e){ |
1081 | 1125 | e.stopPropagation(); |
1082 | 1126 | selectTd(this.id)}); |
... | ... | @@ -1526,11 +1570,7 @@ function can_add_position_category(lemma_id) { |
1526 | 1570 | } |
1527 | 1571 | |
1528 | 1572 | function openEditForm(id) { |
1529 | - if(window.can_modify && !checkIfSemChangedAndAlert()) { | |
1530 | - /*if(schemaGotAssignedSemantics(id)) { | |
1531 | - semanticsAssignedAlert(); | |
1532 | - }*/ | |
1533 | - | |
1573 | + if(!checkIfSemChangedAndAlert()) { | |
1534 | 1574 | editedFrameInstance = getFrameInstance(id, window.schemas); |
1535 | 1575 | elemInstance = getElementInstance(id, window.schemas); |
1536 | 1576 | addSyntacticFramesPerm = user_has_perm('dictionary.add_syntactic_frames'); |
... | ... |
dictionary/static/js/lemma_grid.js
... | ... | @@ -61,7 +61,6 @@ $(function(){ |
61 | 61 | window['remap']? remap : undefined}, |
62 | 62 | |
63 | 63 | gridComplete: function() { |
64 | - //grid.jqGrid('sortGrid', grid.jqGrid('getGridParam','sortname'), false, grid.jqGrid('getGridParam','sortorder')); | |
65 | 64 | var lemma_id = window.lemma_id; |
66 | 65 | var lastSelectedId = window.lastSelectedId; |
67 | 66 | if(window.activeLemmaPanel == 'preview_lemma') { |
... | ... |
dictionary/templates/lemma_preview.html
... | ... | @@ -8,17 +8,7 @@ |
8 | 8 | |
9 | 9 | frame_chars_str = '{{frame_char_list}}'; |
10 | 10 | frame_chars_str = convertHtml(frame_chars_str); |
11 | - window.frame_char_order = serializedObjToObj(frame_chars_str) | |
12 | - | |
13 | - serialized_text = '{{serialized_frames}}'; | |
14 | - serialized_text = convertHtml(serialized_text); | |
15 | - serialized_frames = serialized_text; | |
16 | - window.prev_frames = serializedObjToObj(serialized_frames); | |
17 | - | |
18 | - nkjp_examples_str = '{{nkjp_examples}}'; | |
19 | - nkjp_examples_str = convertHtml(nkjp_examples_str); | |
20 | - window.prev_nkjp_examples = serializedNkjpToObj(nkjp_examples_str); | |
21 | - | |
11 | + window.frame_char_order = serializedObjToObj(frame_chars_str); | |
22 | 12 | |
23 | 13 | function selectPrevNkjpTr(id) |
24 | 14 | { |
... | ... | @@ -265,7 +255,6 @@ $(document).ready(function() { |
265 | 255 | $('#prev_frame_filter #pred_filter').val(window.prev_filter_pred_val); |
266 | 256 | $('#prev_frame_filter #opinion_filter').val(window.prev_filter_opinion_val); |
267 | 257 | $('#prev_frame_filter #argument_filter').trigger('change'); |
268 | - }); | |
269 | - draw_filtered_prev_frames(); | |
258 | + }); | |
270 | 259 | }); |
271 | 260 | </script> |
... | ... |
dictionary/templates/new_frames.html
... | ... | @@ -6,31 +6,8 @@ |
6 | 6 | $('#add-table-elem-dialog').dialog({ autoOpen: false, |
7 | 7 | modal: 'true', |
8 | 8 | width: 400}); |
9 | - {% if can_modify %} | |
10 | - window.can_modify = true; | |
11 | - {% else %} | |
12 | - window.can_modify = false; | |
13 | - {% endif %} | |
14 | 9 | create_example_opinion_dialog(); |
15 | 10 | } |
16 | - | |
17 | - lemma_nkjp_examples_str = '{{lemma_nkjp_examples}}'; | |
18 | - lemma_nkjp_examples_str = convertHtml(lemma_nkjp_examples_str); | |
19 | - window.nkjp_lemma_examples = serializedNkjpToObj(lemma_nkjp_examples_str); | |
20 | - | |
21 | - serialized_text = '{{serialized_frames}}'; | |
22 | - serialized_text = convertHtml(serialized_text); | |
23 | - serialized_frames = serialized_text; | |
24 | - schemas = serializedObjToObj(serialized_frames); | |
25 | - | |
26 | - nkjp_examples_str = '{{nkjp_examples}}'; | |
27 | - nkjp_examples_str = convertHtml(nkjp_examples_str); | |
28 | - window.nkjp_examples = serializedNkjpToObj(nkjp_examples_str); | |
29 | - | |
30 | - $("span#new-frames-count").empty(); | |
31 | - $("span#new-frames-count").append(schemas.length); | |
32 | - $("span#lemma-examples-count").empty(); | |
33 | - $("span#lemma-examples-count").append(window.nkjp_lemma_examples.length); | |
34 | 11 | |
35 | 12 | function draw_filtered_new_frames() |
36 | 13 | { |
... | ... | @@ -103,15 +80,7 @@ |
103 | 80 | $("button#back").click(function(){backOneModification(); return false;}); |
104 | 81 | $("button#forward").click(function(){forwardOneModification(); return false;}); |
105 | 82 | $("button#save").click(function(){save_new_frames(); return false;}); |
106 | - $("button#validate").click(function(){ | |
107 | - if(window.change) | |
108 | - { | |
109 | - HideProgressAnimation(); | |
110 | - error_alert('Przed walidacją/zmianą statusu hasło musi zostać zapisane.'); | |
111 | - return false; | |
112 | - } | |
113 | - validate_new_frames(false, false); | |
114 | - }); | |
83 | + $("button#validate").click(function(){validateSchemata(); return false;}); | |
115 | 84 | |
116 | 85 | $("button#delete_example").click(function(){ |
117 | 86 | delete_nkjp_example(selected_example_id)}); |
... | ... | @@ -312,12 +281,35 @@ $(document).ready(function() { |
312 | 281 | $('#frame_filter #pred_filter').val(window.filter_pred_val); |
313 | 282 | $('#frame_filter #opinion_filter').val(window.filter_opinion_val); |
314 | 283 | $('#frame_filter #argument_filter').trigger('change'); |
315 | - }); | |
316 | - | |
317 | - frame_class = 'InactiveFrameTable'; | |
284 | + }); | |
285 | + | |
318 | 286 | {% if can_modify %} |
319 | - frame_class = 'ActiveFrameTable'; | |
287 | + {% if perms.dictionary.add_syntactic_frames or perms.dictionary.add_phraseologic_frames %} | |
288 | + $(document).unbind('keydown'); | |
289 | + $(document).bind('keydown', 'shift+s', saveHandle); | |
290 | + $(document).bind('keydown', 'shift+z', function(evt){backOneModification(); return false; }); | |
291 | + $(document).bind('keydown', 'shift+y', function(evt){forwardOneModification(); return false; }); | |
292 | + $(document).bind('keydown', 'shift+a', function(evt){addElement(); return false; }); | |
293 | + $(document).bind('keydown', 'shift+r', function(evt){removeElement(); return false; }); | |
294 | + $(document).bind('keydown', 'shift+d', function(evt){duplicateElement(); return false; }); | |
295 | + $(document).bind('keydown', 'shift+c', function(evt){copyElement(); return false; }); | |
296 | + $(document).bind('keydown', 'shift+v', function(evt){pasteElement(); return false; }); | |
297 | + $(document).bind('keydown', 'shift+w', function(evt){validateSchemata(); return false; }); | |
298 | + {% if perms.dictionary.add_syntactic_frames %} | |
299 | + $(document).bind('keydown', 'shift+x', function(evt){cutElement(); return false; }); | |
300 | + $(document).bind('keydown', 'shift+m', function(evt){reserveLemma(); return false; }); | |
301 | + {% endif %} | |
302 | + {% if perms.dictionary.add_phraseologic_frames %} | |
303 | + $(document).bind('keydown', 'shift+l', function(evt){addPhraseologicFrame(); return false; }); | |
304 | + $(document).bind('keydown', 'shift+b', function(evt){openAssignPhraseologicFrameDialog(); return false; }); | |
305 | + {% endif %} | |
306 | + {% endif %} | |
307 | + {% else %} | |
308 | + $(document).unbind('keydown'); | |
309 | + {% if perms.dictionary.own_lemmas %} | |
310 | + $(document).bind('keydown', 'shift+m', function(evt){reserveLemma(); return false; }); | |
311 | + {% endif %} | |
320 | 312 | {% endif %} |
321 | - draw_filtered_frames(window.schemas, 'new-frame-tables', 'new-frame-table', 'frame_filter', window.nkjp_examples, frame_class, window.lemma_entry, window.lemma_entry); | |
313 | + | |
322 | 314 | }); |
323 | 315 | </script> |
... | ... |
dictionary/views.py
... | ... | @@ -193,6 +193,7 @@ def lemma_view(request): |
193 | 193 | 'ajax_deselect_preview_tab': reverse('deselect_preview_tab'), |
194 | 194 | 'ajax_get_schemata': reverse('get_schemata'), |
195 | 195 | 'ajax_get_examples': reverse('get_examples'), |
196 | + 'ajax_get_schemata_and_examples': reverse('get_schemata_and_examples'), | |
196 | 197 | |
197 | 198 | # powiazywanie hasel (nieczasownikowe) |
198 | 199 | 'ajax_relate_entries' : reverse('relate_entries'), |
... | ... |
semantics/views.py
... | ... | @@ -76,7 +76,7 @@ def ajax_frames(request, lemma_id): |
76 | 76 | return context |
77 | 77 | |
78 | 78 | def create_frames_context(lemma_id): |
79 | - lemma = Lemma.objects.get(id=lemma_id, old=False) | |
79 | + lemma = Lemma.objects.get(id=lemma_id) | |
80 | 80 | |
81 | 81 | #lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ')|Q(base__contains=u' '+lemma.entry+u' ')|Q(base__endswith=u' '+lemma.entry)|Q(base=lemma.entry)).order_by('sense') |
82 | 82 | lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')).order_by('sense') |
... | ... | @@ -215,7 +215,7 @@ def ajax_units(request, lemma_id): |
215 | 215 | return context |
216 | 216 | |
217 | 217 | def create_units_context(lemma_id): |
218 | - lemma = Lemma.objects.get(id=lemma_id, old=False) | |
218 | + lemma = Lemma.objects.get(id=lemma_id) | |
219 | 219 | lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry, pos="czasownik")|Q(base = lemma.entry + u' się', pos="czasownik")).order_by('base', 'sense') |
220 | 220 | # lexical_units = LexicalUnit.objects.filter(Q(base__startswith=lemma.entry + u' ', pos="czasownik")|Q(base__contains=u' '+lemma.entry+u' ', pos="czasownik")|Q(base__endswith=u' '+lemma.entry, pos="czasownik")|Q(base=lemma.entry, pos="czasownik")).order_by('base', 'sense') |
221 | 221 | |
... | ... | @@ -329,7 +329,7 @@ def ajax_roles(request): |
329 | 329 | @ajax(method='get', encode_result=False) |
330 | 330 | def ajax_schemas(request, lemma_id): |
331 | 331 | |
332 | - lemma = Lemma.objects.get(id=lemma_id, old=False) | |
332 | + lemma = Lemma.objects.get(id=lemma_id).entry_obj.actual_lemma() | |
333 | 333 | |
334 | 334 | schemas_all = lemma.frames.all() |
335 | 335 | |
... | ... | @@ -412,7 +412,7 @@ def ajax_schemas(request, lemma_id): |
412 | 412 | @ajax(method='get', encode_result=False) |
413 | 413 | def ajax_examples(request, lemma_id): |
414 | 414 | |
415 | - lemma = Lemma.objects.get(id=lemma_id, old=False) | |
415 | + lemma = Lemma.objects.get(id=lemma_id).entry_obj.actual_lemma() | |
416 | 416 | nkjp_examples = lemma.nkjp_examples.all() |
417 | 417 | lexical_units = LexicalUnit.objects.filter(Q(base = lemma.entry)|Q(base = lemma.entry + u' się')) |
418 | 418 | |
... | ... |
urls.py
... | ... | @@ -123,6 +123,7 @@ urlpatterns += patterns('dictionary.ajax_lemma_view', |
123 | 123 | url(r'^ajax/deselect_preview_tab/$', 'deselect_preview_tab'), |
124 | 124 | url(r'^ajax/get_schemata/$', 'get_schemata'), |
125 | 125 | url(r'^ajax/get_examples/$', 'get_examples'), |
126 | + url(r'^ajax/get_schemata_and_examples/$', 'get_schemata_and_examples'), | |
126 | 127 | |
127 | 128 | # powiazywanie hasel (nieczasownikowe) |
128 | 129 | url(r'^ajax/relate_entries/$', 'relate_entries'), |
... | ... |