models.py
3.96 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
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
from django.db.models import AutoField, BooleanField, CharField, \
FloatField, ForeignKey, Model, OneToOneField, \
PositiveIntegerField, TextField, URLField
from django.db.models.fields.related import ManyToManyField
from common import constants
class Entry(Model):
name = TextField(db_index=True)
domains = ManyToManyField('Domain', related_name='entries')
meanings = ManyToManyField('Meaning', related_name='entries')
sources = ManyToManyField('Source', related_name='entries')
def __unicode__(self):
return self.name
class Meaning(Model):
id = AutoField(primary_key=True)
plWN_synset = PositiveIntegerField(blank=True, null=True)
wikilink = URLField(max_length=400, blank=True, null=True)
description = TextField(blank=True, null=True)
comment = TextField(blank=True, null=True)
status = ForeignKey('MeaningStatus', related_name='meanings',
blank=True, null=True)
domains = ManyToManyField('Domain', related_name='meanings')
def add_domains(self, dom_names):
for name in dom_names:
domain_obj, _ = Domain.objects.get_or_create(name=name)
self.domains.add(domain_obj)
def __unicode__(self):
return ' = '.join([expr.text for expr in self.expressions.all()]) + ' !! %s' % self.comment
class MeaningStatus(Model):
hidden = BooleanField(default=False)
key = CharField(max_length=16, primary_key=True)
name = CharField(max_length=32)
display_color = CharField(max_length=16)
def __unicode__(self):
return self.name
def get_or_create_meaning(plWN_synset, wikilink):
created = False
meaning = None
if plWN_synset:
try:
meaning = Meaning.objects.get(plWN_synset=plWN_synset)
except Meaning.DoesNotExist:
pass
if wikilink and meaning == None:
try:
meaning = Meaning.objects.get(wikilink=wikilink)
except Meaning.DoesNotExist:
pass
if meaning == None:
meaning = Meaning.objects.create(plWN_synset=plWN_synset, wikilink=wikilink)
created = True
return meaning, created
class Expression(Model):
id = AutoField(primary_key=True)
text = TextField()
base_text = TextField()
orth_text = TextField()
meaning = ForeignKey('Meaning', related_name='expressions')
score = FloatField()
NKJP_freq = PositiveIntegerField()
is_catchword = BooleanField(default=False)
def __unicode__(self):
return self.text
class SourceLink(Model):
expression = OneToOneField('Expression', related_name='link')
source = ForeignKey('Source', related_name='links')
exact_link = URLField(max_length=400, blank=True, null=True)
class Source(Model):
key = CharField(max_length=16, primary_key=True)
name = CharField(max_length=32)
description = TextField(blank=True, null=True)
url = URLField(blank=True, null=True)
protected = BooleanField(default=True)
class Meta:
ordering = ['name']
def __unicode__(self):
return self.name
class Segment(Model):
position_in_expr = PositiveIntegerField()
expression = ForeignKey('Expression', related_name='segments')
orth = CharField(max_length=64)
base = CharField(max_length=64)
ctag = CharField(max_length=8)
msd = CharField(max_length=64)
is_head = BooleanField(default=False)
has_nps = BooleanField(default=False)
def is_verb(self):
if self.ctag in constants.VERB_TAGS:
return True
return False
def is_noun(self):
if self.ctag in constants.NOUN_TAGS:
return True
return False
def __unicode__(self):
return self.orth
class Domain(Model):
id = AutoField(primary_key=True)
name = CharField(max_length=128)
description = TextField(blank=True, null=True)
class Meta:
ordering = ['name']
def __unicode__(self):
return self.name