fix_homonym.py
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#-*- coding:utf-8 -*-
from django.core.management.base import BaseCommand
from django.db.models import Count
from common.util import no_history
from dictionary.models import Lexeme
MORFEUSZ_LETTERS = {
'v': ['v', 'pred'],
's': ['subst', 'osc', 'skrs'],
'a': ['adj'],
'd': ['adv', 'advndm'],
'n': ['num'],
'b': ['fraz'],
'q': ['part'],
'i': ['interj'],
'o': ['ppron'],
'p': ['prep'],
'c': ['comp'],
'j': ['conj'],
}
class Command(BaseCommand):
args = 'none'
help = 'fixes homonym numbers'
def handle(self, **options):
fix_homonym()
def fix_homonym():
no_history()
homonyms = (
Lexeme.objects.values('entry', 'part_of_speech')
.annotate(count=Count('pk')).filter(count__gt=1))
for homonym in homonyms:
lexemes = Lexeme.objects.filter(
entry=homonym['entry'],
part_of_speech=homonym['part_of_speech']).order_by('pk')
for i, lexeme in enumerate(lexemes, 1):
lexeme.homonym_number = i
lexeme.save()