models.py
4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
128
129
# -*- 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
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)
def role_exists(self, role_name):
if self.complements.filter(roles__role=role_name).exists():
return True
return False
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)
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)
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)
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)