models.py 2.79 KB
from django.db import models

from examples.models import Example
from meanings.models import LexicalUnit
from semantics.models import Argument
from syntax.models import Position, Schema, Subentry
from syntax.models_phrase import PhraseType


class Entry(models.Model):
    name = models.CharField(max_length=32)
    pos = models.ForeignKey('POS', related_name='entries', on_delete=models.PROTECT)
    status = models.ForeignKey('Status', related_name='entries', on_delete=models.PROTECT)
    frequency_1M = models.PositiveIntegerField(default=0)
    frequency_300M = models.PositiveIntegerField(default=0)
    schemata_count = models.PositiveIntegerField(null=False, default=0)
    frames_count = models.PositiveIntegerField(null=False, default=0)
    lexical_units_count = models.PositiveIntegerField(null=False, default=0)

    class Meta:
        ordering = ['name']
        unique_together = ('name', 'pos',)

    def __str__(self):
        return '%s (%s)' % (self.name, self.pos)


class POS(models.Model):
    tag = models.CharField(max_length=16, unique=True)
    # name = TODO: wymaga lokalizacji

    class Meta:
        ordering = ['tag']

    def __str__(self):
        return self.tag


class Status(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 ExampleConnection(models.Model):
    example = models.ForeignKey(Example, related_name='example_connections', on_delete=models.PROTECT)
    lexical_unit = models.ForeignKey(LexicalUnit, related_name='example_connections', null=True, on_delete=models.PROTECT)
    arguments = models.ManyToManyField(Argument, related_name='example_connections')
    schema_connections = models.ManyToManyField('SchemaHook', related_name='example_connections')


class SchemaHook(models.Model):
    subentry = models.ForeignKey(Subentry, related_name='schema_hooks', on_delete=models.PROTECT)
    schema = models.ForeignKey(Schema, related_name='schema_hooks', on_delete=models.PROTECT)
    position = models.ForeignKey(Position, related_name='schema_hooks', on_delete=models.PROTECT)
    phrase_type = models.ForeignKey(PhraseType, related_name='schema_hooks', on_delete=models.PROTECT)
    alternation = models.IntegerField(default=1)

    def __str__(self):
        return 'sub_%d_sch_%d_pos_%d_pt_%d_alt_%d_' % (self.subentry.id, self.schema.id, self.position.id,
                                                       self.phrase_type.id, self.alternation)


class ArgumentConnection(models.Model):
    argument = models.ForeignKey(Argument, related_name='argument_connections', on_delete=models.PROTECT)
    schema_connections = models.ManyToManyField('SchemaHook', related_name='argument_connections')