connect_noun_lexical_units.py 751 Bytes
#! /usr/bin/python
# -*- coding: utf-8 -*-

import sys, os, codecs

from django.core.management.base import BaseCommand

from dictionary.models import Entry, POS
from wordnet.models import LexicalUnit
from settings import PROJECT_PATH

class Command(BaseCommand):
    args = 'none'
    help = ''

    def handle(self, **options):
        connect_nouns()

def connect_nouns():
    noun = POS.objects.get(tag='noun')
    entries = Entry.objects.filter(pos=noun)
    for entry in entries:
        lus = LexicalUnit.objects.filter(base=entry.name, pos=u'rzeczownik')
        for lu in lus:
            if lu.entry is None:
                print lu.base, lu.sense
                lu.entry = entry
                lu.save()