Commit 7562241c66d5a913407691fa22dc12270ad62ddf
1 parent
9e395812
ostatecznie poprawione kopiowanie aspektów
Showing
1 changed file
with
23 additions
and
19 deletions
dictionary/management/commands/import_data.py
... | ... | @@ -389,23 +389,28 @@ class ImportData(object): |
389 | 389 | from_lexeme_id=row['nrod'], to_lexeme_id=row['nrdo'], |
390 | 390 | type=cr_type) |
391 | 391 | |
392 | - def copy_aspects(self, lexeme_attrs): | |
393 | - aspect_vals = LexemeAttributeValue.objects.filter(attribute__name='aspekt') | |
394 | - aspect_avs = [] | |
395 | - control_set = set() | |
392 | + def copy_aspects(self): | |
393 | + aspect_vals = dict(LexemeAttributeValue.objects.filter( | |
394 | + attribute__name='aspekt').values_list('value', 'pk')) | |
395 | + if MINI_MODE: | |
396 | + result = self.sqlite_cursor.execute( | |
397 | + "select distinct nrdo, aspekt " | |
398 | + "from odsylacze o " | |
399 | + "join leksemy l on o.nrod = l.nr " | |
400 | + "where typods in ('verger', 'verppas', 'verpact') " | |
401 | + "and nrod in (%(subq)s) and nrdo in (%(subq)s)" | |
402 | + % {'subq': MINI_LEXEME_QUERY % 'nr'}, | |
403 | + [MINI_LEXEME_COUNT, MINI_LEXEME_COUNT]) | |
404 | + else: | |
405 | + result = self.sqlite_cursor.execute( | |
406 | + "select distinct nrdo, aspekt " | |
407 | + "from odsylacze o " | |
408 | + "join leksemy l on o.nrod = l.nr " | |
409 | + "where typods in ('verger', 'verppas', 'verpact')") | |
396 | 410 | # TODO zrobić zapytanie które weźmie gotowe dane z sqlite |
397 | - for lexeme_av in lexeme_attrs: | |
398 | - if lexeme_av.attribute_value in aspect_vals: | |
399 | - crs = CrossReference.objects.filter( | |
400 | - from_lexeme__id=lexeme_av.lexeme_id, | |
401 | - type__symbol__in=('verger', 'verppas', 'verpact')) | |
402 | - for cr in crs: | |
403 | - l = cr.to_lexeme | |
404 | - av = lexeme_av.attribute_value | |
405 | - if (l, av) not in control_set: | |
406 | - aspect_avs.append(LexemeAV(lexeme=l, attribute_value=av)) | |
407 | - control_set.add((l, av)) | |
408 | - bulk_create(LexemeAV, aspect_avs) | |
411 | + for row in result: | |
412 | + yield LexemeAV( | |
413 | + lexeme_id=row['nrdo'], attribute_value_id=aspect_vals[row['aspekt']]) | |
409 | 414 | |
410 | 415 | def import_pattern_types(self): |
411 | 416 | self.cache_lc_pos() |
... | ... | @@ -646,8 +651,7 @@ class ImportData(object): |
646 | 651 | q.lexeme_set.add(lexeme_id) #add |
647 | 652 | print 'attributes...' |
648 | 653 | bulk_create(LexemeAV, lexeme_attrs) |
649 | - return lexeme_attrs | |
650 | - lexeme_attrs = import_lexemes() | |
654 | + import_lexemes() | |
651 | 655 | def import_lips(): |
652 | 656 | print 'importing lexeme inflection patterns...' |
653 | 657 | lips, lip_quals = self.new_lexeme_inflection_patterns() |
... | ... | @@ -666,7 +670,7 @@ class ImportData(object): |
666 | 670 | print 'importing cross-references...' |
667 | 671 | bulk_create(CrossReference, self.new_cross_references()) |
668 | 672 | print 'copying aspect values to derived lexemes...' |
669 | - self.copy_aspects(lexeme_attrs) | |
673 | + bulk_create(LexemeAV, self.copy_aspects()) | |
670 | 674 | print 'importing variants...' |
671 | 675 | bulk_create(Variant, self.new_variants()) |
672 | 676 | print 'importing table templates...' |
... | ... |