verbs_wordnet.py 1.65 KB
#! /usr/bin/python
# -*- coding: utf-8 -*-

from django.core.management.base import BaseCommand

from django.core.exceptions import ObjectDoesNotExist
from dictionary.models import Entry, POS
from semantics.views import location
import codecs


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

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


def verbs_wordnet():
    with codecs.open('verbs_for_wordnet.txt', 'wt', 'utf-8') as outfile:
        verb = POS.objects.get(tag='verb')
        entries = Entry.objects.filter(pos=verb).order_by('name')
        for entry in entries:
            try:
                lemma = entry.actual_lemma()
                if lemma.status.priority == 100:
                    outfile.write(entry.name)
                    outfile.write('\n')
                    meanings = entry.meanings.filter(luid=-1)
                    if len(meanings) > 0:
                        for meaning in meanings:
                            outfile.write('\t')
                            outfile.write(meaning.base)
                            outfile.write('-')
                            outfile.write(meaning.sense)
                            outfile.write('\t')
                            outfile.write('{')
                            outfile.write(meaning.glossa)
                            outfile.write('}')
                            outfile.write('\t')
                            outfile.write('{')
                            outfile.write(location(meaning))
                            outfile.write('}')
                            outfile.write('\n')
                    
            except ObjectDoesNotExist:
                continue