models.py 2.46 KB
from django.db import models

from meanings.models import LexicalUnit, Synset


class Frame(models.Model):  # TODO: jak wspoldzielic ramy?
    entry = models.ForeignKey('connections.Entry', related_name='frames', on_delete=models.PROTECT)
    lexical_units = models.ManyToManyField(LexicalUnit, related_name='frames')
    arguments = models.ManyToManyField('Argument')
    opinion = models.ForeignKey('FrameOpinion', on_delete=models.PROTECT)

    def sorted_arguments(self):  # TODO: zaimplementowac wlasciwe sortowanie
        return self.arguments.all()

    def __str__(self):
        return '%s: %s' % (self.opinion, ' + '.join([str(arg) for arg in self.sorted_arguments()]))


class FrameOpinion(models.Model):
    key = models.CharField(max_length=16, unique=True)
    # name = TODO wymaga lokalizacji
    priority = models.PositiveIntegerField()

    class Meta:
        ordering = ['priority']

    def __str__(self):
        return self.key


class Argument(models.Model):
    roles = models.ManyToManyField('SemanticRole')
    selective_preference = models.ForeignKey('SelectivePreference', on_delete=models.PROTECT)

    def __str__(self):
        return str(self.roles.all())


class SemanticRole(models.Model):
    role = models.CharField(max_length=20)
    color = models.CharField(max_length=11)
    gradient = models.CharField(max_length=10)
    priority = models.PositiveIntegerField()

    class Meta:
        ordering = ['priority']

    def __str__(self):
        return self.role


class SelectivePreference(models.Model):
    generals = models.ManyToManyField('GeneralSelectivePreference')
    synsets = models.ManyToManyField(Synset)
    relations = models.ManyToManyField('RelationalSelectivePreference')


class GeneralSelectivePreference(models.Model):
    key = models.CharField(max_length=20, unique=True)
    # name = TODO: wymaga lokalizacji
    members = models.ForeignKey('SelectivePreference', on_delete=models.PROTECT)

    def __str__(self):
        return self.key


class RelationalSelectivePreference(models.Model):
    relation = models.ForeignKey('SelectivePreferenceRelation', on_delete=models.PROTECT)
    to = models.ForeignKey('Argument', on_delete=models.PROTECT)

    def __str__(self):
        return '%s -> %s' % (self.relation, self.to)


class SelectivePreferenceRelation(models.Model):
    key = models.CharField(max_length=40, unique=True)
    # name = TODO: wymaga lokalizacji
    plwn_id = models.IntegerField(null=True)

    def __str__(self):
        return self.key