models.py 2.93 KB
from django.db import models

from meanings.models import LexicalUnit, Synset


class Frame(models.Model):
    lexical_units = models.ManyToManyField(LexicalUnit, related_name='frames')
    opinion = models.ForeignKey('FrameOpinion', on_delete=models.PROTECT)
    arguments_count = models.PositiveIntegerField(null=False, default=0)

    def sorted_arguments(self):  # TODO: zaimplementowac wlasciwe sortowanie
        return Argument.objects.filter(frame=self)

    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):
    role = models.ForeignKey('ArgumentRole', on_delete=models.PROTECT)
    predefined = models.ManyToManyField('PredefinedSelectionalPreference')
    synsets = models.ManyToManyField(Synset)
    relations = models.ManyToManyField('RelationalSelectionalPreference')
    frame = models.ForeignKey(Frame, on_delete=models.PROTECT)
    prferences_count = models.PositiveIntegerField(null=False, default=0)

    def __str__(self):
        return str(self.role)

class ArgumentRole(models.Model):
    role = models.ForeignKey('SemanticRole', on_delete=models.PROTECT)
    attribute = models.ForeignKey('RoleAttribute', null=True, on_delete=models.PROTECT)

    def __str__(self):
        if self.attribute is None:
            return str(self.role)
        else:
            return str(self.role) + " " + str(self.attribute)
    
class SemanticRole(models.Model):
    role = models.CharField(max_length=20)
    color = models.CharField(max_length=11, null=True)
    priority = models.PositiveIntegerField()

    class Meta:
        ordering = ['priority']

    def __str__(self):
        return self.role

class RoleAttribute(models.Model):
    attribute = models.CharField(max_length=20)
    gradient = models.CharField(max_length=10, null=True)
    priority = models.PositiveIntegerField()

    class Meta:
        ordering = ['priority']

    def __str__(self):
        return self.attribute

class PredefinedSelectionalPreference(models.Model):
    key = models.CharField(max_length=20, unique=True)
    # name = TODO: wymaga lokalizacji

    def __str__(self):
        return self.key


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

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


class SelectionalPreferenceRelation(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