Blame view

semantics/models.py 6.19 KB
Bartłomiej Nitoń authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# -*- coding: utf-8 -*-

from django.db import models

from dictionary.models import Argument, Frame, Position, NKJP_Example
from wordnet.models import LexicalUnit, Synset
from django.contrib.auth.models import User
from datetime import datetime

################################################
############### Semantic Walenty ###############
################################################

class SemanticRole(models.Model): # lista dostępnych ról semantycznych
        # słowna nazwa roli
    role = models.CharField(max_length=20)
        # kolor przypisany roli
    color = models.CharField(max_length=11, null=True)
        # kierunek gradientu
    gradient = models.CharField(max_length=10, null=True)

    def __unicode__(self):
        return '%s' % self.role 
Tomasz Bartosiak authored
24
25
26
27
28
29
30
31
32
33

class FrameOpinion(models.Model):
    value = models.CharField(max_length=16, unique=True)
    short = models.CharField(max_length=16, blank=True, null=True)
    # okresla kolejnosc prezentowania opinii
    priority = models.PositiveIntegerField(blank=True, null=True)

    def __unicode__(self):
      return '%s' % (self.value)
Bartłomiej Nitoń authored
34
35
36
37
38
39
40
41
42
43
44
class SemanticFrame(models.Model):
        # identyfikator ramki
    id = models.AutoField(primary_key=True)
        # jednostka leksykalna, dla której jest to ramka
    lexical_units = models.ManyToManyField(LexicalUnit, related_name='frames')
    # validation - LexicalUnit must have 'czasownik' in pos field ?
    complements = models.ManyToManyField('Complement')
        # historia zmian
    next = models.ForeignKey('SemanticFrame', null=True)
    removed = models.BooleanField(default=False)
    author = models.ForeignKey(User, null=True)
Tomasz Bartosiak authored
45
    opinion = models.ForeignKey(FrameOpinion, null=True)
Bartłomiej Nitoń authored
46
47
48
49
50
51

    def role_exists(self, role_name):
        if self.complements.filter(roles__role=role_name).exists():
            return True
        return False
Bartłomiej Nitoń authored
52
53
54
55
56
    def opinion_selected(self):
        if not self.opinion:
            return False
        return True
Bartłomiej Nitoń authored
57
58
59
60
61
62
    def connected_schemata(self):
        connected_schemata_ids = []
        for compl in self.complements.all():
            connected_schemata_ids.extend([schema.id for schema in compl.connected_schemata()])
        return Frame.objects.filter(id__in=connected_schemata_ids).distinct()
Bartłomiej Nitoń authored
63
64
65
66
67
68
69
70
71
72
73
74
75
    def __unicode__(self):
        complements_str_tab = [unicode(compl) for compl in self.complements.all()]
        return u'%d --> %s' % (self.id, u'+'.join(complements_str_tab))

class FramePosition(models.Model):
        # schemat
    frame = models.ForeignKey(Frame)
        # pozycja w tym schemacie
    position = models.ForeignKey(Position)
        # argument w tej pozycji
    argument = models.ForeignKey(Argument)
        # numer alternacji
    alternation = models.IntegerField(default=1)
Bartłomiej Nitoń authored
76
77
78
79

    def __unicode__(self):
        return 'schema_%d_pos_%d_arg_%d_alt_%d_' % (self.frame.id, self.position.id,
                                                    self.argument.id, self.alternation)
Bartłomiej Nitoń authored
80
81
82
83
84
85
86
87

class LexicalUnitExamples(models.Model):
    example = models.ForeignKey(NKJP_Example)
    lexical_unit = models.ForeignKey(LexicalUnit, null=True)

class GeneralSelectivePreference(models.Model):
    name = models.CharField(max_length=20)
    members = models.ForeignKey('SelectivePreference', null=True)
Bartłomiej Nitoń authored
88
89
90

    def __unicode__(self):
        return u'%s' % (self.name)
Bartłomiej Nitoń authored
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

class SelectivePreferenceRelations(models.Model):
    plwn_id = models.IntegerField(null=True)
    name = models.CharField(max_length=80)
    # !NOWE!
    sym_name = models.CharField(max_length=40)

    def __unicode__(self):
        return u'%s' % (self.name)

class RelationalSelectivePreference(models.Model):
    relation = models.ForeignKey(SelectivePreferenceRelations)
    to = models.ForeignKey('Complement')

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

class SynsetRelationalSelectivePreference(models.Model):
    relation = models.ForeignKey(SelectivePreferenceRelations)
    to = models.ForeignKey(Synset)

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

class Complement(models.Model): # pola z ramki
    frame = models.ForeignKey(SemanticFrame)
        # lista ról, które spełnia to pole w ramce
    roles = models.ManyToManyField(SemanticRole)
        # list synsetów definiujących preferencje selektywne
    selective_preference = models.ForeignKey(SelectivePreference, null=True)
    # validation - Synsets in selective preference are not related by hypernymy/hyperonymy
        # realizacje tego argumentu w schematach składniowych
    realizations = models.ManyToManyField(FramePosition)
Bartłomiej Nitoń authored
128
129
130
131
132
133
    def has_only_phraseologic_realizations(self):
        for real in self.realizations.all():
            if not real.argument.is_phraseologic():
                return False
        return True
Bartłomiej Nitoń authored
134
135
136
137
    def connected_schemata(self):
        schemata_ids = [real.frame.id for real in self.realizations.all()]
        return Frame.objects.filter(id__in=schemata_ids).distinct()
Bartłomiej Nitoń authored
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    def __unicode__(self):
        return u'%d:%s' % (self.id, self.roles.all())

################################################
################## Wspomaganie #################
################################################

class FrameRankings(models.Model): # automatyczna ocena ramy
        # dla którego znaczenia schemat jest oceniany
    lexical_unit = models.ForeignKey(LexicalUnit)
        # który schemat jest oceniana
    frame = models.ForeignKey(Frame)
        # ocena
    rank = models.DecimalField(max_digits=5, decimal_places=4)
        # właściwy podschemat oznaczony manualnie
    done = models.BooleanField()

class SemanticRolesDisplay(models.Model):
        # numer wiersza
    row = models.IntegerField()
        # numer kolumny
    column = models.IntegerField()
        # rowspan
    rowspan = models.IntegerField()
        # colspan
    colspan = models.IntegerField()
        # role
    roles = models.ManyToManyField(SemanticRole)
        # napis (np. nagłówek wiersza/kolumny)
    caption = models.CharField(max_length=30, null=True)