models.py 2.38 KB
from django.db import models


class Synset(models.Model):
    id = models.IntegerField(primary_key=True)

    def __unicode__(self):
        text_rep = u''
        units_in_synset = LexicalUnit.objects.filter(synset__id=self.id)
        if units_in_synset.exists():
            first_lex_unit = units_in_synset.order_by('luid')[0]
            text_rep = unicode(first_lex_unit)
        return text_rep


class LexicalUnit(models.Model):
    # identyfikator ze Slowosieci
    luid = models.IntegerField(primary_key=True)
    # podstawa jednostki leksykalnej
    base = models.CharField(max_length=150)
    # numer znaczenia
    sense = models.CharField(max_length=5)
    # czesc mowy
    pos = models.CharField(max_length=20)
    # wskaznik do synsetu
    synset = models.ForeignKey(Synset, null=True, related_name='lus')
    # definicja
    definition = models.TextField(default="")

    def __unicode__(self):
        return u'%s-%s' % (self.base, self.sense)

    class Meta:
        unique_together = ('base', 'sense', 'pos',)


class Relation(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=80)
    parent = models.ForeignKey('Relation', null=True, related_name='child')

    def __unicode__(self):
        text_rep = u'%s' % self.name
        if self.parent:
            text_rep = u'%s --> %s' % (unicode(self.parent), self.name)
        return text_rep


class SynsetLink(models.Model):
    relation = models.ForeignKey(Relation, related_name='synset_links')
    parent = models.ForeignKey(Synset, related_name='sources')
    child = models.ForeignKey(Synset, related_name='targets')

    def __unicode__(self):
        return u'%s --%s--> %s' % (unicode(self.child),
                                   unicode(self.relation),
                                   unicode(self.parent))

    class Meta:
        unique_together = ('parent', 'child', 'relation')


class LexicalUnitLink(models.Model):
    relation = models.ForeignKey(Relation, related_name='lu_links')
    parent = models.ForeignKey(LexicalUnit, related_name='sources')
    child = models.ForeignKey(LexicalUnit, related_name='targets')

    def __unicode__(self):
        return u'%s --%s--> %s' % (unicode(self.child),
                                   unicode(self.relation),
                                   unicode(self.parent))

    class Meta:
        unique_together = ('parent', 'child', 'relation')