| author | ymh <ymh.work@gmail.com> |
| Fri, 21 Jun 2013 15:20:24 +0200 | |
| changeset 26 | 758b9289aa9a |
| parent 24 | 1d20eaea6169 |
| child 35 | 859862939996 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Jun 8, 2013 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
7 |
||
| 15 | 8 |
from .. import settings |
| 0 | 9 |
from django.contrib.auth import get_user_model |
| 15 | 10 |
from django.db import models |
11 |
from django.utils.translation import ugettext as _ |
|
| 0 | 12 |
import datetime |
13 |
import logging |
|
14 |
||
15 |
logger = logging.getLogger(__name__) |
|
16 |
||
17 |
User = get_user_model() |
|
18 |
||
19 |
TERM_URL_STATUS_CHOICES = ( |
|
20 |
(0, "null_result"), |
|
21 |
(1, "redirection"), |
|
22 |
(2, "homonyme"), |
|
23 |
(3, "match"), |
|
24 |
(4, "unsematized"), |
|
25 |
) |
|
26 |
||
| 15 | 27 |
TERM_URL_STATUS_CHOICES_TRANS = ( |
28 |
(0, _("null_result")), |
|
29 |
(1, _("redirection")), |
|
30 |
(2, _("homonyme")), |
|
31 |
(3, _("match")), |
|
32 |
(4, _("unsematized")), |
|
33 |
) |
|
34 |
||
| 0 | 35 |
TERM_URL_STATUS_DICT = { |
36 |
"null_result":0, |
|
37 |
"redirection":1, |
|
38 |
"homonyme":2, |
|
39 |
"match":3, |
|
40 |
"unsemantized":4, |
|
41 |
} |
|
42 |
||
43 |
class Thesaurus(models.Model): |
|
44 |
label = models.CharField(max_length=128, unique=True, blank=False, null=False, db_index=True) |
|
45 |
title = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=False) |
|
46 |
description = models.TextField(blank=True, null=True) |
|
47 |
uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
48 |
||
49 |
class Meta: |
|
50 |
app_label = 'core' |
|
51 |
ordering = ['label'] |
|
52 |
||
53 |
def __unicode__(self): |
|
54 |
return self.label |
|
55 |
||
56 |
||
57 |
class Term(models.Model): |
|
58 |
label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True) |
|
59 |
lang = models.CharField(max_length=128, unique=False, blank=True, null=True, db_index=True) |
|
60 |
uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
61 |
normalized_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True, editable=False) |
|
62 |
wp_label = models.CharField(max_length=1024, unique=False, blank=True, null=True, db_index=True) |
|
63 |
wp_alternative_label = models.CharField(max_length=1024, unique=False, blank=True, null=True, db_index=True) |
|
64 |
thesaurus = models.ForeignKey(Thesaurus, blank=False, null=False, db_index=True) |
|
65 |
created_at = models.DateTimeField(auto_now_add=True) |
|
66 |
wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
67 |
wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True) |
|
68 |
wikipedia_revision_id = models.BigIntegerField(unique=False, blank=True, null=True) |
|
69 |
alternative_wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
|
70 |
alternative_wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True) |
|
| 15 | 71 |
url_status = models.IntegerField(choices=TERM_URL_STATUS_CHOICES_TRANS, blank=True, null=True, default=None, db_index=True) |
| 0 | 72 |
dbpedia_uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True) |
73 |
validation_date = models.DateTimeField(null=True, blank=True, serialize=False) |
|
74 |
validated = models.BooleanField(default=False, db_index=True) |
|
75 |
validator = models.ForeignKey(User, null=True, blank=True, serialize=False) |
|
|
26
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
76 |
wikipedia_edition = models.BooleanField(default=False, blank=False, null=False) |
| 0 | 77 |
|
78 |
@property |
|
79 |
def alternative_labels_str(self): |
|
|
26
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
80 |
return " | ".join([l.label for l in self.alternative_labels.all() if l.label != self.label]) |
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
81 |
|
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
82 |
@property |
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
83 |
def alternative_labels_list(self): |
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
24
diff
changeset
|
84 |
return [l.label for l in self.alternative_labels.all() if l.label != self.label] |
| 0 | 85 |
|
86 |
@property |
|
87 |
def wikipedia_revision_permalink(self): |
|
88 |
return settings.WIKIPEDIA_VERSION_PERMALINK_TEMPLATE % (unicode(self.wikipedia_revision_id)) |
|
|
24
1d20eaea6169
small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
89 |
|
|
1d20eaea6169
small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
90 |
@property |
|
1d20eaea6169
small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
91 |
def url_status_text(self): |
|
1d20eaea6169
small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
92 |
return TERM_URL_STATUS_CHOICES[self.url_status][1] |
| 0 | 93 |
|
94 |
@property |
|
|
24
1d20eaea6169
small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
95 |
def url_status_text_trans(self): |
| 15 | 96 |
return TERM_URL_STATUS_CHOICES_TRANS[self.url_status][1] |
| 0 | 97 |
|
98 |
def validate(self, user): |
|
99 |
if not self.validated: |
|
100 |
self.validation_date = datetime.datetime.utcnow() |
|
101 |
self.validated = True |
|
102 |
self.validator = user |
|
103 |
self.save() |
|
104 |
||
105 |
def unvalidate(self): |
|
106 |
if self.validated: |
|
107 |
self.validated = False |
|
108 |
self.validator = None |
|
109 |
self.validation_date = None |
|
110 |
self.save() |
|
111 |
||
112 |
class Meta: |
|
113 |
app_label = 'core' |
|
114 |
||
115 |
class TermLabel(models.Model): |
|
116 |
label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True) |
|
117 |
lang = models.CharField(max_length=128, unique=False, blank=True, null=True, db_index=True) |
|
118 |
term = models.ForeignKey(Term, blank=False, null=False, db_index=True, related_name="alternative_labels") |
|
119 |
||
120 |
class Meta: |
|
121 |
app_label = 'core' |