Commit 9cc75e4c43555c9ffce32daddb1ca426f3349d7c

Authored by janek37
1 parent 1c9e4979

poprawione proponowanie automatycznych derywatów (adjnie)

dictionary/ajax_lexeme_view.py
... ... @@ -418,11 +418,11 @@ def update_lexeme(request, form_data):
418 418 if new_lexeme:
419 419 insert_new_lexeme(l, request)
420 420 computed_derivatives = lexeme_derivatives(l)
421   - crs = l.refs_to.values_list(
422   - 'to_lexeme__entry', 'to_lexeme__part_of_speech_id')
  421 + crs = l.refs_to.values_list('to_lexeme__entry', 'type__symbol')
423 422 cr_set = set(tuple(cr) for cr in crs)
424 423 needed_derivatives = [
425   - d for d in computed_derivatives if (d['entry'], d['pos']) not in cr_set]
  424 + d for d in computed_derivatives
  425 + if (d['entry'], d['cr_type']) not in cr_set]
426 426 return {'derivatives': needed_derivatives}
427 427  
428 428  
... ... @@ -434,20 +434,21 @@ def create_derivatives(request, lexeme_id, chosen_derivatives):
434 434 new_derivatives = {}
435 435 for der_data in chosen_derivatives:
436 436 pos = der_data['pos']
  437 + cr_type = der_data['cr_type']
437 438 entry = der_data['entry']
438 439 if entry == '':
439 440 raise AjaxError(_(u'Nie wpisano hasła'))
440 441 new_lexemes = create_derivative(
441   - lexeme, pos, entry, pl=der_data.get('pl'),
  442 + lexeme, pos, cr_type, entry, pl=der_data.get('pl'),
442 443 index=der_data['index'])
443 444 for der in new_lexemes:
444 445 insert_new_lexeme(der, request)
445   - new_derivatives[pos] = new_lexemes
446   - chosen_poses = [der_data['pos'] for der_data in chosen_derivatives]
  446 + new_derivatives[cr_type] = new_lexemes
  447 + chosen_types = [der_data['cr_type'] for der_data in chosen_derivatives]
447 448 if lexeme.part_of_speech_id == 'adj':
448   - if 'adv' in chosen_poses and 'advcom' in chosen_poses:
449   - adv = new_derivatives['adv'][0]
450   - advcom = new_derivatives['advcom'][0]
  449 + if 'adjadv' in chosen_types and 'adjadvc' in chosen_types:
  450 + adv = new_derivatives['adjadv'][0]
  451 + advcom = new_derivatives['adjadvc'][0]
451 452 adv.add_cross_reference(advcom, 'advcom')
452 453 advcom.add_cross_reference(adv, 'comadv')
453 454 return {}
... ...
dictionary/auto_derivatives.py
1 1 # -*- coding: utf-8 -*-
2 2 from django.db.models import Max
3 3 from dictionary.models import Ending, Lexeme, LexemeInflectionPattern, \
4   - Pattern, Gender, LexemeAttributeValue
  4 + Pattern, Gender, LexemeAttributeValue, LexemeAttribute
5 5  
6 6 VOWELS = u'aeiouyąęó'
7 7  
  8 +ADJ_POS = ('ppas', 'appas', 'pact', 'adjcom', 'nieadj')
  9 +
8 10 Ppact = Pattern.objects.get(name='P2') # hardcoded pattern
9 11 Pppas_ty = Pattern.objects.get(name='P4t')
10 12 Pppas_ny_ni = Pattern.objects.get(name='P4')
... ... @@ -17,23 +19,25 @@ Pcom = Pattern.objects.get(name='P4zs')
17 19 Pndm = Pattern.objects.get(name='ndm')
18 20 n2 = Gender.objects.get(symbol='n2')
19 21 f = Gender.objects.get(symbol='f')
  22 +ATTR_POPRZ = LexemeAttribute.objects.get(name=u'forma poprz.')
  23 +ATTR_ZLOZ = LexemeAttribute.objects.get(name=u'forma złoż.')
20 24 NO_POPRZ = LexemeAttributeValue.objects.get(
21 25 value=u'nieobecna', attribute__name=u'forma poprz.')
22 26 NO_ZLOZ = LexemeAttributeValue.objects.get(
23 27 value=u'nieobecna', attribute__name=u'forma złoż.')
24 28  
25 29 CR_TYPES = {
26   - 'pact': ('verpact', 'pactver'),
27   - 'ppas': ('verppas', 'ppasver'),
28   - 'appas': ('verppas', 'ppasver'),
29   - 'ger': ('verger', 'gerver'),
30   - 'osc': ('adjosc', 'oscadj'),
31   - 'adv': ('adjadv', 'advadj'),
32   - 'advcom': ('adjadvc', 'advcadj'),
  30 + 'verpact': ('verpact', 'pactver'),
  31 + 'verppas': ('verppas', 'ppasver'),
  32 + # 'verappas': ('verppas', 'ppasver'),
  33 + 'verger': ('verger', 'gerver'),
  34 + 'adjosc': ('adjosc', 'oscadj'),
  35 + 'adjadv': ('adjadv', 'advadj'),
  36 + 'adjadvc': ('adjadvc', 'advcadj'),
33 37 'adjcom': ('adjcom', 'comadj'),
34   - 'nieadj': ('adjnie', 'nieadj'),
35   - 'nieadv': ('adjnie', 'nieadj'),
36   - 'nieosc': ('adjnie', 'nieadj'),
  38 + 'adjnie': ('adjnie', 'nieadj'),
  39 + 'advnie': ('adjnie', 'nieadj'),
  40 + 'oscnie': ('adjnie', 'nieadj'),
37 41 }
38 42  
39 43  
... ... @@ -48,6 +52,7 @@ def ppas_data(lips, pos='ppas'):
48 52 for ending12 in endings12:
49 53 yield {
50 54 'pos': pos,
  55 + 'cr_type': 'verppas',
51 56 'entry': lip.root + ending.string + 'y',
52 57 'pl': lip.root + ending12.string,
53 58 'index': lip.index,
... ... @@ -62,6 +67,7 @@ def pact_data(lips):
62 67 for ending in endings3:
63 68 yield {
64 69 'pos': 'pact',
  70 + 'cr_type': 'verpact',
65 71 'entry': lip.root + ending.string + 'cy',
66 72 'index': lip.index,
67 73 }
... ... @@ -75,6 +81,7 @@ def ger_data(lips):
75 81 for ending in endings11:
76 82 yield {
77 83 'pos': 'ger',
  84 + 'cr_type': 'verger',
78 85 'entry': lip.root + ending.string + 'ie',
79 86 'index': lip.index,
80 87 }
... ... @@ -131,33 +138,37 @@ def lexeme_derivatives(lexeme):
131 138 yield data
132 139 elif lexeme.part_of_speech.symbol == 'adj':
133 140 # adjcom, adv, advcom, osc, nieadj
134   - for pos in ('adjcom', 'adv', 'advcom'):
  141 + pos_types = (
  142 + ('adjcom', 'adjcom'),
  143 + ('adv', 'adjadv'),
  144 + ('advcom', 'adjadvc')
  145 + )
  146 + for pos, cr_type in pos_types:
135 147 yield {
136 148 'pos': pos,
  149 + 'cr_type': cr_type,
137 150 'entry': None,
138 151 'index': 1,
139 152 }
140 153 yield {
141 154 'pos': 'osc',
  155 + 'cr_type': 'adjosc',
142 156 'entry': guess_osc(lexeme.entry),
143 157 'index': 1,
144 158 }
145 159 yield {
146   - 'pos': 'nieadj',
  160 + 'pos': 'adj',
  161 + 'cr_type': 'adjnie',
147 162 'entry': make_negation(lexeme.entry),
148 163 'index': 1,
149 164 }
150 165  
151 166  
152   -def create_derivative(lexeme, part_of_speech, entry, index, pl=None):
153   - negation = part_of_speech.startswith('nie')
154   - if negation:
155   - pos = part_of_speech[3:]
156   - else:
157   - pos = part_of_speech
  167 +def create_derivative(lexeme, part_of_speech, cr_type, entry, index, pl=None):
  168 + negation = cr_type.endswith('nie')
158 169 next_id = Lexeme.all_objects.aggregate(Max('id'))['id__max'] + 1
159 170 der = Lexeme.objects.create(
160   - id=next_id, entry=entry, part_of_speech_id=pos,
  171 + id=next_id, entry=entry, part_of_speech_id=part_of_speech,
161 172 status=lexeme.status, owner_vocabulary_id=lexeme.owner_vocabulary_id,
162 173 specialist=lexeme.specialist,
163 174 borrowing_source_id=lexeme.borrowing_source_id)
... ... @@ -211,18 +222,20 @@ def create_derivative(lexeme, part_of_speech, entry, index, pl=None):
211 222 for q in orig_lip.qualifiers.all():
212 223 lip.qualifiers.add(q)
213 224 for attr, attr_val in lexeme.attributes_values():
214   - if attr_val and attr.parts_of_speech.filter(symbol=part_of_speech):
  225 + if attr not in (ATTR_POPRZ, ATTR_ZLOZ) and attr_val \
  226 + and attr.parts_of_speech.filter(symbol=part_of_speech):
215 227 attr_val.add_lexeme(der)
216 228 if part_of_speech in ('ppas', 'appas', 'pact', 'adjcom', 'nieadj'):
217 229 NO_POPRZ.add_lexeme(der)
218 230 NO_ZLOZ.add_lexeme(der)
219 231 for q in lexeme.qualifiers.all():
220 232 der.qualifiers.add(q)
221   - cr_to, cr_from = CR_TYPES[part_of_speech]
  233 + cr_to, cr_from = CR_TYPES[cr_type]
222 234 lexeme.add_cross_reference(der, cr_to)
223 235 der.add_cross_reference(lexeme, cr_from)
224 236 new_lexemes = [der]
225   - if part_of_speech in ('osc', 'adv'):
  237 + if cr_type in ('adjosc', 'adjadv'):
226 238 new_lexemes.extend(create_derivative(
227   - der, 'nie' + part_of_speech, make_negation(entry), index))
228   - return new_lexemes
229 239 \ No newline at end of file
  240 + der, part_of_speech, part_of_speech + 'nie', make_negation(entry),
  241 + index))
  242 + return new_lexemes
... ...
dictionary/static/js/lexeme-edit.js
... ... @@ -432,11 +432,11 @@ $.extend(edit, {
432 432 var label = $('<label/>').attr('for', name);
433 433 li.append(input).append(label).appendTo(ul);
434 434 if (der_data.entry) {
435   - label.text(der_data.pos + ', ' + der_data.entry);
  435 + label.text(der_data.cr_type + ', ' + der_data.entry);
436 436 } else {
437 437 var der_input = $('<input/>').attr('type', 'text')
438 438 .addClass('derivative-input');
439   - label.text(der_data.pos + ', ');
  439 + label.text(der_data.cr_type + ', ');
440 440 li.append(der_input);
441 441 }
442 442 });
... ...