models.py
3.16 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
# -*- coding: utf-8 -*-
from django.db import models
from settings import MORFEUSZ2
###############################################
################## plWordnet ##################
###############################################
class Synset(models.Model):
# identyfikator ze słowosieci
id = models.IntegerField(primary_key=True)
def __unicode__(self):
text_rep = u''
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 = unicode(first_lex_unit)
return text_rep
class LexicalUnit(models.Model):
# identyfikator ze słowosieci (jeśli jest)
luid = models.IntegerField(null=True)
# podstawa jednostki leksykalnej
base = models.CharField(max_length=150)
# numer znaczenia
sense = models.CharField(max_length=5)
# część mowy
pos = models.CharField(max_length=20)
# wskaźnik do synsetu, w którym się znajduje
synset = models.ForeignKey(Synset, null=True)
# definition
definition = models.TextField(default="")
# glossa
glossa = models.TextField(default="")
# haslo w Walentym
entry = models.ForeignKey('dictionary.Entry', null=True, related_name='meanings')
def __unicode__(self):
return u'%s-%s' % (self.base, self.sense)
def actual_frames(self):
return self.frames.filter(next__isnull=True, removed=False)
def connected(self):
return self.actual_frames().exists()
def is_new(self):
if self.luid < 0:
return True
return False
def is_reflexive(self):
reflexive = False
base_parts = self.base.split()
if len(base_parts) > 1:
last_is_lemma = False
for part in base_parts:
if last_is_lemma and part == u'się':
reflexive = True
elif last_is_lemma:
break
for (orth, base, tag, _, _) in MORFEUSZ2.analyse(part):
lemma = base.split(':')[0]
if lemma == self.entry.name:
last_is_lemma = True
break
return reflexive
def is_multiword(self):
base_parts = self.base.split()
if len(base_parts) > 2 and self.is_reflexive():
return True
elif len(base_parts) > 1 and not self.is_reflexive():
return True
return False
class Meta:
unique_together = ('base', 'sense', 'pos',)
class Hypernymy(models.Model): # hiperonimia jest odwrotna
# hiponim childa
parent = models.ForeignKey(Synset, related_name='hyponym')
# hiperonim parenta
child = models.ForeignKey(Synset, related_name='hypernym')
class Meta:
unique_together = ('parent', 'child',)
class Synonymy(models.Model): # relacja jest symetryczna, dane zwielokrotnione
parent = models.ForeignKey(Synset, related_name='synset')
child = models.ForeignKey(Synset, related_name='synonym')
class Meta:
unique_together = ('parent', 'child',)