Commit 3a22a50cfa786dbed6e285c2b7251434d9596e1d
1 parent
517e0a7e
Added find_hanging_examples and find_hanging_connections scripts.
Showing
3 changed files
with
76 additions
and
5 deletions
dictionary/ajax_lemma_view.py
... | ... | @@ -2496,16 +2496,18 @@ def save_new_frames(request, data, id, examples, lemma_examples): |
2496 | 2496 | for argument in arg_selection['arguments']: |
2497 | 2497 | try: |
2498 | 2498 | arg_obj = jsArgToObj(argument) |
2499 | - argument_objs.append(arg_obj) | |
2500 | - if len(nkjp_arg_sel_query.all()) > 0: # Q objectem to zalatwic | |
2501 | - nkjp_arg_sel_query = nkjp_arg_sel_query.filter(arguments=arg_obj) | |
2499 | + if arg_obj not in argument_objs: | |
2500 | + argument_objs.append(arg_obj) | |
2501 | + if len(nkjp_arg_sel_query.all()) > 0: # Q objectem to zalatwic | |
2502 | + nkjp_arg_sel_query = nkjp_arg_sel_query.filter(arguments=arg_obj) | |
2502 | 2503 | except TypeError: |
2503 | 2504 | pass |
2504 | - | |
2505 | + | |
2506 | + | |
2505 | 2507 | nkjp_arg_sel_obj = None |
2506 | 2508 | if len(nkjp_arg_sel_query.all()) > 0: |
2507 | 2509 | for nkjp_arg_sel in nkjp_arg_sel_query.all(): |
2508 | - if len(nkjp_arg_sel.arguments.all()) == len(argument_objs): | |
2510 | + if len(nkjp_arg_sel.arguments.all()) == len(argument_objs): # zrobic list(set(argument_objs)) | |
2509 | 2511 | nkjp_arg_sel_obj = nkjp_arg_sel |
2510 | 2512 | break |
2511 | 2513 | if not nkjp_arg_sel_obj: |
... | ... |
semantics/management/commands/find_hanging_connections.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +import datetime | |
4 | + | |
5 | +from django.core.management.base import BaseCommand | |
6 | + | |
7 | +from dictionary.models import Lemma | |
8 | + | |
9 | +class Command(BaseCommand): | |
10 | + args = 'none' | |
11 | + help = "" | |
12 | + | |
13 | + def handle(self, **options): | |
14 | + find_hanging_connections() | |
15 | + | |
16 | +def find_hanging_connections(): | |
17 | + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') | |
18 | + for lemma in lemmas: | |
19 | + frames = lemma.entry_obj.actual_frames() | |
20 | + for frame in frames: | |
21 | + for compl in frame.complements.all(): | |
22 | + for real in compl.realizations.all(): | |
23 | + match = False | |
24 | + matching_schemata = lemma.frames.filter(id=real.frame.id).all() | |
25 | + for schema in matching_schemata: | |
26 | + matching_poss = schema.positions.filter(id=real.position.id, | |
27 | + arguments=real.argument) | |
28 | + if matching_poss.exists(): | |
29 | + match = True | |
30 | + break | |
31 | + if not match: | |
32 | + compl_ref = 'frame_%d_comp_%d_' % (frame.id, compl.id) | |
33 | + print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
34 | + print 'lemma: %s\tcomplement: %s\trealization: %s' % (lemma.entry_obj.name, | |
35 | + compl_ref, | |
36 | + unicode(real)) | |
37 | + | |
0 | 38 | \ No newline at end of file |
... | ... |
semantics/management/commands/find_hanging_examples.py
0 → 100644
1 | +#-*- coding:utf-8 -*- | |
2 | + | |
3 | +from django.core.management.base import BaseCommand | |
4 | + | |
5 | +from dictionary.models import Lemma | |
6 | +from semantics.models import LexicalUnitExamples | |
7 | + | |
8 | +class Command(BaseCommand): | |
9 | + args = 'none' | |
10 | + help = "" | |
11 | + | |
12 | + def handle(self, **options): | |
13 | + find_hanging_examples() | |
14 | + | |
15 | +def find_hanging_examples(): | |
16 | + lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name') | |
17 | + for lemma in lemmas: | |
18 | + print_hanging_examples(lemma) | |
19 | + | |
20 | +def print_hanging_examples(lemma): | |
21 | + lex_units = lemma.entry_obj.lexical_units().all() | |
22 | + for lu in lex_units: | |
23 | + lu_examples = LexicalUnitExamples.objects.filter(lexical_unit=lu) | |
24 | + for lu_ex in lu_examples: | |
25 | + example = lu_ex.example | |
26 | + if not lemma.nkjp_examples.filter(id=example.id).exists(): | |
27 | + print '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
28 | + print 'lemma: %s\tlu_ex_id: %d\texample: %s\tex_id: %d' % (lemma.entry_obj.name, | |
29 | + lu_ex.id, | |
30 | + example.sentence, | |
31 | + example.id) | |
32 | + | |
0 | 33 | \ No newline at end of file |
... | ... |