models.py
1.36 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
from django.db import models
class LexicalUnit(models.Model):
entry = models.ForeignKey('connections.Entry', related_name='lexical_units', on_delete=models.PROTECT, null=True)
luid = models.IntegerField(null=True)
base = models.CharField(max_length=150)
sense = models.CharField(max_length=5)
#pos = models.ForeignKey('connections.POS', related_name='lexical_units', on_delete=models.PROTECT)
pos = models.CharField(max_length=20)
synset = models.ForeignKey('Synset', related_name='lexical_units', on_delete=models.PROTECT)
definition = models.TextField(default='')
gloss = models.TextField(default='')
text_rep = models.TextField()
class Meta:
unique_together = ('base', 'sense', 'pos',)
def __str__(self):
return '%s-%s' % (self.base, self.sense)
class Synset(models.Model):
id = models.IntegerField(primary_key=True)
definition = models.TextField(default='')
hypernyms = models.ManyToManyField('Synset', related_name='hyponyms')
def __str__(self):
return ' '.join(sorted(map(str, self.lexical_units.all())))
'''
text_rep = ''
units_in_synset = LexicalUnit.objects.filter(synset__id=self.id)
if units_in_synset.exists():
first_lex_unit = units_in_synset.order_by('luid')[0]
text_rep = str(first_lex_unit)
return text_rep
'''